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

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

    $showPopup = $showByApi;
?>

<div class="wtai-start-trial-popup-modal" data-bind="scope: 'wtaiStartTrialPopup'" style="display: none;">
    <div class="wtai-popup-content">
        <div class="wtai-popup-image"></div>
        <div class="wtai-popup-text">
            <div class="wtai-popup-title">
                <?= $block->escapeHtml(__("You're on a free trial of WriteText.ai!")) ?>
            </div>
            <div>
                <p class="wtai-mb-twenty">
                    <?= /* @noEscape */sprintf(
                        __("Enjoy <strong>%s complimentary credits</strong> and " .
                            "<strong>full access to all features</strong> for <strong>%s days</strong>."),
                        $freeTrialCredits,
                        $freeTrialDays)
                    ?>
                </p>
                <p>
                    <?= /* @noEscape */__('Start generating text by clicking on a product.') ?>
                </p>
            </div>
            <div class="wtai-popup-buttons">
                <button type="button" class="action-primary primary" data-bind="click: closeStartTrialPopup">
                    <?= $block->escapeHtml(__('Got it')) ?>
                </button>
            </div>
        </div>
    </div>
</div>
<script type="text/x-magento-init">
    {
        "*": {
            "Magento_Ui/js/core/app": {
                "components": {
                    "wtaiStartTrialPopup": {
                        "component": "WriteTextAI_WriteTextAI/js/popups/start-trial",
                        "saveUrl": "<?= $block->escapeJs($block->getUrl('wtai/settings/popups')) ?>",
                        "showPopupOnLoad": <?= /* @noEscape */ $showPopup ? 'true' : 'false' ?>
                    }
                }
            }
        }
    }
</script>