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

<?php
    use WriteTextAI\WriteTextAI\ViewModel\Premium;
    use WriteTextAI\WriteTextAI\ViewModel\Popups;
?>

<?php
    /** @var Premium $premium */
    $premium = $block->getPremium();
    $getNoCreditsFreeTrial = $premium->getNoCreditsFreeTrial();
    $membershipType = $premium->getMembershipType();
    $showByApi = $getNoCreditsFreeTrial && $membershipType === Premium::MEMBERSHIP_TYPE_FREE_TRIAL;

    /** @var Popups $popups */
    $popups = $block->getPopups();
    $credits = $popups->getCredits();
    $freeTrialCredits = $credits['freeTrialCredits'] ?? 35;

    $showPopup = $showByApi;
?>

<div class="wtai-no-more-trial-credits-popup-modal" data-bind="
    scope: 'wtaiNoMoreTrialCreditsPopup'
" style="display: none;">
    <div class="wtai-popup-content">
        <div class="wtai-popup-image"></div>
        <div class="wtai-popup-text">
            <div class="wtai-popup-title">
                <?= $escaper->escapeHtml(sprintf(
                    __("You’ve used up your %s complimentary credits."),
                    $freeTrialCredits
                )) ?>
            </div>
            <div>
                <p>
                    <?= $escaper->escapeHtml(__(
                        "You can still explore WriteText.ai, but you won’t be able to generate text without credits."
                    )) ?>
                </p>
                <p>
                    <?= $escaper->escapeHtml(__(
                        "To unlock full access and continue generating product content, consider upgrading your plan."
                    )) ?>
                </p>
            </div>
            <div class="wtai-popup-buttons">
                <button type="button" class="action-default" data-bind="click: closeNoMoreTrialCreditsPopup">
                    <?= $escaper->escapeHtml(__("I'll do it later")) ?>
                </button>
                <a href="https://platform.writetext.ai/premium" target="_blank" class="action-primary primary">
                    <?= $escaper->escapeHtml(__("Check plans")) ?>
                </a>
            </div>
        </div>
    </div>
</div>
<script type="text/x-magento-init">
    {
        "*": {
            "Magento_Ui/js/core/app": {
                "components": {
                    "wtaiNoMoreTrialCreditsPopup": {
                        "component": "WriteTextAI_WriteTextAI/js/popups/no-more-trial-credits",
                        "saveUrl": "<?= $escaper->escapeJs($block->getUrl('wtai/settings/popups')) ?>",
                        "showPopupOnLoad": <?= $showPopup ? 'true' : 'false' ?>
                    }
                }
            }
        }
    }
</script>