<?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
 */

use Lof\Formbuilder\Helper\Data;
use Lof\Formbuilder\Helper\Fields;

$helper           = $this->helper(Fields::class);
$dataHelper       = $this->helper(Data::class);
$form             = $block->getForm();
$formData        = $this->getData('form_data');
$field            = $this->getData('field_data');
$fieldType       = $field['field_type'];
$label            = $block->filterMessage($field['label']);
$options          = $field['field_options'];
$required         = $field['required'];
$cid              = $dataHelper->getFieldId($field);
$fieldName       = $helper->getFieldPrefix() . $cid . $form->getId();
$fieldId          = $fieldName.uniqid();
$availableFields = $helper->getAvailableFields();
$html             = '';
$fieldValidate   = $availableFields[$fieldType] ?? '';
$validates        = $fieldValidate;
$fieldHelp       = isset($options['description']) ? $block->filterMessage($options['description']) : '';
$inlineCss        = $field['inline_css'] ?? '';
if ($fieldValidate && is_array($fieldValidate)) {
    $validates = implode(" ", $fieldValidate);
}
$id = $cid . time();

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

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

$frameWorkCss   = '';
if (isset($field['frame_work_css'])) {
    $frameWorkCss      = $field['frame_work_css'];
}
if ($frameWorkCss == 'foundation') {
    $medium = 'columns medium-';
} else {
    $medium = 'col-sm-';
}
?>
<div class="subtemplate-wrapper" style="<?= $inlineCss ?>">
    <div class="row">
        <?php if ($label && $label != "") { ?>
            <div class="input-box-label <?= $medium; ?>6">
                <label for="<?= $fieldId; ?>" style="<?= $fontSize.$fontStyle.$fontWeight.$colorLabel; ?>" class="<?= (1 == $required) ? 'required' : ''; ?>"><?= __($label); ?><?= (1 == $required) ? '<em>*</em>' : '';?></label>
            </div>
        <?php } ?>
        <div class="input-box <?= $medium; ?>6">
            <div class="input-line" style="<?= $colorText; ?>">
                <span class="hours">
                    <select name="<?= $fieldName.'_hours'; ?>" id="<?= $fieldId.'_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="<?= $fieldName.'_minutes'; ?>" id="<?= $fieldId.'_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="<?= $fieldName.'_seconds'; ?>" id="<?= $fieldId.'_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="<?= $fieldName.'_am_pm'; ?>" id="<?= $fieldId.'_am_pm'; ?>" class="time-<?= $id ?>" >
                                <option value="AM"><?= $block->escapeHtml(__("AM")); ?></option>
                                <option value="PM"><?= $block->escapeHtml(__("PM")); ?></option>
                            </select>
                        </span>
                    </div>
                    <?php if ($fieldHelp) { ?>
                        <span class="help-block" style="<?= $colorDescription; ?>"><?= $fieldHelp; ?></span>
                        <?php } ?>
                    </div>
        </div>
</div>
