<?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">
                    <?= $block->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><?= $block->escapeHtml(__("Save")) ?></span>
            </button>
        <?php endif; ?>
        <?php if ($permissions->isTransferAllowed()): ?>
            <div class="wtai-transfer-action">
                <button type="button"
                    class="action-default wtai-transfer action-secondary"
                    data-bind="
                        click: transfer,
                        disable: !canTransfer()
                    "
                >
                    <span><?= $block->escapeHtml(__("Transfer selected to Magento")) ?></span>
                </button>
            </div>
        <?php endif; ?>
        <?php if ($permissions->isGenerateAllowed()): ?>
            <div class="wtai-generate-action">
                <button type="button"
                    class="action-default scalable primary"
                    data-bind="
                        enable: canGenerate,
                        click: function () { generate(false) }
                    "
                >
                    <span><?= $block->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": "<?= $block->escapeJs($transferSettings->getConfirmContent()) ?>",
                        "saveUrl": "<?= $block->escapeJs($block->getUrl('wtai/categories/edit_save')) ?>",
                        "uploadUrl": "<?= $block->escapeJs($block->getUrl('wtai/categories/image_upload')) ?>",
                        "transferUrl":
                            "<?= $block->escapeJs($block->getUrl('wtai/categories/edit_transfer')) ?>",
                        "generateUrl":
                            "<?= $block->escapeJs($block->getUrl('wtai/categories/edit_generate')) ?>",
                        "hasAiModels": <?= /* @noEscape */ $aiModels->hasAiModels() ? 'true' : 'false' ?>,
                        "getGeneratedUrl":
                            "<?= $block->escapeJs($block->getUrl('wtai/categories/edit_textfields_get')) ?>"
                    }
                }
            }
        }
    }
</script>
