@extends('admin.layouts.app')

@section('title', __('admin/quotes.title'))

@section('content')
<div class="container-fluid px-4">
    <x-admin.page-header
        :title="__('admin/quotes.title')"
        icon="fas fa-file-invoice"
        :buttons="[
            ['label' => __('admin/quotes.btn_create'), 'route' => route('admin.quotes.create'), 'icon' => 'fas fa-plus', 'color' => 'primary', 'permission' => 'create quotes'],
        ]"
    />

    <x-admin.card>
        <!-- Filters -->
        <div class="d-flex justify-content-between align-items-center mb-3">
            <!-- Search (Left) -->
            <div class="input-group input-group-sm" style="max-width: 220px;">
                <span class="input-group-text border-end-0 bg-transparent">
                    <i class="fas fa-search text-muted small"></i>
                </span>
                <input type="text"
                       class="form-control form-control-sm border-start-0 ps-0"
                       id="searchInput"
                       placeholder="{{ __('admin/common.search') }}...">
            </div>

            <!-- Status Filter (Right) -->
            <div class="d-flex gap-2">
                <select id="statusFilter" class="form-select form-select-sm" style="width: auto; min-width: 150px;">
                    <option value="all">{{ __('admin/quotes.filter_all') }}</option>
                    <option value="draft">{{ __('admin/quotes.status_draft') }}</option>
                    <option value="sent">{{ __('admin/quotes.status_sent') }}</option>
                    <option value="accepted">{{ __('admin/quotes.status_accepted') }}</option>
                    <option value="rejected">{{ __('admin/quotes.status_rejected') }}</option>
                    <option value="expired">{{ __('admin/quotes.status_expired') }}</option>
                    <option value="converted">{{ __('admin/quotes.status_converted') }}</option>
                </select>
            </div>
        </div>

        <!-- DataTable -->
        <div class="table-responsive">
            <table id="quotesTable" class="table table-hover align-middle mb-0">
                <thead>
                    <tr>
                        <th>{{ __('admin/quotes.table_quote_number') }}</th>
                        <th>{{ __('admin/quotes.table_subject') }}</th>
                        <th>{{ __('admin/quotes.table_client') }}</th>
                        <th>{{ __('admin/quotes.table_admin') }}</th>
                        <th>{{ __('admin/quotes.table_status') }}</th>
                        <th>{{ __('admin/quotes.table_total') }}</th>
                        <th>{{ __('admin/quotes.table_valid_until') }}</th>
                        <th>{{ __('admin/quotes.table_created_at') }}</th>
                        <th class="text-end">{{ __('admin/common.actions') }}</th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </x-admin.card>
</div>
@endsection

@push('scripts')
<script>
    window.pageConfig = window.pageConfig || {};
    window.pageConfig.permissions = {
        canEdit: {{ auth()->user()->hasPermissionTo('update quotes') ? 'true' : 'false' }},
        canDelete: {{ auth()->user()->hasPermissionTo('delete quotes') ? 'true' : 'false' }},
        canDownloadPdf: {{ auth()->user()->can('viewAny', App\Models\Quote::class) ? 'true' : 'false' }},
    };

    window.quoteIndexConfig = {
        routes: {
            records: '{{ route("api.admin.quotes.records") }}',
            destroy: '{{ route("api.admin.quotes.destroy", ":id") }}',
            edit: '{{ route("admin.quotes.edit", ":id") }}',
            downloadPdf: '{{ route("admin.quotes.download-pdf", ":id") }}'
        },
        translations: {
            status_draft: '{{ __("admin/quotes.status_draft") }}',
            status_sent: '{{ __("admin/quotes.status_sent") }}',
            status_accepted: '{{ __("admin/quotes.status_accepted") }}',
            status_rejected: '{{ __("admin/quotes.status_rejected") }}',
            status_expired: '{{ __("admin/quotes.status_expired") }}',
            status_converted: '{{ __("admin/quotes.status_converted") }}',
            confirm_delete: '{{ __("admin/quotes.confirm_delete") }}',
            btn_download_pdf: '{{ __("admin/quotes.btn_download_pdf") }}',
            btn_delete: '{{ __("admin/quotes.btn_delete") }}'
        },
        apiToken: window.getApiToken()
    };
</script>
@vite('resources/js/admin/quotes/index.js')
@endpush
