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

<?php
/** @var \WriteTextAI\WriteTextAI\ViewModel\Premium $premium */
/** @var \WriteTextAI\WriteTextAI\ViewModel\Footer $footer */

$premium = $block->getPremium();
$footer = $block->getFooter();
?>

<?php if ($footer->isLoggedIn()): ?>
    <?php
    $totalCredits = $premium->getTotalCredits(true);
    $availableCredits = $premium->getAvailableCredits();
    ?>
<div class="wtai-total-credits" data-bind="scope: 'wtaiTotalCredits'">
    <a href="https://platform.writetext.ai/premium" target="_blank">
        <span data-bind="text: getAvailableCreditsText()">
            <?= $block->escapeHtml(sprintf(__("%s credit available"), "-")) ?>
        </span>
    </a>
</div>
<div class="wtai-credit-help-container">
    <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-bottom-left" data-target="dropdown">
            <div class="wtai-content-wrapper">
                <a href="https://writetext.ai/knowledge-base/plans-pricing/how-is-credit-cost-calculated" target="_blank"> 
                    <?= $block->escapeHtml(__("How credit cost is calculated")); ?>
                </a>
            </div>
        </div>
    </div>
</div>
<script type="text/x-magento-init">
    {
        "*": {
            "Magento_Ui/js/core/app": {
                "components": {
                    "wtaiTotalCredits": {
                        "component": "WriteTextAI_WriteTextAI/js/total-credits",
                        "totalCredits": "<?= $block->escapeJs($totalCredits) ?>"
                    }
                }
            }
        }
    }
</script>
<?php endif; ?>
