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

<?php
use Magento\Store\Model\Store;

/** @var \WriteTextAI\WriteTextAI\ViewModel\AttrScope $attrScope */
/** @var \WriteTextAI\WriteTextAI\ViewModel\Premium $premium */

$attrScope = $block->getAttrScope();
$premium = $block->getPremiumModel();

$imageScope = $attrScope->getCatAttrScope('image');
?>

<div class="wtai-category-image" data-bind="scope: 'wtaiCategoryImage'">
    <div class="wtai-empty" data-bind="hidden: categoryImage">
        <?= $escaper->escapeHtml(__('No image found.')) ?>
    </div>
    <div class="wtai-has-image" data-bind="visible: categoryImage">
        <div class="wtai-field-wrapper">
            <input type="checkbox"
                id="wtaiCategoryImage"
                class="admin__control-checkbox"
                data-bind="
                    checked: categoryImageSelected,
                    event: { change: savePreferences }
                "
            />
            <label class="admin__field-label wtai-description" for="wtaiCategoryImage">
                <?= $escaper->escapeHtml(__("Category Image")) ?>
                <span data-config-scope="<?= $escaper->escapeHtmlAttr(
                    $imageScope
                ) ?>"></span>
                <div class="wtai-note">
                    <?= $escaper->escapeHtml(__("(Analyze image to generate more relevant text)")) ?>
                </div>
            </label>
        </div>
        <div class="wtai-image-wrapper">
            <div class="wtai-preview-wrapper" data-bind="click: preview">
                <img class="wtai-image" data-bind="attr: { src: categoryImage }" />
            </div>
            <div class="wtai-field-content" data-bind="visible: !isAllStoreView()">
                <input type="checkbox"
                    id="wtaiCategoryImageUseDefault"
                    class="admin__control-checkbox"
                    data-bind="checked: useDefault"
                    disabled
                />
                <label class="wtai-label admin__field-label" for="wtaiCategoryImageUseDefault">
                    <?= $escaper->escapeHtml(__('Use default value')) ?>
                </label>
            </div>
        </div>
    </div>
</div>
<script type="text/x-magento-init">
    {
        "*": {
            "Magento_Ui/js/core/app": {
                "components": {
                    "wtaiCategoryImage": {
                        "component": "WriteTextAI_WriteTextAI/js/categories/edit/image",
                        "saveUrl": "<?= $escaper->escapeJs($block->getUrl('wtai/settings/save')) ?>",
                        "defaultStoreId" : <?= $escaper->escapeJs(Store::DEFAULT_STORE_ID) ?>
                    }
                }
            }
        }
    }
</script>
