<?php
/**
 * Landofcoder
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Landofcoder.com license that is
 * available through the world-wide-web at this URL:
 * https://landofcoder.com/terms
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade this extension to newer
 * version in the future.
 *
 * @category   Landofcoder
 * @package    Lof_Formbuilder
 * @copyright  Copyright (c) 2021 Landofcoder (https://www.landofcoder.com/)
 * @license    https://landofcoder.com/terms
 */

$helper           = $this->helper("Lof\Formbuilder\Helper\Fields");
$dataHelper       = $this->helper("Lof\Formbuilder\Helper\Data");
$form             = $block->getForm();
$form_data        = $this->getData('form_data');
$field            = $this->getData('field_data');
$field_type       = $field['field_type'];
$label            = $block->filterMessage($field['label']);
$options          = $field['field_options'];
$required         = $field['required'];
$cid              = $dataHelper->getFieldId($field);
$field_name       = $helper->getFieldPrefix() . $cid . $form->getId();
$field_id          = $field_name.uniqid();
$available_fields = $helper->getAvailableFields();
$field_validate   = isset($available_fields[$field_type])?$available_fields[$field_type]:'';
$validates        = $field_validate;
$field_help       = isset($options['description'])?$block->filterMessage($options['description']):'';
$inlineCss        = isset($field['inline_css'])?$field['inline_css']:'';
$cssClass   = isset($field['css_class']) ? ($block->escapeHtmlAttr($field['css_class']).' ') : '';
if ($field_validate && is_array($field_validate)) {
    $validates = implode(" ", $field_validate);
}
$limit = isset($field['limit'])?(int)$field['limit']:5;
$default = isset($field['default'])?(float)$field['default']:0;
?>
<div class="subtemplate-wrapper <?= $cssClass; ?>" style="<?= $inlineCss ?>">
    <label for="<?= $field_id; ?>" class="<?= (1==$required)?'required':''; ?>"><?= __($label); ?><?= (1==$required)?'<em>*</em>':'';?></label>
    <div class="input-box">
        <input name="<?= $field_name; ?>" id="<?= $field_id; ?>" title="<?= $label; ?>" value="<?= ($form_data && isset($form_data[$field_name]))?$form_data[$field_name]:''; ?>" class="input-text <?= (1==$required)?'required-entry':''; ?>" type="hidden"/>
        <input name="<?= $field_name."_limit"; ?>" id="<?= $field_id."_limit"; ?>" title="<?= $label; ?>" value="<?= $limit; ?>" class="input-text" type="hidden"/>
        <div id="<?= $field_id."_rating"; ?>" class="ves-rating-play"></div>
        <script type="text/javascript">
            require(['jquery', 'Lof_Formbuilder/js/raty/raty'], function(){
                jQuery('#<?= $field_id."_rating"; ?>').raty({
                    path: '<?= $block->escapeUrl($dataHelper->getMediaUrl()."lof/formbuilder/rating/"); ?>',
                    score: <?= $default; ?>,
                    number: <?= $limit; ?>,
                    targetScore: '#<?= $field_id; ?>',
                    click: function(score, evt) {
                        jQuery('#<?= $field_id; ?>').val(score);
                        return false;
                    }
                });
            });
        </script>
        <?php if ($field_help) : ?>
        <span class="help-block"><?= $field_help; ?></span>
        <?php endif; ?>
    </div>
</div>
