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

<?php
$tooltipText = __("Note: Selecting the product image"
    . " to be considered in generating text might result in a significantly"
    . " longer time to complete your bulk generation, This is because"
    . " we have to download and resize the image and then send it to the"
    . " AI for analysis. The time it takes for this processing on a single"
    . " product generation may be negligible, but it can add up when"
    . " doing bulk generation for multiple products.");
?>

<div class="wtai-col wtai-col-2">
    <div class="row wtai-product-attributes">
        <fieldset class="wtai-fieldset">
            <div class="wtai-fieldset-title">
                <?= $block->escapeHtml(__('Product data')) ?>
            </div>
            <div class="wtai-text-introduction">
                <span><?= $block->escapeHtml(
                    __('Product data includes Attributes, your thumbnail, and'.
                    ' optional Product Research (up to 50 data fields per product at no extra cost).')
                ) ?>
                </span>
            </div>
            <div class="wtai-field wtai-select-all">
                <input type="checkbox"
                    class="admin__control-checkbox wtai-checkbox-select-all"
                    value="all"
                    id="wtaiAttributesAll"
                    data-name="attributes"
                    data-field="attributes[]"
                    data-bind="checked: allAttributesSelected, enable: attrAllowed"
                />
                <label class="wtai-label admin__field-label wtai-strong" for="wtaiAttributesAll">
                    <?= $block->escapeHtml(__('Select all')) ?>
                </label>
            </div>
            <div class="wtai-field-columns">
                <!-- ko foreach: attributes -->
                    <!-- ko if: $data.value === 'thumbnail' -->
                        <div class="wtai-field wtai-thumbnail-field" data-bind="attr: {
                            title: '<?= $block->escapeHtmlAttr($tooltipText) ?>'
                        }">
                            <input type="checkbox"
                                class="admin__control-checkbox wtai-product_attributes"
                                data-bind="
                                    checked: $parent.attributesSelected,
                                    value: $data.value,
                                    attr: {
                                        id: 'wtaiAttr' + $data.id,
                                    },
                                    enable: $parent.attrAllowed
                                "
                                name="attributes[]"
                            />
                            <label class="wtai-label admin__field-label" data-bind="
                                attr: { for: 'wtaiAttr' + $data.id }
                            ">
                                <span data-bind="text: $data.label"></span>
                                <p class="wtai-thumbnail-text">
                                    <?= $block->escapeHtml(
                                        __("(Analyze image to generate more relevant text)")
                                    ) ?>
                                </p>
                            </label>
                        </div>
                    <!-- /ko -->
                    <!-- ko if: $data.value === 'wtai_product_research_data' -->
                        <div class="wtai-field wtai-thumbnail-field">
                            <input type="checkbox"
                                class="admin__control-checkbox wtai-product_attributes"
                                data-bind="
                                    checked: $parent.attributesSelected,
                                    attr: {
                                        id: 'wtaiAttr' + $data.id,
                                    },
                                    value: $data.value,
                                    enable: $parent.attrAllowed
                                "
                                name="attributes[]"
                            />
                            <label class="wtai-label admin__field-label" data-bind="
                                attr: { for: 'wtaiAttr' + $data.id }
                            ">
                                <span data-bind="text: $data.label"></span>
                                <p class="wtai-thumbnail-text">
                                    <?= $block->escapeHtml(
                                        __("(AI-powered research to improve writing accuracy)")
                                    ) ?>
                                </p>
                            </label>
                        </div>
                    <!-- /ko -->
                    <!-- ko ifnot: $data.value === 'thumbnail' || $data.value === 'wtai_product_research_data' -->
                        <div class="wtai-field">
                            <input type="checkbox"
                                class="admin__control-checkbox wtai-product_attributes"
                                data-bind="
                                    checked: $parent.attributesSelected,
                                    attr: {
                                        id: 'wtaiAttr' + $data.id,
                                    },
                                    value: $data.value,
                                    enable: $parent.attrAllowed
                                "
                                name="attributes[]"
                            />
                            <label class="wtai-label admin__field-label" data-bind="
                                attr: { for: 'wtaiAttr' + $data.id }
                            ">
                                <span data-bind="text: $data.label"></span>
                            </label>
                        </div>
                    <!-- /ko -->
                <!-- /ko -->
            </div>
            <div class="wtai-error-message"></div>
        </fieldset>
    </div>
    <div class="row wtai-special-instructions">
        <div class="wtai-field">
            <label class="admin__field-label">
                <?= $block->escapeHtml(__('Special instructions')) ?>
            </label>
            <div class="admin__field-tooltip wtai-small">
                <a class="admin__field-tooltip-action" href="#" data-toggle="dropdown"></a>
                <div class="admin__field-tooltip-content" data-target="dropdown">
                    <div class="wtai-content-wrapper">
                        <?= /* @noEscape */ $block->getTooltip('wtai.special.instructions') ?>
                    </div>
                </div>
            </div>
        </div>
        <div class="wtai-control">
            <textarea class="admin__control-textarea"
                name="product_details"
                data-bind="
                    event: { input: handleInputSpecialInstructions },
                    textInput: specialInstructions,
                    attr: { maxlength: rules().maxOtherDetailsLength }
                "
            ></textarea>
            <span class="wtai-note">
                <?= $block->escapeHtml(__('Use a comma to separate details.')) ?>
            </span>
            <span class="wtai-text-length" data-bind="text: getOtherProductDetailsLength"></span>
        </div>
    </div>
</div>