<?php if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) die();

use Bitrix\Main\Localization\Loc;
use intec\core\helpers\Html;
use intec\core\platform\main\Component;

/** @var array $arParams */
/** @var array $arResult */
/** @var CBitrixComponentTemplate $this */
/** @var CBitrixComponent $component */

$this->setFrameMode(true);
$templateId = Html::getUniqueId(null, Component::getUniqueId($this));
$visual = &$arResult['VISUAL'];
$templateId = $templateId . '_' . $visual['INPUT']['ID'];

$backgroundColor = null;
$transparent = false;
$textColor = null;

if ($visual['INPUT']['COLOR']['MODE'] === 'CUSTOM') {
    $backgroundColor = 'rgba(' .
        $visual['INPUT']['COLOR']['BACKGROUND'][0] . ', ' .
        $visual['INPUT']['COLOR']['BACKGROUND'][1] . ', ' .
        $visual['INPUT']['COLOR']['BACKGROUND'][2] . ', 0.4)';
    $textColor = 'rgba(' .
        $visual['INPUT']['COLOR']['TEXT'][0] . ', ' .
        $visual['INPUT']['COLOR']['TEXT'][1] . ', ' .
        $visual['INPUT']['COLOR']['TEXT'][2] . ')';
} elseif ($visual['INPUT']['COLOR']['MODE'] === 'TRANSPARENT') {
    $backgroundColor = 'rgba(255, 255, 255, 0.1)';
    $transparent = true;
}

?>
<!--googleoff: all-->
<!--noindex-->
<?= Html::beginTag('div', [
    'id' => $templateId,
    'class' => [
        'ns-bitrix',
        'c-search-title',
        'c-search-title-input-1'
    ],
    'data-size' => $visual['INPUT']['SIZE'],
    'data-role' => 'search.area',
]) ?>
    <?php if (empty($visual['INPUT']['ID'])) { ?>
        <div style="text-align: center; color: red; padding: 30px 0">
            <?= Loc::getMessage('C_SEARCH_TITLE_INPUT_1_ERROR_INPUT_ID_EMPTY') ?>
        </div>
    <?php } else { ?>
        <?= Html::beginForm($arResult['FORM_ACTION'], 'get', [
            'data-role' => 'search.form',
            'style' => 'position: relative'
        ]) ?>
            <?= Html::textInput('q', null, [
                'class' => [
                    'search-title-form-input',
                    'ui-input-text',
                    Html::cssClassFromArray([
                        'light' => $visual['INPUT']['LIGHT'],
                        'bordered' => $visual['INPUT']['BORDER']
                    ], true)
                ],
                'id' => $visual['INPUT']['ID'],
                'autocomplete' => 'off',
                'placeholder' => $visual['INPUT']['TEXT'],
                'data-role' => 'input',
                'data-transparent' => $transparent ? "true" : "false",
                'style' => [
                    'background-color' => $backgroundColor,
                    'color' => $textColor
                ]
            ]) ?>
            <?= Html::tag('div', Loc::getMessage('C_SEARCH_TITLE_INPUT_1_BUTTON_CLEAR'), [
                'class' => Html::cssClassFromArray([
                    'search-title-form-button-clear' => true,
                    'ui-text' => [
                        'small' => $visual['INPUT']['SIZE'] === 'small',
                        'large' => $visual['INPUT']['SIZE'] === 'large',
                        'height-2' => true,
                        'ntr-sd' => !$visual['INPUT']['LIGHT'],
                        'ntr-b' => $visual['INPUT']['LIGHT'],
                        'prm-hover' => true
                    ]
                ], true),
                'data' => [
                    'action' => 'search.clear',
                    'hidden' => 'true'
                ]
            ]) ?>
            <?= Html::beginTag('button', [
                'class' => [
                    'search-title-form-button-submit',
                    'ui-svg' => [
                        Html::cssClassFromArray([
                           'stroke' => [
                               'ntr-sd' => !$visual['INPUT']['LIGHT'],
                               'ntr-b' => $visual['INPUT']['LIGHT']
                           ]
                        ], true),
                        'stroke-prm-hover',
                        '24'
                    ]
                ],
                'type' => 'submit',
                'data-action' => 'search.submit'
            ]) ?>
                <svg xmlns="http://www.w3.org/2000/svg">
                    <use xlink:href="#loupe"></use>
                </svg>
            <?= Html::endTag('button') ?>
        <?= Html::endForm() ?>
        <?php include(__DIR__ . '/parts/script.php') ?>
    <?php } ?>
<?= Html::endTag('div') ?>
<!--/noindex-->
<!--googleon: all-->