<?php $__env->startSection('title', 'Subscription'); ?>
<?php $__env->startSection('page-title', 'Settings'); ?>

<?php $__env->startPush('styles'); ?>
<style>
    .plan-card { border-radius:12px; border:2px solid #e2e8f0; transition:all 0.2s; position:relative; overflow:hidden; background:white; }
    .plan-card:hover { border-color:#00a651; transform:translateY(-2px); box-shadow:0 8px 24px rgba(0,166,81,0.12); }
    .plan-card.current { border-color:#00a651; }
    .plan-card.popular { border-color:#7c3aed; }
    .popular-badge { position:absolute; top:0; right:0; background:#7c3aed; color:white; font-size:0.7rem; font-weight:700; padding:4px 12px; border-radius:0 0 0 8px; text-transform:uppercase; letter-spacing:0.05em; }
    .current-badge { position:absolute; top:0; left:0; right:0; background:#00a651; color:white; font-size:0.7rem; font-weight:700; padding:5px; text-align:center; text-transform:uppercase; letter-spacing:0.06em; }
    .plan-price { font-size:2rem; font-weight:800; color:#1e293b; line-height:1; }
    .plan-price span { font-size:0.9rem; font-weight:400; color:#94a3b8; }
    .feature-item { display:flex; align-items:center; gap:8px; font-size:0.875rem; color:#374151; padding:4px 0; }
    .feature-item i { color:#00a651; flex-shrink:0; }
    .feature-item.locked i { color:#cbd5e1; }
    .feature-item.locked span { color:#94a3b8; }
    .btn-upgrade { font-weight:700; padding:0.7rem 1rem; border-radius:8px; width:100%; border:none; font-size:0.95rem; transition:all 0.15s; cursor:pointer; }
    .btn-upgrade:hover:not(:disabled) { transform:translateY(-1px); box-shadow:0 4px 12px rgba(0,0,0,0.15); }
    .expires-bar { height:6px; background:#e2e8f0; border-radius:3px; overflow:hidden; margin-top:8px; }
    .expires-fill { height:100%; border-radius:3px; transition:width 0.5s; }
</style>
<?php $__env->stopPush(); ?>

<?php $__env->startSection('content'); ?>
<?php echo $__env->make('settings.partials.tabs', ['active' => 'subscription'], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>


<?php if(session('success')): ?>
    <div class="alert alert-success rounded-3 d-flex align-items-center gap-2 mb-4">
        <i class="bi bi-check-circle-fill"></i> <?php echo e(session('success')); ?>

    </div>
<?php endif; ?>
<?php if(session('error')): ?>
    <div class="alert alert-danger rounded-3 d-flex align-items-center gap-2 mb-4">
        <i class="bi bi-exclamation-circle-fill"></i> <?php echo e(session('error')); ?>

    </div>
<?php endif; ?>


<div class="card table-card p-4 mb-4"
     style="background:linear-gradient(135deg,#0f1923,#1a2b3c);border:none;">
    <div class="d-flex align-items-center justify-content-between flex-wrap gap-3">
        <div>
            <div style="color:rgba(255,255,255,0.6);font-size:0.75rem;text-transform:uppercase;letter-spacing:0.08em;margin-bottom:4px;">
                Current Plan
            </div>
            <div class="d-flex align-items-center gap-2 flex-wrap">
                <span style="font-size:1.5rem;font-weight:800;color:white;">
                    <?php echo e(auth()->user()->plan_label); ?> Plan
                </span>
                <span style="background:#00a651;color:white;font-size:0.7rem;font-weight:700;padding:3px 8px;border-radius:20px;text-transform:uppercase;">
                    Active
                </span>
            </div>

            <?php if(auth()->user()->plan_expires_at && !auth()->user()->isFreePlan()): ?>
                <?php
                    $expiresAt = auth()->user()->plan_expires_at;
                    $daysLeft  = max(0, (int) now()->diffInDays($expiresAt, false));
                    $pctLeft   = min(100, ($daysLeft / 30) * 100);
                    $barColor  = $daysLeft <= 5 ? '#ef4444' : '#00a651';
                ?>
                <div style="color:rgba(255,255,255,0.6);font-size:0.82rem;margin-top:6px;">
                    Expires <?php echo e($expiresAt->format('d M Y')); ?>

                    (<?php echo e($daysLeft); ?> day<?php echo e($daysLeft !== 1 ? 's' : ''); ?> remaining)
                </div>
                <div class="expires-bar" style="max-width:200px;">
                    <div class="expires-fill" style="width:<?php echo e($pctLeft); ?>%;background:<?php echo e($barColor); ?>;"></div>
                </div>
            <?php elseif(auth()->user()->isFreePlan()): ?>
                <div style="color:rgba(255,255,255,0.5);font-size:0.82rem;margin-top:6px;">
                    <?php echo e(auth()->user()->monthlyInvoiceCount()); ?>/<?php echo e(config('invotrack.free_invoice_limit')); ?> invoices used this month
                </div>
            <?php endif; ?>
        </div>

        <?php if(!auth()->user()->isFreePlan()): ?>
            <form method="POST" action="<?php echo e(route('subscription.cancel')); ?>"
                  onsubmit="return confirm('Cancel your subscription? You will be moved to the Free plan immediately.')">
                <?php echo csrf_field(); ?>
                <button type="submit" class="btn btn-sm btn-outline-light opacity-75">
                    Cancel Subscription
                </button>
            </form>
        <?php endif; ?>
    </div>
</div>


<div class="row g-3 mb-4">

    
    <div class="col-md-4">
        <div class="plan-card p-4 h-100 <?php echo e(auth()->user()->isFreePlan() ? 'current' : ''); ?>">
            <?php if(auth()->user()->isFreePlan()): ?>
                <div class="current-badge">✓ Current Plan</div>
            <?php endif; ?>
            <div style="margin-top:<?php echo e(auth()->user()->isFreePlan() ? '28px' : '8px'); ?>;"></div>

            <div class="mb-3">
                <div style="font-size:0.8rem;font-weight:700;color:#64748b;text-transform:uppercase;letter-spacing:0.06em;margin-bottom:8px;">Free</div>
                <div class="plan-price">₦0 <span>/month</span></div>
            </div>

            <div class="mb-4">
                <div class="feature-item"><i class="bi bi-check-circle-fill"></i><span>5 invoices/month</span></div>
                <div class="feature-item"><i class="bi bi-check-circle-fill"></i><span>Client management</span></div>
                <div class="feature-item"><i class="bi bi-check-circle-fill"></i><span>PDF downloads</span></div>
                <div class="feature-item"><i class="bi bi-check-circle-fill"></i><span>Basic dashboard</span></div>
                <div class="feature-item locked"><i class="bi bi-x-circle-fill"></i><span>Expense tracking</span></div>
                <div class="feature-item locked"><i class="bi bi-x-circle-fill"></i><span>Payment reminders</span></div>
                <div class="feature-item locked"><i class="bi bi-x-circle-fill"></i><span>Reports & export</span></div>
            </div>

            <button class="btn-upgrade" style="background:#f1f5f9;color:#94a3b8;" disabled>
                <?php echo e(auth()->user()->isFreePlan() ? 'Current Plan' : 'Free Plan'); ?>

            </button>
        </div>
    </div>

    
    <div class="col-md-4">
        <div class="plan-card p-4 h-100 <?php echo e(auth()->user()->isProPlan() ? 'current' : 'popular'); ?>">
            <?php if(auth()->user()->isProPlan()): ?>
                <div class="current-badge">✓ Current Plan</div>
            <?php else: ?>
                <div class="popular-badge">Most Popular</div>
            <?php endif; ?>
            <div style="margin-top:28px;"></div>

            <div class="mb-3">
                <div style="font-size:0.8rem;font-weight:700;color:#7c3aed;text-transform:uppercase;letter-spacing:0.06em;margin-bottom:8px;">Pro</div>
                <div class="plan-price">₦5,000 <span>/month</span></div>
            </div>

            <div class="mb-4">
                <div class="feature-item"><i class="bi bi-check-circle-fill"></i><span>Unlimited invoices</span></div>
                <div class="feature-item"><i class="bi bi-check-circle-fill"></i><span>Client management</span></div>
                <div class="feature-item"><i class="bi bi-check-circle-fill"></i><span>PDF downloads</span></div>
                <div class="feature-item"><i class="bi bi-check-circle-fill"></i><span>Expense tracking</span></div>
                <div class="feature-item"><i class="bi bi-check-circle-fill"></i><span>Automated reminders</span></div>
                <div class="feature-item"><i class="bi bi-check-circle-fill"></i><span>Email notifications</span></div>
                <div class="feature-item locked"><i class="bi bi-x-circle-fill"></i><span>Reports & export</span></div>
            </div>

            <?php if(auth()->user()->isProPlan()): ?>
                <button class="btn-upgrade" style="background:#f1f5f9;color:#94a3b8;" disabled>Current Plan</button>
            <?php else: ?>
                <form method="POST" action="<?php echo e(route('subscription.initiate')); ?>">
                    <?php echo csrf_field(); ?>
                    <input type="hidden" name="plan" value="pro">
                    <button type="submit" class="btn-upgrade" style="background:#7c3aed;color:white;">
                        <i class="bi bi-lightning-charge-fill me-2"></i>Upgrade — ₦5,000/mo
                    </button>
                </form>
            <?php endif; ?>
        </div>
    </div>

    
    <div class="col-md-4">
        <div class="plan-card p-4 h-100 <?php echo e(auth()->user()->isBusinessPlan() ? 'current' : ''); ?>">
            <?php if(auth()->user()->isBusinessPlan()): ?>
                <div class="current-badge">✓ Current Plan</div>
            <?php endif; ?>
            <div style="margin-top:<?php echo e(auth()->user()->isBusinessPlan() ? '28px' : '8px'); ?>;"></div>

            <div class="mb-3">
                <div style="font-size:0.8rem;font-weight:700;color:#d97706;text-transform:uppercase;letter-spacing:0.06em;margin-bottom:8px;">Business</div>
                <div class="plan-price">₦15,000 <span>/month</span></div>
            </div>

            <div class="mb-4">
                <div class="feature-item"><i class="bi bi-check-circle-fill"></i><span>Everything in Pro</span></div>
                <div class="feature-item"><i class="bi bi-check-circle-fill"></i><span>Revenue reports</span></div>
                <div class="feature-item"><i class="bi bi-check-circle-fill"></i><span>Top clients report</span></div>
                <div class="feature-item"><i class="bi bi-check-circle-fill"></i><span>VAT report</span></div>
                <div class="feature-item"><i class="bi bi-check-circle-fill"></i><span>CSV export</span></div>
                <div class="feature-item"><i class="bi bi-check-circle-fill"></i><span>Priority support</span></div>
            </div>

            <?php if(auth()->user()->isBusinessPlan()): ?>
                <button class="btn-upgrade" style="background:#f1f5f9;color:#94a3b8;" disabled>Current Plan</button>
            <?php else: ?>
                <form method="POST" action="<?php echo e(route('subscription.initiate')); ?>">
                    <?php echo csrf_field(); ?>
                    <input type="hidden" name="plan" value="business">
                    <button type="submit" class="btn-upgrade"
                            style="background:linear-gradient(135deg,#d97706,#b45309);color:white;">
                        <i class="bi bi-star-fill me-2"></i>Upgrade — ₦15,000/mo
                    </button>
                </form>
            <?php endif; ?>
        </div>
    </div>

</div>


<?php if($subscriptions->isNotEmpty()): ?>
<div class="card table-card mb-3">
    <div class="p-3 border-bottom">
        <h6 class="fw-700 mb-0" style="color:#1e293b;">Payment History</h6>
    </div>
    <div class="table-responsive">
        <table class="table mb-0">
            <thead>
                <tr>
                    <th>Plan</th>
                    <th>Amount</th>
                    <th class="d-none d-md-table-cell">Reference</th>
                    <th class="d-none d-md-table-cell">Date</th>
                    <th class="d-none d-md-table-cell">Expires</th>
                    <th>Status</th>
                </tr>
            </thead>
            <tbody>
                <?php $__currentLoopData = $subscriptions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $sub): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <tr>
                    <td class="fw-500"><?php echo e($sub->plan_label); ?></td>
                    <td>₦<?php echo e(number_format($sub->amount, 2)); ?></td>
                    <td class="d-none d-md-table-cell">
                        <span style="font-family:monospace;font-size:0.75rem;color:#64748b;">
                            <?php echo e($sub->paystack_reference); ?>

                        </span>
                    </td>
                    <td class="d-none d-md-table-cell text-muted small">
                        <?php echo e($sub->starts_at?->format('d/m/Y') ?? '—'); ?>

                    </td>
                    <td class="d-none d-md-table-cell text-muted small">
                        <?php echo e($sub->expires_at?->format('d/m/Y') ?? '—'); ?>

                    </td>
                    <td>
                        <?php
                            $style = match($sub->status) {
                                'active'    => 'background:#dcfce7;color:#15803d;',
                                'pending'   => 'background:#fef9c3;color:#92400e;',
                                'expired','cancelled' => 'background:#f1f5f9;color:#64748b;',
                                'failed'    => 'background:#fee2e2;color:#b91c1c;',
                                default     => 'background:#f1f5f9;color:#64748b;',
                            };
                        ?>
                        <span style="font-size:0.72rem;font-weight:700;padding:3px 10px;border-radius:20px;text-transform:uppercase;<?php echo e($style); ?>">
                            <?php echo e(ucfirst($sub->status)); ?>

                        </span>
                    </td>
                </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </tbody>
        </table>
    </div>
</div>
<?php endif; ?>

<div class="p-3 rounded" style="background:#f8fafc;border:1px solid #e2e8f0;font-size:0.82rem;color:#64748b;">
    <i class="bi bi-info-circle me-1"></i>
    Subscriptions are billed monthly and activate immediately after payment.
    Secured by Paystack. For support: <strong>support@invotrack.ng</strong>
</div>

<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\Users\Bunmi\Desktop\crud\resources\views/settings/subscription.blade.php ENDPATH**/ ?>