@php
    $breadcrumbs = [
        ['label' => __('common.home'), 'url' => route('dashboard.index')],
        ['label' => __('admin.title'), 'url' => route('admin.dashboard')],
        ['label' => __('plans.title')],
    ];
@endphp

<x-ui.layout.page
    :title="__('plans.title')"
    :subtitle="__('plans.subtitle')"
    page-icon="fe fe-package"
    :breadcrumbs="$breadcrumbs"
>
    <x-slot:actions>
        @can('plans.create')
            <x-ui.buttons.primary :href="route('admin.plans.create')" icon="fe fe-plus">
                {{ __('plans.actions.add') }}
            </x-ui.buttons.primary>
        @endcan
    </x-slot:actions>

    <x-ui.table.table :columns="[
        ['label' => __('plans.fields.name')],
        ['label' => __('plans.fields.price')],
        ['label' => __('plans.fields.cycle')],
        ['label' => __('plans.fields.modules')],
        ['label' => __('plans.fields.tenants')],
        ['label' => __('plans.fields.flags')],
        ['label' => __('common.actions'), 'align' => 'end', 'width' => '120px'],
    ]">
        @forelse ($plans as $plan)
            <x-ui.table.row>
                <td>
                    <strong>{{ $plan->name }}</strong><br>
                    <small class="text-muted">{{ $plan->slug }}</small>
                </td>
                <td>{{ number_format((float) $plan->price, 2) }} {{ $plan->currency }}</td>
                <td>{{ __('plans.cycles.'.$plan->billing_cycle) }}</td>
                <td>
                    @forelse ($plan->modules as $module)
                        <span class="badge bg-primary-subtle text-primary">{{ $module->name }}</span>
                    @empty
                        <span class="text-muted">—</span>
                    @endforelse
                </td>
                <td>{{ $plan->tenants_count ?? 0 }}</td>
                <td>
                    @if ($plan->is_trial)
                        <span class="badge bg-warning-subtle text-warning">{{ __('plans.trial') }}</span>
                    @endif
                    @if ($plan->is_default)
                        <span class="badge bg-info-subtle text-info">{{ __('plans.default') }}</span>
                    @endif
                    @if ($plan->is_active)
                        <span class="badge bg-success">{{ __('common.active') }}</span>
                    @else
                        <span class="badge bg-secondary">{{ __('common.inactive') }}</span>
                    @endif
                </td>
                <td class="text-end">
                    <x-ui.table.actions-trigger
                        :type="__('plans.singular')"
                        :id="$plan->id"
                        :view-href="auth()->user()?->can('plans.update', $plan) ? route('admin.plans.edit', $plan) : null"
                        :delete-url="auth()->user()?->can('plans.delete', $plan) ? route('admin.plans.destroy', $plan) : null"
                    />
                </td>
            </x-ui.table.row>
        @empty
            <x-ui.table.row>
                <td colspan="7" class="text-center text-muted py-4">
                    {{ __('plans.empty') }}
                </td>
            </x-ui.table.row>
        @endforelse
    </x-ui.table.table>

    <x-ui.modal.actions />
</x-ui.layout.page>
