@extends('layouts.app')

@section('title', __('messages.vat_zatca'))

@section('content')
<div class="d-flex align-items-center justify-content-between mb-3">
    <div>
        <h5 class="fw-bold mb-0">Saudi VAT & ZATCA Phase 1 Configuration</h5>
        <span class="text-muted fs-xs">E-Invoicing Phase 1 Mandate Settings, QR Codes, Tax Preferences & Invoice Defaults</span>
    </div>
</div>

<div class="card-erp p-3">
    <form method="POST" action="{{ route('settings.zatca.update') }}">
        @csrf

        <div class="alert alert-info border-info d-flex align-items-center py-2 small mb-4">
            <i class="bi bi-info-circle-fill fs-5 me-2"></i>
            <div>
                <strong>ZATCA Phase 1 Active Mode:</strong> System is running in ZATCA Phase 1 compliant TLV QR Code generation mode. Architecture is prepared for seamless Phase 2 integration when required.
            </div>
        </div>

        <div class="row g-3 mb-3">
            <div class="col-md-4">
                <label class="form-label small fw-semibold">ZATCA Mode</label>
                <input type="text" name="zatca_mode" class="form-control form-control-sm font-monospace fw-bold" value="{{ old('zatca_mode', $vatSetting->zatca_mode) }}" readonly>
            </div>
            <div class="col-md-4">
                <label class="form-label small fw-semibold">VAT Registration Number</label>
                <input type="text" name="vat_number" class="form-control form-control-sm font-monospace fw-bold" value="{{ old('vat_number', $vatSetting->vat_number) }}" placeholder="302176698800003">
            </div>
            <div class="col-md-4">
                <label class="form-label small fw-semibold">Default VAT Rate (%)</label>
                <input type="number" step="0.01" name="default_vat_rate" class="form-control form-control-sm" value="{{ old('default_vat_rate', $vatSetting->default_vat_rate) }}" required>
            </div>
        </div>

        <h6 class="fw-bold border-bottom pb-2 mt-4 text-primary"><i class="bi bi-qr-code me-1"></i> QR Code & Invoicing Preferences</h6>
        <div class="row g-3 mb-3">
            <div class="col-md-4">
                <label class="form-label small fw-semibold">QR Code Size</label>
                <select name="qr_size" class="form-select form-select-sm" required>
                    <option value="Small" {{ old('qr_size', $vatSetting->qr_size) === 'Small' ? 'selected' : '' }}>Small (100px)</option>
                    <option value="Medium" {{ old('qr_size', $vatSetting->qr_size) === 'Medium' ? 'selected' : '' }}>Medium (140px)</option>
                    <option value="Large" {{ old('qr_size', $vatSetting->qr_size) === 'Large' ? 'selected' : '' }}>Large (180px)</option>
                </select>
            </div>
            <div class="col-md-4">
                <label class="form-label small fw-semibold">Invoice Language</label>
                <select name="invoice_language" class="form-select form-select-sm" required>
                    <option value="Bilingual" {{ old('invoice_language', $vatSetting->invoice_language) === 'Bilingual' ? 'selected' : '' }}>Bilingual (English + Arabic)</option>
                    <option value="Arabic" {{ old('invoice_language', $vatSetting->invoice_language) === 'Arabic' ? 'selected' : '' }}>Arabic Only</option>
                    <option value="English" {{ old('invoice_language', $vatSetting->invoice_language) === 'English' ? 'selected' : '' }}>English Only</option>
                </select>
            </div>
            <div class="col-md-4">
                <label class="form-label small fw-semibold">Price Pricing Mode</label>
                <select name="price_mode" class="form-select form-select-sm" required>
                    <option value="Exclusive VAT" {{ old('price_mode', $vatSetting->price_mode) === 'Exclusive VAT' ? 'selected' : '' }}>Exclusive VAT (Price + VAT)</option>
                    <option value="Inclusive VAT" {{ old('price_mode', $vatSetting->price_mode) === 'Inclusive VAT' ? 'selected' : '' }}>Inclusive VAT (Price includes 15% VAT)</option>
                </select>
            </div>
            <div class="col-md-4">
                <label class="form-label small fw-semibold">Default Invoice Type</label>
                <select name="default_invoice_type" class="form-select form-select-sm" required>
                    <option value="Tax Invoice" {{ old('default_invoice_type', $vatSetting->default_invoice_type) === 'Tax Invoice' ? 'selected' : '' }}>Tax Invoice (B2B Standard)</option>
                    <option value="Simplified Tax Invoice" {{ old('default_invoice_type', $vatSetting->default_invoice_type) === 'Simplified Tax Invoice' ? 'selected' : '' }}>Simplified Tax Invoice (B2C Cashier)</option>
                </select>
            </div>
        </div>

        <div class="row g-3 mb-4">
            <div class="col-md-4">
                <div class="form-check border rounded p-2 bg-light">
                    <input type="checkbox" name="invoice_qr_enabled" value="1" class="form-check-input" id="qrEnable" {{ old('invoice_qr_enabled', $vatSetting->invoice_qr_enabled) ? 'checked' : '' }}>
                    <label class="form-check-label small fw-semibold" for="qrEnable">
                        Enable ZATCA QR Code Output
                    </label>
                </div>
            </div>
            <div class="col-md-4">
                <div class="form-check border rounded p-2 bg-light">
                    <input type="checkbox" name="simplified_qr_mandatory" value="1" class="form-check-input" id="simpMandatory" {{ old('simplified_qr_mandatory', $vatSetting->simplified_qr_mandatory) ? 'checked' : '' }}>
                    <label class="form-check-label small fw-semibold" for="simpMandatory">
                        Simplified Tax Invoice QR Mandatory
                    </label>
                </div>
            </div>
            <div class="col-md-4">
                <div class="form-check border rounded p-2 bg-light">
                    <input type="checkbox" name="tax_invoice_qr_enabled" value="1" class="form-check-input" id="taxQrEnable" {{ old('tax_invoice_qr_enabled', $vatSetting->tax_invoice_qr_enabled) ? 'checked' : '' }}>
                    <label class="form-check-label small fw-semibold" for="taxQrEnable">
                        Standard Tax Invoice QR Enabled
                    </label>
                </div>
            </div>
        </div>

        <div class="d-flex justify-content-end gap-2">
            <button type="submit" class="btn btn-sm btn-primary"><i class="bi bi-save me-1"></i> Update ZATCA Settings</button>
        </div>
    </form>
</div>
@endsection
