@extends('layouts.app')

@section('content')
<div class="mx-auto max-w-4xl space-y-6">
    <div class="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
        <div>
            <h1 class="text-2xl font-bold text-gray-900 dark:text-white">
                Pengaturan PPN
            </h1>
            <p class="text-sm text-gray-500 dark:text-gray-400">
                Atur status dan persentase PPN untuk kebutuhan invoice.
            </p>
        </div>

        <a href="{{ url()->previous() }}"
           style="display:inline-flex !important;align-items:center !important;justify-content:center !important;background:#ffffff !important;color:#374151 !important;border:1px solid #d1d5db !important;border-radius:10px !important;padding:10px 16px !important;font-size:14px !important;font-weight:700 !important;text-decoration:none !important;">
            Kembali
        </a>
    </div>

    @if(session('success'))
        <div class="rounded-lg bg-green-50 p-4 text-sm text-green-700 dark:bg-green-500/10 dark:text-green-300">
            {{ session('success') }}
        </div>
    @endif

    @if($errors->any())
        <div class="rounded-lg bg-red-50 p-4 text-sm text-red-700 dark:bg-red-500/10 dark:text-red-300">
            <div class="font-semibold">Data belum valid:</div>
            <ul class="mt-2 list-disc space-y-1 pl-5">
                @foreach($errors->all() as $error)
                    <li>{{ $error }}</li>
                @endforeach
            </ul>
        </div>
    @endif

    <form method="POST" action="{{ route('tax-settings.update') }}"
          class="rounded-xl border border-gray-200 bg-white p-6 shadow-sm dark:border-gray-800 dark:bg-gray-900">
        @csrf
        @method('PUT')

        <div class="grid grid-cols-1 gap-5 md:grid-cols-2">
            <div class="md:col-span-2">
                <label class="inline-flex items-center gap-3 rounded-lg border border-gray-200 bg-gray-50 px-4 py-3 dark:border-gray-700 dark:bg-gray-800">
                    <input type="checkbox"
                           name="is_active"
                           value="1"
                           @checked(old('is_active', $taxSetting->is_active))
                           class="rounded border-gray-300 text-indigo-600 focus:ring-indigo-500">
                    <span class="text-sm font-semibold text-gray-800 dark:text-gray-200">
                        Aktifkan PPN sebagai default invoice
                    </span>
                </label>
            </div>

            <div>
                <label for="rate" class="mb-1 block text-sm font-medium text-gray-700 dark:text-gray-300">
                    Persentase PPN <span class="text-red-500">*</span>
                </label>
                <div class="flex">
                    <input id="rate"
                           type="number"
                           step="0.01"
                           min="0"
                           max="100"
                           name="rate"
                           value="{{ old('rate', $taxSetting->rate) }}"
                           required
                           class="w-full rounded-l-lg border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900 dark:border-gray-700 dark:bg-gray-800 dark:text-white">
                    <span class="inline-flex items-center rounded-r-lg border border-l-0 border-gray-300 bg-gray-50 px-3 text-sm font-semibold text-gray-600 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-300">
                        %
                    </span>
                </div>
            </div>

            <div>
                <label for="npwp" class="mb-1 block text-sm font-medium text-gray-700 dark:text-gray-300">
                    NPWP
                </label>
                <input id="npwp"
                       type="text"
                       name="npwp"
                       value="{{ old('npwp', $taxSetting->npwp) }}"
                       placeholder="Opsional"
                       class="w-full rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900 dark:border-gray-700 dark:bg-gray-800 dark:text-white">
            </div>

            <div>
                <label for="pkp_name" class="mb-1 block text-sm font-medium text-gray-700 dark:text-gray-300">
                    Nama PKP
                </label>
                <input id="pkp_name"
                       type="text"
                       name="pkp_name"
                       value="{{ old('pkp_name', $taxSetting->pkp_name) }}"
                       placeholder="Opsional"
                       class="w-full rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900 dark:border-gray-700 dark:bg-gray-800 dark:text-white">
            </div>

            <div>
                <label for="pkp_address" class="mb-1 block text-sm font-medium text-gray-700 dark:text-gray-300">
                    Alamat PKP
                </label>
                <textarea id="pkp_address"
                          name="pkp_address"
                          rows="3"
                          class="w-full rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900 dark:border-gray-700 dark:bg-gray-800 dark:text-white">{{ old('pkp_address', $taxSetting->pkp_address) }}</textarea>
            </div>

            <div class="md:col-span-2">
                <label for="notes" class="mb-1 block text-sm font-medium text-gray-700 dark:text-gray-300">
                    Catatan Pajak
                </label>
                <textarea id="notes"
                          name="notes"
                          rows="3"
                          class="w-full rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900 dark:border-gray-700 dark:bg-gray-800 dark:text-white">{{ old('notes', $taxSetting->notes) }}</textarea>
            </div>
        </div>

        <div class="mt-6 flex justify-end gap-3">
            <button type="submit"
                    style="display:inline-flex !important;align-items:center !important;justify-content:center !important;background:#2563eb !important;color:#ffffff !important;border:1px solid #1d4ed8 !important;border-radius:10px !important;padding:10px 18px !important;font-size:14px !important;font-weight:800 !important;box-shadow:0 4px 10px rgba(37,99,235,.25) !important;cursor:pointer !important;">
                Simpan Pengaturan PPN
            </button>
        </div>
    </form>

    <div class="rounded-xl border border-blue-200 bg-blue-50 p-5 text-sm text-blue-800 dark:border-blue-500/30 dark:bg-blue-500/10 dark:text-blue-200">
        <strong>Catatan:</strong> status PPN di sini menjadi default invoice. Saat cetak invoice, PPN tetap bisa dipaksa lewat URL/tombol dengan parameter <code>ppn=1</code> atau <code>ppn=0</code>.
    </div>
</div>
@endsection
