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

<?php
/** @var \WriteTextAI\WriteTextAI\ViewModel\TransferSettings $transferSettings */
/** @var \WriteTextAI\WriteTextAI\ViewModel\Tooltip $tooltip */
/** @var \WriteTextAI\WriteTextAI\ViewModel\Permissions $permissions */
/** @var \WriteTextAI\WriteTextAI\ViewModel\AiModels $aiModels */

$transferSettings = $block->getTransferSettings();
$tooltip = $block->getTooltip();
$permissions = $block->getPermissions();
$aiModels = $block->getAiModels();
?>
<div class="wtai-buttons page-actions" data-bind="scope: 'wtaiEditButtons'" >
    <div class="page-actions-buttons">
        <div class="wtai-step-wrapper">
            <?php if ($permissions->isGenerateAllowed()): ?>
                <span class="wtai-step" data-bind="hidden: guideSteps">
                    <?= $escaper->escapeHtml(__('Step 5')) ?>
                </span>
            <?php endif; ?>
        </div>
        <?= /* @noEscape */ $block->getChildHtml(); ?>
        <hr class="wtai-line-break"/>
        <?php if ($permissions->isEditAllowed()): ?>
            <button type="button"
                class="action-default wtai-save action-secondary"
                data-bind="click: save, disable: !canSave()"
            >
                <span><?= $escaper->escapeHtml(__("Save")) ?></span>
            </button>
        <?php endif; ?>
        <?php if ($permissions->isTransferAllowed()): ?>
            <div class="wtai-transfer-action" data-bind="attr: {
                title: !canTransfer()
                    ? '<?= $escaper->escapeJs(__(
                        'Select at least one text field with generated content to enable transfer.'
                    )) ?>'
                    : null
            }">
                <button type="button"
                    class="action-default wtai-transfer action-secondary"
                    data-bind="
                        click: transfer,
                        disable: !canTransfer()
                        "
                >
                    <span><?= $escaper->escapeHtml(__("Transfer selected to Magento")) ?></span>
                </button>
            </div>
        <?php endif; ?>
        <?php if ($permissions->isGenerateAllowed()): ?>
            <div class="wtai-generate-action" data-bind="attr: {
                title: !canGenerate()
                    ? '<?= $escaper->escapeJs(__('Select at least one text field to generate text.')) ?>'
                    : null
            }">
                <button type="button"
                    class="action-default scalable primary"
                    data-bind="
                        enable: canGenerate,
                        click: function () { generate(false) }
                        "
                >
                    <span><?= $escaper->escapeHtml(__('Generate selected')) ?></span>
                </button>
            </div>
        <?php endif; ?>
        <?php if ($permissions->isTransferAllowed()): ?>
            <div class="wtai-tooltip-wrapper">
                <div class="admin__field-tooltip wtai-small">
                    <a class="admin__field-tooltip-action" href="#" data-toggle="dropdown"></a>
                    <div class="admin__field-tooltip-content wtai-upper-right" data-target="dropdown">
                        <div class="wtai-content-wrapper">
                            <?= /* @noEscape */ $tooltip->getTooltip('wtai.transfer.category') ?>
                        </div>
                    </div>
                </div>
            </div>
        <?php endif; ?>
        <div class="wtai-edit-loading-mask"></div>
    </div>
</div>
<script type="text/x-magento-init">
    {
        "*": {
            "Magento_Ui/js/core/app": {
                "components": {
                    "wtaiEditButtons": {
                        "component": "WriteTextAI_WriteTextAI/js/categories/edit/buttons",
                        "confirmContent": "<?= $escaper->escapeJs($transferSettings->getConfirmContent()) ?>",
                        "saveUrl": "<?= $escaper->escapeJs($block->getUrl('wtai/categories/edit_save')) ?>",
                        "uploadUrl": "<?= $escaper->escapeJs($block->getUrl('wtai/categories/image_upload')) ?>",
                        "transferUrl":
                            "<?= $escaper->escapeJs($block->getUrl('wtai/categories/edit_transfer')) ?>",
                        "generateUrl":
                            "<?= $escaper->escapeJs($block->getUrl('wtai/categories/edit_generate')) ?>",
                        "hasAiModels": <?= /* @noEscape */ $aiModels->hasAiModels() ? 'true' : 'false' ?>,
                        "getGeneratedUrl":
                            "<?= $escaper->escapeJs($block->getUrl('wtai/categories/edit_textfields_get')) ?>",
                        "templateHasImageUrl": "<?= $escaper->escapeJs($block->getUrl('wtai/template/hasImage')) ?>"
                    }
                }
            }
        }
    }
</script>
