<?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);
$helperData = $this->helper(Data::class);
$form           = $block->getForm();
$field          = $this->getData('field_data');

$fieldType     = $field['field_type'];
$label          = $block->filterMessage($field['label']);
$options        = $field['field_options'];
$required       = $field['required'];
$cid              = $helperData->getFieldId($field);
$inlineCss      = $field['inline_css'] ?? '';
$fieldName     = $helper->getFieldPrefix() . $cid . $form->getId();
$fieldId          = $fieldName.uniqid();
$frameWorkCss = '';
if (isset($field['frame_work_css'])) {
    $frameWorkCss      = $field['frame_work_css'];
}
$availableFields = $helper->getAvailableFields();
$html             = '';
$fieldValidate   = $availableFields[$fieldType] ?? '';
$validates        = $fieldValidate;
$fieldHelp       = isset($options['description']) ? $block->filterMessage($options['description']) : '';
if ($fieldValidate && is_array($fieldValidate)) {
    $validates = implode(" ", $fieldValidate);
}
$imageType = $field['image_type'] ?? 'png,jpg,gif,jpeg,zip,doc,pdf';
$imageMaximumSize = $field['image_maximum_size'] ?? 10;

$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'].';' : '';

if ($frameWorkCss == 'foundation') { ?>
<div class="docs-code-live">
    <div class="row">
        <?php if ($label && $label != '') { ?>
        <div class="input-box-label columns medium-6">
            <label for="<?= $fieldId; ?>" style="<?= $fontSize.$fontStyle.$fontWeight.$colorLabel; ?>" class="button <?= (1 == $required) ? 'required' : ''; ?>"><?= __($label); ?><?= (1 == $required) ? '<em>*</em>' : '';?></label>
        </div>
        <?php } ?>
        <div class="input-box columns medium-6">
            <input name="<?= $fieldName; ?>" id="<?= $fieldId; ?>" style="<?= $colorText.$backgroundColor; ?>" title="<?= $label; ?>" class="show-for-sr input-text<?= (1 == $required) ? ' required-entry' : ''; ?> <?= $validates; ?>" type="file" />
                <?php if ($fieldHelp) { ?>
                    <span class="help-block" style="<?= $colorDescription; ?>" ><?= $fieldHelp; ?></span>
                <?php } ?>
        </div>
    </div>
</div>

    <?php
} else {
    ?>

<div class="subtemplate-wrapper" style="<?= $inlineCss ?>">
    <div class="row">
        <?php if ($label && $label != '') { ?>
        <div class="input-box-label col-sm-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 col-sm-6">
            <input name="<?= $fieldName; ?>" id="<?= $fieldId; ?>" style="<?= $colorText.$backgroundColor; ?>" title="<?= $label; ?>" class="input-text<?= (1 == $required) ? ' required-entry' : ''; ?> <?= $validates; ?>" type="file" />
            <?php if ($fieldHelp) { ?>
                <span class="help-block" style="<?= $colorDescription; ?>" ><?= $fieldHelp; ?></span>
            <?php } ?>
        </div>
    </div>
</div>
<?php } ?>
