@extends('saas-admin.layout')

@section('title', 'Subscription plans')

@section('content')
    <div class="d-flex justify-content-between align-items-center mb-3">
        <h4 class="m-0">{{ __('Subscription plans') }}</h4>
        <a href="{{ route('saas-admin.subscription-plans.create') }}" class="btn btn-primary btn-sm">
            {{ __('+ New plan') }}
        </a>
    </div>

    <div class="card shadow-sm">
        <div class="table-responsive">
            <table class="table table-hover align-middle m-0">
                <thead class="table-light">
                    <tr>
                        <th>{{ __('Plan') }}</th>
                        <th>{{ __('Price') }}</th>
                        <th>{{ __('User limit') }}</th>
                        <th>{{ __('Custom domain') }}</th>
                        <th>{{ __('Status') }}</th>
                        <th>{{ __('Companies') }}</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    @forelse ($plans as $plan)
                        <tr>
                            <td>{{ $plan->name }}</td>
                            <td>{{ number_format($plan->price, 2) }} / {{ $plan->billing_interval }}</td>
                            <td>{{ $plan->user_limit ?? __('Unlimited') }}</td>
                            <td>{{ $plan->custom_domain_allowed ? __('Included') : __('Not included') }}</td>
                            <td>
                                <span class="badge {{ $plan->isActive() ? 'bg-success' : 'bg-secondary' }}">
                                    {{ ucfirst($plan->status) }}
                                </span>
                            </td>
                            <td>{{ $plan->company_subscriptions_count }}</td>
                            <td class="text-end">
                                <a href="{{ route('saas-admin.subscription-plans.edit', $plan) }}" class="btn btn-sm btn-outline-secondary">
                                    {{ __('Edit') }}
                                </a>
                                <form action="{{ route('saas-admin.subscription-plans.destroy', $plan) }}" method="POST" class="d-inline"
                                    onsubmit="return confirm('{{ __('Delete this plan?') }}')">
                                    @csrf
                                    @method('DELETE')
                                    <button type="submit" class="btn btn-sm btn-outline-danger">{{ __('Delete') }}</button>
                                </form>
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="7" class="text-center text-muted py-4">
                                {{ __('No subscription plans yet — create the first one.') }}
                            </td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>
@endsection
