@extends('admin.reports._layout')
@section('title', 'GSTR3B Report')

@php $reportTitle = 'GSTR3B Report'; @endphp

@section('reports_content')
<div class="hub-page">
    <div class="hub-page__header">
        <h1 class="hub-page__title">GSTR3B Report</h1>
        <p class="hub-page__subtitle">Monthly summary return — tables 3.1, 4, 5 and 6.1 for portal entry</p>
    </div>
    <div class="hub-page__body">
        @include('partials.admin.module-hub.filter-month', [
            'formAction' => route('admin.reports.gstr3b'),
            'formId' => 'gstr3b-period-form',
            'periodFrom' => $periodFrom,
            'periodTo' => $periodTo,
            'exportId' => 'gstr3b-export',
        ])

        @if(empty($company->gstin))
            <div class="hub-alert alert alert-warning mb-4">
                <i class="ri-error-warning-line"></i>
                <div>
                    Add your company <strong>GSTIN</strong> under
                    <a href="{{ route('admin.preferences.profile') }}" class="alert-link">Company profile</a>.
                </div>
            </div>
        @endif

        @include('partials.admin.module-hub.help', [
            'title' => 'Steps to File GSTR-3B',
            'ordered' => true,
            'items' => config('reports.gstr3b.filing_steps', []),
        ])
    </div>
</div>
@endsection

@push('scripts')
<script>
(function () {
    const form = document.getElementById('gstr3b-period-form');
    document.getElementById('gstr3b-export')?.addEventListener('click', function (e) {
        e.preventDefault();
        const params = new URLSearchParams({
            period_from: form.querySelector('[name="period_from"]').value,
            period_to: form.querySelector('[name="period_to"]').value,
        });
        window.location.href = @json(route('admin.reports.gstr3b.export')) + '?' + params.toString();
    });
})();
</script>
@endpush
