{% extends "subscriptions/base.html" %}
{% load static %}
{% load currency_filters %}

{% block title %}Pricing — SwiftPOS{% endblock %}
{% block meta_description %}Transparent, affordable pricing for every business size. Start free, upgrade as you grow.{% endblock %}

{% endblock %}

{% block content %}
<!-- HERO -->
<div class="pricing-hero">
    <h1>Simple, transparent pricing</h1>
    <p>Start free for 3 days. No credit card required. Cancel anytime.</p>

    <!-- Billing cycle switcher -->
    <div class="cycle-tabs" id="cycleTabs">
        <button class="cycle-tab active" data-cycle="monthly">Monthly</button>
        <button class="cycle-tab" data-cycle="bimonthly">2 Months</button>
        <button class="cycle-tab" data-cycle="trimonthly">3 Months</button>
        <button class="cycle-tab" data-cycle="yearly">Yearly <span style="background:#f59e0b;color:#fff;padding:1px 6px;border-radius:6px;font-size:0.65rem;margin-left:4px;">SAVE</span></button>
    </div>
</div>

<!-- PLANS GRID -->
<div class="plans-grid">
    {% for plan in plans %}
    {% with is_popular=forloop.counter0 %}
    <div class="plan-card {% if forloop.counter == 2 %}popular{% endif %}">
        {% if forloop.counter == 2 %}
        <div class="popular-badge">⭐ Most Popular</div>
        {% endif %}

        <div class="plan-name">{{ plan.name }}</div>
        <div class="plan-price-wrap">
            <!-- Monthly price (default shown) -->
            <div class="plan-price" data-plan-id="{{ plan.id }}"
                 data-monthly="{{ plan.price_monthly }}"
                 data-bimonthly="{{ plan.price_bimonthly }}"
                 data-trimonthly="{{ plan.price_trimonthly }}"
                 data-yearly="{{ plan.price_yearly }}">
                <span class="sym">₦</span><span class="amount">{{ plan.price_monthly|currency:0 }}</span><span class="per">/month</span>
            </div>
        </div>

        <ul class="plan-features">
            {% if plan.max_orders_per_day > 0 %}
            <li><i class="fas fa-check check"></i> {{ plan.max_orders_per_day }} orders/day</li>
            {% else %}
            <li><i class="fas fa-check check"></i> Unlimited orders</li>
            {% endif %}
            {% if plan.max_products > 0 %}
            <li><i class="fas fa-check check"></i> {{ plan.max_products }} products</li>
            {% else %}
            <li><i class="fas fa-check check"></i> Unlimited products</li>
            {% endif %}
            {% if plan.max_staff > 0 %}
            <li><i class="fas fa-check check"></i> Up to {{ plan.max_staff }} staff</li>
            {% else %}
            <li><i class="fas fa-check check"></i> Unlimited staff</li>
            {% endif %}
            <li><i class="fas fa-check check"></i> POS Terminal</li>
            {% if plan.feature_barcode_pos %}<li><i class="fas fa-check check"></i> Barcode POS</li>{% else %}<li><i class="fas fa-times cross"></i> <span class="locked">Barcode POS</span></li>{% endif %}
            {% if plan.feature_profit_loss %}<li><i class="fas fa-check check"></i> P&amp;L Reports</li>{% else %}<li><i class="fas fa-times cross"></i> <span class="locked">P&amp;L Reports</span></li>{% endif %}
            {% if plan.feature_audit_logs %}<li><i class="fas fa-check check"></i> Audit Logs</li>{% else %}<li><i class="fas fa-times cross"></i> <span class="locked">Audit Logs</span></li>{% endif %}
            {% if plan.feature_multi_branch %}<li><i class="fas fa-check check"></i> Multi-Branch ({{ plan.max_branches }} branches)</li>{% else %}<li><i class="fas fa-times cross"></i> <span class="locked">Multi-Branch</span></li>{% endif %}
            {% if plan.feature_bulk_import %}<li><i class="fas fa-check check"></i> Bulk Import</li>{% else %}<li><i class="fas fa-times cross"></i> <span class="locked">Bulk Import</span></li>{% endif %}
        </ul>

        <a href="/register/" class="btn-plan {% if forloop.counter == 2 %}btn-plan-primary{% else %}btn-plan-outline{% endif %}">
            Start Free Trial
        </a>

        <div class="limit-row">
            <span>Max branches: <strong>{{ plan.max_branches }}</strong></span>
            {% if plan.feature_android_app %}<span class="limit-badge"><i class="fab fa-android"></i> Android App</span>{% endif %}
        </div>
    </div>
    {% endwith %}
    {% endfor %}

    {% if not plans %}
    <div class="text-center py-5" style="grid-column: 1/-1;">
        <i class="fas fa-box-open" style="font-size:3rem;color:#cbd5e1;"></i>
        <p class="mt-3 text-muted">Plans coming soon. <a href="/register/">Start your free trial</a></p>
    </div>
    {% endif %}
</div>

<!-- FAQ -->
<div class="faq-section">
    <h2 class="faq-title">Frequently Asked Questions</h2>
    <div class="faq-item">
        <div class="faq-q">Is the 3-day trial really free? <i class="fas fa-chevron-down"></i></div>
        <div class="faq-a">Yes! No credit card required. You get full access to the system during your trial period.</div>
    </div>
    <div class="faq-item">
        <div class="faq-q">Can I upgrade or downgrade my plan? <i class="fas fa-chevron-down"></i></div>
        <div class="faq-a">Yes. Upgrades take effect immediately after payment. Downgrades are applied at the end of your current billing cycle.</div>
    </div>
    <div class="faq-item">
        <div class="faq-q">What payment methods are accepted? <i class="fas fa-chevron-down"></i></div>
        <div class="faq-a">We accept all Nigerian bank cards, bank transfers, USSD, and mobile money via Monnify — a CBN-licensed payment gateway.</div>
    </div>
    <div class="faq-item">
        <div class="faq-q">What happens when my subscription expires? <i class="fas fa-chevron-down"></i></div>
        <div class="faq-a">You'll receive reminder emails 3 days and 1 day before expiry. After expiry, you'll be redirected to renew your subscription. Your data is never deleted.</div>
    </div>
</div>
{% endblock %}

{% block extra_js %}
<script>
(function () {
    const priceData = {};
    document.querySelectorAll('.plan-price[data-plan-id]').forEach(el => {
        priceData[el.dataset.planId] = {
            monthly: parseFloat(el.dataset.monthly) || 0,
            bimonthly: parseFloat(el.dataset.bimonthly) || 0,
            trimonthly: parseFloat(el.dataset.trimonthly) || 0,
            yearly: parseFloat(el.dataset.yearly) || 0,
        };
    });

    const cycleLabels = {
        monthly: '/month',
        bimonthly: '/2 months',
        trimonthly: '/3 months',
        yearly: '/year',
    };

    function fmt(n) {
        return n.toLocaleString('en-NG', { minimumFractionDigits: 0, maximumFractionDigits: 0 });
    }

    function switchCycle(cycle) {
        document.querySelectorAll('.cycle-tab').forEach(t => t.classList.toggle('active', t.dataset.cycle === cycle));
        document.querySelectorAll('.plan-price[data-plan-id]').forEach(el => {
            const data = priceData[el.dataset.planId];
            const price = data[cycle] || data.monthly;
            el.querySelector('.amount').textContent = fmt(price);
            el.querySelector('.per').textContent = cycleLabels[cycle];
        });
    }

    document.querySelectorAll('.cycle-tab').forEach(btn => {
        btn.addEventListener('click', () => switchCycle(btn.dataset.cycle));
    });

    // FAQ accordion
    document.querySelectorAll('.faq-q').forEach(q => {
        q.addEventListener('click', () => q.closest('.faq-item').classList.toggle('open'));
    });
})();
</script>
{% endblock %}
