@extends('layouts.app')

@section('title')
  Dashboard
@endsection

@section('admin-content')
    <script src="https://cdn.jsdelivr.net/npm/autonumeric@4.6.0/dist/autoNumeric.min.js"></script>
    <section class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1>Edit Expense Up Country</h1>
                </div>
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                        <li class="breadcrumb-item"><a href="{{ route('dashboard.index') }}">Dashboard</a></li>
                        </li>
                    </ol>
                </div>
            </div>
        </div>
    </section>
    <style>
        #loading-spinner-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent black background */
            z-index: 9999; /* High z-index to cover everything */
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .spinner-wrapper {
            text-align: center;
            color: white;
        }
    </style>
    <section class="content">
        <div class="container-fluid">
            <div class="card card-primary card-outline">
                <div class="card-body">
					<form id="expense-form" method="POST" action="{{ route('forms.up-country.update', $form->id) }}" enctype="multipart/form-data">
                        @csrf
                        @method('PUT')
                        @include('backend.layouts.partials.messages')
                        <div class="row">
                            <div class="col-lg-6">
                                <div class="mb-3">
                                    <label class="form-label">Pilih Rayon <span class="font-italic font-weight-normal">(required)</span></label>
                                    <select class="form-control form-control-md" name="rayon_id" required>
                                        <option value="">Pilih Rayon</option>
                                        @foreach ($rayons as $rayon)
                                            <option value="{{ $rayon->id }}" {{ $form->rayon_id == $rayon->id ? 'selected' : '' }}>{{ $rayon->name }}</option>
                                        @endforeach
                                    </select>
                                </div>
                                <div class="mb-3">
                                    <label class="form-label">Tanggal <span class="font-italic font-weight-normal">(required)</span></label>
                                    <input type="date" class="form-control" name="tanggal" required value="{{ $form->tanggal }}">
                                </div>
                                <div class="mb-3">
                                    <label class="form-label">Tujuan <span class="font-italic font-weight-normal">(required)</span></label>
                                    <input type="text" class="form-control" name="tujuan" required value="{{ $form->tujuan }}">
                                </div>
                                <div class="mb-3">
                                    <label class="form-label">Jarak (km) <span class="font-italic font-weight-normal">(required)</span></label>
                                    <input type="number" class="form-control" name="jarak" required value="{{ $form->jarak }}">
                                </div>
                                <div class="mb-3">
                                    <label class="form-label">Allowance <span class="font-italic font-weight-normal">(optional)</span></label>
                                    <input type="string" class="form-control" name="allowance" id="allowance" value="{{ $form->allowance }}">
                                </div>
                                <div class="mb-3">
                                    <label class="form-label">Bukti Allowance <span class="font-italic font-weight-normal">(optional)</span></label>
                                    <input type="file" class="form-control" name="bukti_allowance" value="{{ old('bukti_allowance') }}">
                                </div>
                            </div>

                            <div class="col-lg-6">
                                <div class="mb-3">
                                    <label class="form-label">Transport Dalam Kota <span class="font-italic font-weight-normal">(optional)</span></label>
                                    <input type="string" class="form-control" name="transport_dalkot" id="transport_dalkot" value="{{  $form->transport_dalkot }}">
                                </div>
                                <div class="mb-3">
                                    <label class="form-label">Bukti Transport Dalam Kota <span class="font-italic font-weight-normal">(optional)</span></label>
                                    <input type="file" class="form-control" name="bukti_transport_dalkot" value="{{ old('bukti_transport_dalkot') }}">
                                </div>
                                <div class="mb-3">
                                    <label class="form-label">Transport Antar Kota <span class="font-italic font-weight-normal">(optional)</span></label>
                                    <input type="string" class="form-control" name="transport_ankot" id="transport_ankot" value="{{ $form->transport_ankot }}">
                                </div>
                                <div class="mb-3">
                                    <label class="form-label">Bukti Transport Antar Kota <span class="font-italic font-weight-normal">(optional)</span></label>
                                    <input type="file" class="form-control" name="bukti_transport_ankot" value="{{ old('bukti_transport_ankot') }}">
                                </div>
                                <div class="mb-3">
                                    <label class="form-label">Hotel <span class="font-italic font-weight-normal">(optional)</span></label>
                                    <input type="string" class="form-control" name="hotel" id="hotel" value="{{ $form->hotel }}">
                                </div>
                                <div class="mb-3">
                                    <label class="form-label">Bukti Hotel <span class="font-italic font-weight-normal">(optional)</span></label>
                                    <input type="file" class="form-control" name="bukti_hotel" value="{{ old('bukti_hotel') }}">
                                </div>
                            </div>

                            <button type="submit" class="btn btn-primary ml-2">Save</button>
                        </div>
					</form>

                    <div id="loading-spinner-overlay" class="d-none">
                        <div class="spinner-wrapper">
                            <div class="spinner-border text-primary" role="status">
                            </div>
                            <p>Submitting, please wait...</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <script>
        new AutoNumeric('#allowance', {
            digitGroupSeparator: '.', // Pemisah ribuan
            decimalCharacter: ',',    // Karakter desimal (tidak digunakan karena tanpa desimal)
            currencySymbol: 'Rp.',    // Simbol mata uang
            decimalPlaces: 0,         // Tidak ada angka desimal
            unformatOnSubmit: true    // Nilai asli tanpa format saat dikirimkan
        });

        new AutoNumeric('#transport_dalkot', {
            digitGroupSeparator: '.', // Pemisah ribuan
            decimalCharacter: ',',    // Karakter desimal (tidak digunakan karena tanpa desimal)
            currencySymbol: 'Rp.',    // Simbol mata uang
            decimalPlaces: 0,         // Tidak ada angka desimal
            unformatOnSubmit: true    // Nilai asli tanpa format saat dikirimkan
        });

        new AutoNumeric('#transport_ankot', {
            digitGroupSeparator: '.', // Pemisah ribuan
            decimalCharacter: ',',    // Karakter desimal (tidak digunakan karena tanpa desimal)
            currencySymbol: 'Rp.',    // Simbol mata uang
            decimalPlaces: 0,         // Tidak ada angka desimal
            unformatOnSubmit: true    // Nilai asli tanpa format saat dikirimkan
        });

        new AutoNumeric('#hotel', {
            digitGroupSeparator: '.', // Pemisah ribuan
            decimalCharacter: ',',    // Karakter desimal (tidak digunakan karena tanpa desimal)
            currencySymbol: 'Rp.',    // Simbol mata uang
            decimalPlaces: 0,         // Tidak ada angka desimal
            unformatOnSubmit: true    // Nilai asli tanpa format saat dikirimkan
        });

        document.getElementById('expense-form').addEventListener('submit', function (e) {
            const spinnerOverlay = document.getElementById('loading-spinner-overlay');
            spinnerOverlay.classList.remove('d-none'); // Show overlay
            spinnerOverlay.classList.add('d-flex'); // Use flexbox for centering
        });
    </script>
@endsection
