<?php
/**
 * @author 1902 Software
 * @copyright Copyright © 2023 1902 Software (https://1902software.com/magento/)
 * @package WriteTextAI_WriteTextAI
 */
?>

<?php
$tooltipAltTextDisabled = __(
    "Image alt text can’t run alone due to a technical limit. "
    . 'Please include another text type.'
);
?>

<div class="wtai-text-introduction">
    <span><?= /* @noEscape */ sprintf(
        __('Don’t see any templates? You can create and assign them in'
            . ' <a href="%s" target="_blank">platform.writetext.ai</a>.'
            . ' Assigned templates will appear here.'),
        'https://platform.writetext.ai/webshops/'
    ) ?>
    </span>
</div>
<fieldset class="wtai-fieldset">
    <div class="wtai-field">
        <input type="checkbox"
            class="admin__control-checkbox"
            value="all"
            id="wtaiFieldGenerateAll"
            name="fields[]"
            data-bind="checked: allFieldsSelected" />
        <label class="wtai-label admin__field-label wtai-strong" for="wtaiFieldGenerateAll">
            <?= $escaper->escapeHtml(__('Select all')) ?>
        </label>
    </div>
    <!-- ko foreach: fields -->
        <div class="wtai-field">
            <input type="checkbox"
                class="admin__control-checkbox wtai-generate-text-fields"
                name="fields[]"
                data-bind="
                    checked: $parent.selectedFields,
                    attr: {
                        id: 'wtaiField' + $data.value,
                    },
                    value: $data.value,
                " />
            <label class="wtai-label admin__field-label wtai-label-with-select-template"
                data-bind="
                    attr: {
                        for: 'wtaiField' + $data.value,
                    },
                    text: $data.label
                "
            ></label>
            <!-- ko if: $data.hasTemplate -->
                <div class="admin__field wtai-select-template-bulk">
                    <div class="admin__field-control">
                        <select class="admin__control-select"
                            data-bind="
                                disable: $parent.selectedFields.indexOf($data.value) === -1,
                                attr: {
                                    id: 'wtai-template-' + $data.value,
                                    name: 'wtai_template_' + $data.value,
                                }
                            "
                        >
                            <option value=""><?= $escaper->escapeHtml(__('No template')) ?></option>
                            <!-- ko foreach: $data.templates -->
                                <option 
                                    data-bind="
                                        attr: {
                                            value: $data.id,
                                            title: $data.name,
                                        },
                                        text: $data.name.length > 60
                                            ? $data.name.substring(0, 60) + '...' + '\u00A0\u00A0'
                                            : $data.name + '\u00A0\u00A0'
                                    "
                                ></option>
                            <!-- /ko -->
                        </select>
                    </div>
                </div>
            <!-- /ko -->
        </div>
    <!-- /ko -->
    <div class="wtai-field" data-bind="attr: { title: isAltTextDisabled()
        ? '<?= $escaper->escapeHtmlAttr($tooltipAltTextDisabled) ?>' : ''
    }, css: {'wtai-not-allowed': isAltTextDisabled}">
        <input type="checkbox"
            class="admin__control-checkbox wtai-generate-text-fields"
            value="alt_text"
            id="wtaiFieldAltText"
            name="fields[]"
            data-bind="
                checked: selectedFields,
                disable: isAltTextDisabled
            "
        />
        <label class="wtai-label admin__field-label" for="wtaiFieldAltText">
            <?= $escaper->escapeHtml(__("Image alt text")) ?>
        </label>
    </div>
    <div class="wtai-error-message"></div>
</fieldset>
<div class="wtai-error-message"></div>