<?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();
$html             = '';
$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);
}
$id = $cid . time();

$color_label       = isset($options['color_label'])?'color:'.$options['color_label'].';':'';
$color_text       = isset($options['color_text'])?'color:'.$options['color_text'].';':'';
$color_description= isset($options['color_description'])?'color:'.$options['color_description'].';':'';
$background_color = isset($options['background_color'])?'background-color:'.$options['background_color'].';':'';

$font_size           = isset($options['font_size'])?'font-size:'.(int)$options['font_size'].'px;':'';
$font_style       = isset($options['font_style'])?'font-style:'.$options['font_style'].';':'';
$font_weight      = isset($options['font_weight'])?'font-weight:'.$options['font_weight'].';':'';

?>
<div class="subtemplate-wrapper <?= $cssClass;?>" style="<?= $inlineCss ?>">
    <label for="<?= $field_id; ?>" style="<?= $font_size.$font_style.$font_weight.$color_label; ?>" class="<?= (1==$required)?'required':''; ?>"><?= __($label); ?><?= (1==$required)?'<em>*</em>':'';?></label>
    <div class="input-box">
        <div class="input-line" style="<?= $color_text; ?>>
            <span class="hours">
                <select name="<?= $field_name.'_hours'; ?>" id="<?= $field_id.'_hours'; ?>" class="<?= (1==$required)?'required-entry':''; ?> validate-zero-or-greater time-<?= $id ?>" >
                    <?php
                    for ($i=0; $i<24; $i++) {
                        $k = $i;
                        if ($i<10) {
                            $k = '0'.$i;
                        } ?>
                        <option value="<?= $k; ?>"><?= $k; ?></option>
                        <?php
                    }
                    ?>
                </select>
                <label><?= __("HH"); ?></label>
            </span>
            <span class="above-line">:</span>
            <span class="minutes">
                <select name="<?= $field_name.'_minutes'; ?>" id="<?= $field_id.'_minutes'; ?>" class="<?= (1==$required)?'required-entry':''; ?> validate-zero-or-greater time-<?= $id ?>" >
                    <?php
                    for ($i=0; $i<60; $i++) {
                        $k = $i;
                        if ($i<10) {
                            $k = '0'.$i;
                        } ?>
                        <option value="<?= $k; ?>"><?= $k ?></option>
                        <?php }
                    ?>

                    </select>
                    <label><?= __("MM"); ?></label>
                </span>
                <span class="above-line">:</span>
                <span class="seconds">
                    <select name="<?= $field_name.'_seconds'; ?>" id="<?= $field_id.'_seconds'; ?>" class="<?= (1==$required)?'required-entry':''; ?> validate-zero-or-greater time-<?= $id ?>" >
                        <?php
                        for ($i=0; $i<60; $i++) {
                            $k = $i;
                            if ($i<10) {
                                $k = '0'.$i;
                            } ?>
                            <option value="<?= $k; ?>"><?= $k; ?></option>
                            <?php }
                        ?>
                        </select>
                        <label><?= __("SS"); ?></label>
                    </span>
                    <span class="am_pm">
                        <select name="<?= $field_name.'_am_pm'; ?>" id="<?= $field_id.'_am_pm'; ?>" class="time-<?= $id ?>" >
                            <option value="AM"><?= __("AM"); ?></option>
                            <option value="PM"><?= __("PM"); ?></option>
                        </select>
                    </span>
                </div>
                <?php if ($field_help) { ?>
                    <span class="help-block" style="<?= $color_description; ?>"><?= $field_help; ?></span>
                    <?php } ?>
                </div>
            </div>
