@extends('layouts.admin')

@section('title', 'Manage Subscription Plans')

@section('admin-content')
<style>
    /* Specific Plans Styles */
    .plans-page .price-badge { font-weight: 700; color: #2e7d32; background: #e8f5e9; padding: 4px 10px; border-radius: 6px; font-size: 0.9rem; }
    .plans-page .currency-label { color: #6c757d; font-size: 0.75rem; margin-right: 4px; font-weight: 500; }
    .plans-page .duration-badge { display: inline-flex; align-items: center; gap: 5px; padding: 5px 12px; background: #f0f2f5; color: #555; border-radius: 50px; font-size: 0.8rem; font-weight: 600; }
</style>

<div class="plans-page">
    <!-- Page Header -->
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h4 class="fw-bold mb-1">Subscription Plans</h4>
            <p class="text-muted mb-0 small">Manage packages and pricing for sellers</p>
        </div>
        <div class="d-flex gap-2">
            <a href="{{ route('admin.plans.create') }}" class="btn btn-primary shadow-sm btn-lg d-flex align-items-center gap-2" 
               style="border-radius: 12px; font-size: 0.95rem;">
                <i class="bi bi-plus-lg"></i> Create New Plan
            </a>
        </div>
    </div>

    @if(session('success'))
        <div class="alert alert-success border-0 shadow-sm rounded-3 mb-4 d-flex align-items-center">
            <i class="bi bi-check-circle-fill me-2 fs-5"></i>
            {{ session('success') }}
        </div>
    @endif

    <!-- Stats Overview -->
    <div class="row g-4 mb-4">
        <div class="col-md-4">
            <div class="stat-card d-flex align-items-center gap-3">
                <div class="stat-icon primary">
                    <i class="bi bi-box-seam"></i>
                </div>
                <div>
                    <div class="stat-value">{{ $plans->count() }}</div>
                    <div class="stat-label">Total Plans</div>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="stat-card d-flex align-items-center gap-3">
                <div class="stat-icon success">
                    <i class="bi bi-toggle-on"></i>
                </div>
                <div>
                    <div class="stat-value">{{ $plans->where('is_active', true)->count() }}</div>
                    <div class="stat-label">Active Plans</div>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="stat-card d-flex align-items-center gap-3">
                <div class="stat-icon info">
                    <i class="bi bi-currency-exchange"></i>
                </div>
                <div>
                    <div class="stat-value">{{ $plans->where('price_inr', '>', 0)->count() }}</div>
                    <div class="stat-label">Paid Plans</div>
                </div>
            </div>
        </div>
    </div>

    <!-- Plans Table -->
    <div class="data-table">
        <div class="table-responsive">
            <table class="table mb-0">
                <thead>
                    <tr>
                        <th class="ps-4">Plan Name</th>
                        <th>Pricing (INR)</th>
                        <th>Pricing (USD)</th>
                        <th>Duration</th>
                        <th class="text-center">Status</th>
                        <th class="text-end pe-4">Actions</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($plans as $plan)
                        <tr>
                            <td class="ps-4">
                                <h6 class="fw-bold text-dark mb-0">{{ $plan->name }}</h6>
                                <small class="text-muted">ID: {{ $plan->id }}</small>
                            </td>
                            <td>
                                <span class="price-badge">
                                    <span class="currency-label">INR</span>₹{{ number_format($plan->price_inr, 2) }}
                                </span>
                            </td>
                            <td>
                                <span class="price-badge" style="background: #e3f2fd; color: #1565c0;">
                                    <span class="currency-label">USD</span>${{ number_format($plan->price_usd, 2) }}
                                </span>
                            </td>
                            <td>
                                <span class="duration-badge">
                                    <i class="bi bi-clock-history"></i> {{ $plan->duration_days }} Days
                                </span>
                            </td>
                            <td class="text-center">
                                @if($plan->is_active)
                                    <span class="status-badge active">
                                        <i class="bi bi-check-circle-fill"></i> Active
                                    </span>
                                @else
                                    <span class="status-badge inactive">
                                        <i class="bi bi-dash-circle-fill"></i> Inactive
                                    </span>
                                @endif
                            </td>
                            <td class="text-end pe-4">
                                <div class="d-flex gap-1 justify-content-end">
                                    <a href="{{ route('admin.plans.show', $plan->id) }}" class="action-btn info" title="View Details" data-bs-toggle="tooltip">
                                        <i class="bi bi-eye"></i>
                                    </a>
                                    <a href="{{ route('admin.plans.edit', $plan->id) }}" class="action-btn primary" title="Edit Plan" data-bs-toggle="tooltip">
                                        <i class="bi bi-pencil"></i>
                                    </a>
                                    
                                    <form action="{{ route('admin.plans.destroy', $plan->id) }}" method="POST" class="d-inline"
                                          onsubmit="return confirm('Are you sure you want to delete this plan?');">
                                        @csrf
                                        @method('DELETE')
                                        <button type="submit" class="action-btn danger" title="Delete Plan" data-bs-toggle="tooltip">
                                            <i class="bi bi-trash"></i>
                                        </button>
                                    </form>
                                </div>
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="6" class="text-center py-5">
                                <div class="py-4">
                                    <i class="bi bi-box-seam fs-1 text-muted opacity-50 d-block mb-3"></i>
                                    <h5 class="fw-bold text-muted">No Plans Found</h5>
                                    <p class="text-muted small mb-0">Create a subscription plan to get started</p>
                                </div>
                            </td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>
</div>

<script>
    document.addEventListener('DOMContentLoaded', function() {
        var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
        tooltipTriggerList.map(function (el) {
            return new bootstrap.Tooltip(el);
        });
    });
</script>
@endsection
