<?php
/**
* @package   BaForms
* @author    Balbooa http://www.balbooa.com/
* @copyright Copyright @ Balbooa
* @license   http://www.gnu.org/licenses/gpl.html GNU/GPL
*/

defined('_JEXEC') or die;

use Balbooa\Component\Forms\Site\Helper\DesignHelper;
use Balbooa\Component\Forms\Site\Helper\Uploads\Enums\UploadEnum;
use Balbooa\Component\Forms\Site\Helper\Uploads\Factory\UploadsFactory;
use Joomla\CMS\Uri\Uri;

$attachmentsHelper = UploadsFactory::getInstance(UploadEnum::Attachments);

ob_start();
?>
<style>
<?php
foreach ($cid as $id => $value) {
    $str = DesignHelper::getInstance()->getVariables($value->design);
?>
.ba-form-<?php echo $id; ?>,
.ba-form-message-popup[data-form="<?php echo $id; ?>"],
.forms-calendar-wrapper[data-form="<?php echo $id; ?>"],
.ba-form-authorize-modal[data-form="<?php echo $id; ?>"],
.ba-form-paypal-modal[data-form="<?php echo $id; ?>"] {
    <?php echo $str; ?>
}
<?php
}
?>
</style>
<script>
var JUri = '<?php echo Uri::root(); ?>',
	uploads_storage = '<?php echo $attachmentsHelper->getStoragePath(); ?>',
	loadFormsMap = <?php echo $loadMapJSON; ?>;
window.conditionLogic = window.conditionLogic ? window.conditionLogic : {};
<?php
foreach ($cid as $id => $value) {
    $conditionLogic = json_encode($value->conditionLogic->conditions);
?>
window.conditionLogic[<?php echo $id; ?>] = <?php echo $conditionLogic; ?>;
<?php
}
?>
</script>
<?php
foreach ($cid as $id => $value) {
    if (!empty($value->design->css)) {
?>
<style>
<?php echo $value->design->css; ?>
</style>
<?php
    }
    if (!empty($value->design->js)) {
?>
<script>
<?php echo $value->design->js; ?>
</script>
<?php
    }
}
$out = ob_get_contents();
ob_end_clean();