@php
    use App\Modules\Procurement\Support\PurchaseOrderLifecycleStatus;

    $breadcrumbs = [
        ['label' => __('common.home'), 'url' => route('dashboard.index')],
        ['label' => __('procurement.breadcrumb_root')],
        ['label' => __('procurement.po.title')],
    ];
@endphp

<x-ui.layout.page
    :title="__('procurement.po.title')"
    :subtitle="__('procurement.po.subtitle')"
    page-icon="fe fe-file-text"
    :breadcrumbs="$breadcrumbs"
>
    <x-ui.operational.index-shell>
        <x-slot:toolbar>
            <x-ui.operational.action-bar>
                <x-slot:filters>
                    <form method="get" action="{{ route('procurement.purchase-orders.index') }}" class="row g-2 align-items-end">
                        <div class="col-md-4">
                            <label class="form-label small">{{ __('sales.orders.filters.status') }}</label>
                            <select name="status" class="form-select form-select-sm">
                                <option value="">{{ __('sales.orders.filters.all_statuses') }}</option>
                                @foreach (PurchaseOrderLifecycleStatus::cases() as $st)
                                    <option value="{{ $st->value }}" @selected($statusFilter === $st->value)>{{ $st->value }}</option>
                                @endforeach
                            </select>
                        </div>
                        <div class="col-md-2">
                            <button type="submit" class="btn btn-sm btn-primary">{{ __('sales.orders.filters.apply') }}</button>
                        </div>
                    </form>
                </x-slot:filters>
                <x-slot:secondary>
                    <span class="small text-muted">{{ __('operational_ui.speed.bulk.toolbar_hint') }}</span>
                </x-slot:secondary>
                <x-slot:primary>
                    @can('viewAny', App\Modules\Procurement\Models\PurchaseOrder::class)
                        <button type="button" class="btn btn-sm btn-outline-secondary" data-erp-select-page="#po-bulk-form">
                            {{ __('procurement.bulk.select_all') }}
                        </button>
                        <button
                            type="submit"
                            form="po-bulk-form"
                            formaction="{{ route('procurement.purchase-orders.bulk.approve') }}"
                            class="btn btn-sm btn-primary"
                            data-bulk-confirm="{{ __('procurement.bulk.confirm_approve', ['count' => '__COUNT__']) }}"
                            data-bulk-confirm-value="APPROVE_PO"
                        >{{ __('procurement.bulk.approve') }}</button>
                        <button
                            type="submit"
                            form="po-bulk-form"
                            formaction="{{ route('procurement.purchase-orders.bulk.cancel-drafts') }}"
                            class="btn btn-sm btn-outline-danger"
                            data-bulk-confirm="{{ __('procurement.bulk.confirm_cancel', ['count' => '__COUNT__']) }}"
                            data-bulk-confirm-value="CANCEL_PO"
                        >{{ __('procurement.bulk.cancel_drafts') }}</button>
                    @endcan
                </x-slot:primary>
            </x-ui.operational.action-bar>
        </x-slot:toolbar>

        @include('pages.procurement.purchase-orders.partials.index-table')

        <x-slot:pagination>
            {{ $purchaseOrders->links() }}
        </x-slot:pagination>
    </x-ui.operational.index-shell>
</x-ui.layout.page>
