@extends('layouts.superadmin')
@section('title', 'Assinaturas')
@section('page-title', 'Assinaturas')
@section('content')
    <p class="mb-4 text-sm text-slate-600">Past due: <strong>{{ $pastDueCount }}</strong></p>
    <div class="overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-sm">
        <table class="min-w-full text-left text-sm">
            <thead class="bg-slate-50 text-xs uppercase tracking-wide text-slate-500">
                <tr>
                    <th class="px-4 py-3">Cliente</th>
                    <th class="px-4 py-3">Plano</th>
                    <th class="px-4 py-3">Preço mensal</th>
                    <th class="px-4 py-3">Status</th>
                    <th class="px-4 py-3">Ciclo</th>
                </tr>
            </thead>
            <tbody>
                @foreach ($subscriptions as $sub)
                    @php
                        $monthly = (int) ($sub->plan?->price_monthly_cents ?? 0);
                        if (($sub->billing_cycle?->value ?? $sub->billing_cycle) === 'yearly') {
                            $monthly = (int) round(((int) ($sub->plan?->price_yearly_cents ?? 0)) / 12);
                        }
                    @endphp
                    <tr class="border-t border-slate-100">
                        <td class="px-4 py-3">{{ $sub->tenant?->name ?? $sub->tenant_id }}</td>
                        <td class="px-4 py-3">{{ $sub->plan?->name }}</td>
                        <td class="px-4 py-3">R$ {{ number_format($monthly / 100, 2, ',', '.') }}</td>
                        <td class="px-4 py-3">{{ $sub->status?->label() ?? $sub->status }}</td>
                        <td class="px-4 py-3">{{ $sub->billing_cycle?->value ?? $sub->billing_cycle }}</td>
                    </tr>
                @endforeach
            </tbody>
        </table>
    </div>
    <div class="mt-4">{{ $subscriptions->links() }}</div>
@endsection
