{% 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 %}

{% block extra_style %}
.pricing-hero {
    text-align: center;
    padding: 4rem 1.5rem 2rem;
    background: linear-gradient(135deg, #4c1d95 0%, #7c3aed 60%, #6366f1 100%);
    color: #fff;
}
.pricing-hero h1 { font-size: 2.8rem; font-weight: 900; margin-bottom: 0.75rem; }
.pricing-hero p { font-size: 1.1rem; opacity: 0.85; max-width: 520px; margin: 0 auto 2rem; }

.cycle-tabs {
    display: inline-flex;
    background: rgba(255,255,255,0.15);
    border-radius: 12px;
    padding: 4px;
    gap: 2px;
    flex-wrap: wrap;
    justify-content: center;
}
.cycle-tab {
    padding: 0.45rem 1.1rem;
    border-radius: 9px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    background: transparent;
    color: rgba(255,255,255,0.7);
    transition: all 0.2s;
}
.cycle-tab.active {
    background: #fff;
    color: var(--primary);
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

.plans-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    max-width: 1050px;
    margin: 0 auto;
    padding: 3rem 1.5rem;
}

.plan-card {
    background: #fff;
    border-radius: 20px;
    border: 2px solid var(--border);
    padding: 2rem;
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
    position: relative;
    overflow: hidden;
}
.plan-card:hover { transform: translateY(-6px); box-shadow: var(--shadow-lg); }
.plan-card.popular {
    border-color: var(--primary);
    transform: scale(1.03);
}
.plan-card.popular:hover { transform: scale(1.03) translateY(-6px); }

.popular-badge {
    position: absolute;
    top: 0; right: 0;
    background: linear-gradient(135deg, #7c3aed, #6366f1);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.35rem 1rem;
    border-radius: 0 18px 0 12px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.plan-name { font-size: 1.1rem; font-weight: 700; color: var(--text-dark); margin-bottom: 0.5rem; }
.plan-price-wrap { margin: 1.25rem 0; }
.plan-price {
    font-size: 2.4rem;
    font-weight: 900;
    color: var(--text-dark);
    line-height: 1;
}
.plan-price .sym { font-size: 1.4rem; vertical-align: top; margin-top: 0.35rem; display: inline-block; }
.plan-price .per { font-size: 0.82rem; color: var(--text-muted); font-weight: 500; margin-left: 0.25rem; }
.plan-desc { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 1.5rem; }

.plan-features { list-style: none; display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 1.75rem; }
.plan-features li { display: flex; align-items: center; gap: 0.6rem; font-size: 0.83rem; }
.plan-features .check { color: var(--success); font-size: 0.75rem; }
.plan-features .cross { color: #cbd5e1; font-size: 0.75rem; }
.plan-features .locked { color: var(--text-muted); }

.btn-plan {
    display: block;
    width: 100%;
    padding: 0.8rem;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 700;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    border: none;
    transition: opacity 0.2s, transform 0.15s;
    font-family: inherit;
}
.btn-plan-primary {
    background: linear-gradient(135deg, #7c3aed, #6366f1);
    color: #fff;
}
.btn-plan-primary:hover { opacity: 0.9; transform: translateY(-1px); color:#fff; }
.btn-plan-outline {
    background: transparent;
    border: 1.5px solid var(--border);
    color: var(--text-dark);
}
.btn-plan-outline:hover { border-color: var(--primary); color: var(--primary); }

.limit-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    border-top: 1px solid var(--border);
    padding-top: 1rem;
    margin-top: 0.5rem;
    color: var(--text-muted);
    flex-wrap: wrap;
    gap: 0.5rem;
}
.limit-badge {
    background: var(--primary-light);
    color: var(--primary);
    padding: 0.15rem 0.6rem;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
}

.faq-section { max-width: 700px; margin: 0 auto; padding: 2rem 1.5rem 4rem; }
.faq-title { font-size: 1.6rem; font-weight: 800; text-align: center; margin-bottom: 2rem; }
.faq-item { border: 1px solid var(--border); border-radius: 12px; margin-bottom: 1rem; overflow: hidden; }
.faq-q {
    padding: 1rem 1.25rem;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.faq-a { padding: 0 1.25rem 1rem; font-size: 0.85rem; color: var(--text-muted); line-height: 1.6; display: none; }
.faq-item.open .faq-a { display: block; }
.faq-item.open .faq-q i { transform: rotate(180deg); }
.faq-q i { transition: transform 0.2s; }
{% 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 %}
