{{-- Month period filter (GSTR) --}}
@php
    $months = $months ?? [];
    if ($months === []) {
        $cursor = now()->subMonths(24)->startOfMonth();
        $end = now()->addMonths(1)->startOfMonth();
        while ($cursor <= $end) {
            $months[] = $cursor->format('Y-m');
            $cursor->addMonth();
        }
        $months = array_reverse($months);
    }
@endphp
<div class="hub-filter">
    <div class="hub-filter__label">
        <i class="ri-calendar-2-line"></i>
        {{ $filterLabel ?? 'Financial Period between' }}
    </div>
    <form method="GET" action="{{ $formAction }}" id="{{ $formId }}" data-hub-filter-form data-auto-submit="false">
        <div class="hub-date-range">
            <select name="period_from" class="form-select form-select-sm" style="min-width: 9rem;" data-month-auto-submit>
                @foreach($months as $m)
                    <option value="{{ $m }}" @selected(($periodFrom ?? '') === $m)>{{ $m }}</option>
                @endforeach
            </select>
            <span class="hub-date-range__sep">to</span>
            <select name="period_to" class="form-select form-select-sm" style="min-width: 9rem;" data-month-auto-submit>
                @foreach($months as $m)
                    <option value="{{ $m }}" @selected(($periodTo ?? '') === $m)>{{ $m }}</option>
                @endforeach
            </select>
        </div>
        @if(!empty($showPresets))
            <div class="hub-date-presets">
                <button type="button" class="btn btn-outline-secondary btn-sm" data-date-preset="this_month">This month</button>
                <button type="button" class="btn btn-outline-secondary btn-sm" data-date-preset="last_month">Last month</button>
            </div>
        @endif
        <div class="hub-filter__actions">
            @if(!empty($exportButtons))
                @foreach($exportButtons as $btn)
                    <a href="#" class="btn btn-sm hub-btn-primary hub-btn-export" id="{{ $btn['id'] }}"
                       data-hub-export data-export-icon="{{ $btn['icon'] ?? 'ri-download-2-line' }}">
                        <i class="{{ $btn['icon'] ?? 'ri-download-2-line' }}"></i> {{ $btn['label'] }}
                    </a>
                @endforeach
            @elseif(!empty($exportId))
                <a href="#" class="btn btn-sm hub-btn-primary hub-btn-export" id="{{ $exportId }}"
                   data-hub-export data-export-icon="ri-download-2-line">
                    <i class="ri-download-2-line"></i> Export
                </a>
            @endif
        </div>
    </form>
</div>
