<div class="card mb-3 voucher-list-filters-card">
    <div class="card-body py-3">
        @php
            $listQueryString = request()->getQueryString();
            $listPrintUrl = route('vouchers.print', $voucherType) . ($listQueryString ? '?' . $listQueryString : '');
            $listExportUrl = route('vouchers.export', $voucherType) . ($listQueryString ? '?' . $listQueryString : '');
        @endphp
        <form method="GET" action="{{ route('vouchers.index', $voucherType) }}" id="voucherListFilterForm">
            <div class="voucher-list-filter-grid">
                <div class="voucher-list-filter-field">
                    <label class="form-label fw-semibold">From date</label>
                    <input type="date" name="date_from" class="form-control" value="{{ $filters['date_from'] ?? '' }}">
                </div>
                <div class="voucher-list-filter-field">
                    <label class="form-label fw-semibold">To date</label>
                    <input type="date" name="date_to" class="form-control" value="{{ $filters['date_to'] ?? '' }}">
                </div>
                <div class="voucher-list-filter-field">
                    <label class="form-label fw-semibold">Min amount</label>
                    <input type="number" name="amount_min" class="form-control" value="{{ $filters['amount_min'] ?? '' }}" step="0.01" min="0" placeholder="">
                </div>
                <div class="voucher-list-filter-field">
                    <label class="form-label fw-semibold">Max amount</label>
                    <input type="number" name="amount_max" class="form-control" value="{{ $filters['amount_max'] ?? '' }}" step="0.01" min="0" placeholder="">
                </div>

                @if($filterOptions['hasPartyFilter'])
                <div class="voucher-list-filter-field">
                    <label class="form-label fw-semibold">{{ $filterOptions['partyFilterLabel'] }}</label>
                    @include('accounting.vouchers._list_party_filter', [
                        'filterOptions' => $filterOptions,
                        'filters' => $filters,
                        'selectedPartyLabel' => $selectedPartyLabel ?? 'All names',
                    ])
                </div>
                @endif

                @foreach($filterOptions['dimensionTrees'] as $slot => $dimension)
                <div class="voucher-list-filter-field">
                    <label class="form-label fw-semibold">{{ $dimension['name'] }}</label>
                    @include('accounting.vouchers._list_dimension_filter', [
                        'slot' => $slot,
                        'dimensionName' => $dimension['name'],
                        'tree' => $dimension['tree'],
                        'selectedValues' => $filters['dim'][$slot] ?? [],
                        'toggleLabel' => $dimensionLabels[$slot] ?? ('All ' . $dimension['name']),
                        'pickerId' => 'voucherDimFilter' . $slot,
                    ])
                </div>
                @endforeach

                <div class="voucher-list-filter-field">
                    <label class="form-label fw-semibold">Columns by</label>
                    @include('reports.profit-loss._multi-filter-picker', [
                        'pickerId' => 'voucherColumnsPicker',
                        'emptyLabel' => 'All columns',
                        'searchPlaceholder' => 'Search columns...',
                        'inputName' => 'columns[]',
                        'selectedValues' => $filters['columns'] ?? [],
                        'options' => $filterOptions['columns'],
                        'toggleLabel' => $selectedColumnsLabel ?? 'All columns',
                    ])
                </div>

                <div class="voucher-list-filter-field">
                    <label class="form-label fw-semibold">Sort By</label>
                    <select name="sort" class="form-select">
                        @foreach($filterOptions['sortOptions'] as $value => $label)
                            <option value="{{ $value }}" {{ ($filters['sort'] ?? '') === (string) $value ? 'selected' : '' }}>
                                {{ $label }}
                            </option>
                        @endforeach
                    </select>
                </div>
            </div>

            <div class="voucher-list-filter-row-secondary">
                <div class="voucher-list-filter-field voucher-list-filter-field-search">
                    <label class="form-label fw-semibold">Search</label>
                    <input type="text" name="search" class="form-control"
                           placeholder="Number, reference, memo…"
                           value="{{ $filters['search'] ?? '' }}">
                </div>
                <div class="voucher-list-filter-field voucher-list-filter-field-status">
                    <label class="form-label fw-semibold">Status</label>
                    <select name="status" class="form-select">
                        <option value="">All</option>
                        @foreach(['draft','submitted','approved','posted','cancelled'] as $status)
                            <option value="{{ $status }}" {{ ($filters['status'] ?? '') === $status ? 'selected' : '' }}>
                                {{ ucfirst($status) }}
                            </option>
                        @endforeach
                    </select>
                </div>
            </div>

            <div class="voucher-list-filter-actions">
                <div class="text-muted" style="font-size:12.5px">
                    {{ $vouchers->total() }} {{ \Illuminate\Support\Str::lower(\Illuminate\Support\Str::plural($recordLabel ?? 'voucher', $vouchers->total())) }}
                </div>
                <div class="d-flex flex-wrap gap-2">
                    <a href="{{ $listPrintUrl }}" class="btn btn-outline-secondary btn-sm" target="_blank" rel="noopener">
                        <i class="bi bi-printer me-1"></i>Print
                    </a>
                    <a href="{{ $listExportUrl }}" class="btn btn-outline-success btn-sm">
                        <i class="bi bi-download me-1"></i>Export
                    </a>
                    <button type="submit" class="btn btn-primary btn-sm">
                        <i class="bi bi-search me-1"></i>Apply
                    </button>
                    <a href="{{ route('vouchers.index', $voucherType) }}" class="btn btn-outline-secondary btn-sm">
                        <i class="bi bi-x-lg me-1"></i>Clear
                    </a>
                </div>
            </div>
        </form>
    </div>
</div>
