<?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();
    $hasProAccess = $premium->getHasProAccess();
    $membershipType = $premium->getMembershipType();
    $showByApi = !$hasProAccess && $membershipType === Premium::MEMBERSHIP_TYPE_FREE_TRIAL;

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

    $showPopup = $showByApi;
?>

<div class="wtai-end-trial-popup-modal" data-bind="scope: 'wtaiEndTrialPopup'" 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(__("Your free trial has ended.")) ?>
            </div>
            <div>
                <p>
                    <?= $escaper->escapeHtml(sprintf(__("Your %s-day free trial has ended."), $freeTrialDays)) ?>
                </p>
                <p>
                    <?= $escaper->escapeHtml(__("To continue using WriteText.ai features, please"
                    . " subscribe to Pro or purchase prepaid credits to get on Starter.")) ?>
                </p>
            </div>
            <div class="wtai-popup-buttons">
                <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": {
                    "wtaiEndTrialPopup": {
                        "component": "WriteTextAI_WriteTextAI/js/popups/end-trial",
                        "saveUrl": "<?= $escaper->escapeJs($block->getUrl('wtai/settings/popups')) ?>",
                        "showPopupOnLoad": <?= /* @noEscape */ $showPopup ? 'true' : 'false' ?>
                    }
                }
            }
        }
    }
</script>