<x-admin.layout>
    <x-slot name="title">No Dues Certificate (Property) / थकबाकी नसल्याचा दाखला(मालमत्ता)</x-slot>
    <x-slot name="heading">No Dues Certificate (Property) / थकबाकी नसल्याचा दाखला(मालमत्ता)</x-slot>

    <!-- Add Form -->
    <div class="row" id="addContainer">
        <div class="col-sm-12">
            <div class="card">
                <form class="theme-form" name="addForm" id="addForm" enctype="multipart/form-data">
                    @csrf

                    <div class="card-header">
                        <h4 class="card-title">Add Details</h4>
                    </div>
                    <div class="card-body">
                        <div class="mb-3 row">
                            <input type="hidden" model-id="id" value="{{ $status->id }}">
                            {{-- <div class="col-md-4">
                                <label class="col-form-label" for="upic_id">UPIC No<span
                                        class="text-danger">*</span></label>
                                <input class="form-control" id="upic_id" name="upic_id" type="text"
                                    placeholder="PNVL000045" value="{{ $noDue->upic_id }}" required>
                                <span class="text-danger is-invalid upic_id_err"></span>
                            </div> --}}
                            <div class="col-md-4">
                                <label class="col-form-label" for="applicant_name_eng">Applicant Full Name / अर्जदाराचे
                                    पूर्ण नाव<span class="text-danger">*</span></label>
                                <input class="form-control" id="applicant_name_eng" name="applicant_name_eng"
                                    type="text" value="{{ $noDue->applicant_name_eng }}"
                                    placeholder="Enter Applicant Name" required>
                                <span class="text-danger is-invalid applicant_name_eng_err"></span>
                            </div>
                            <div class="col-md-4">
                                <label class="col-form-label" for="applicant_name_mar">Applicant Full Address /
                                    अर्जदाराचा पूर्ण पत्ता<span class="text-danger">*</span></label>
                                <input class="form-control" id="applicant_name_mar" name="applicant_name_mar"
                                    type="text" value="{{ $noDue->applicant_name_mar }}"
                                    placeholder="Enter Applicant Name" required>
                                <span class="text-danger is-invalid applicant_name_mar_err"></span>
                            </div>
                            {{-- <div class="col-md-4">
                                <label class="col-form-label" for="applicant_full_address_eng">Permanent Address (
                                    English ) / कायमचा पत्ता ( इंग्रजी )<span class="text-danger">*</span></label>
                                <textarea class="form-control" name="applicant_full_address_eng"
                                    id="applicant_full_address_eng" cols="30" rows="2"
                                    placeholder="Enter Applicant Address"
                                    required>{{ $noDue->applicant_full_address_eng }}</textarea>
                                <span class="text-danger is-invalid applicant_full_address_eng_err"></span>
                            </div>
                            <div class="col-md-4">
                                <label class="col-form-label" for="applicant_full_address_mar">Permanent Address (
                                    Marathi ) / कायमचा पत्ता ( मराठी )<span class="text-danger">*</span></label>
                                <textarea class="form-control" name="applicant_full_address_mar"
                                    id="applicant_full_address_mar" cols="30" rows="2"
                                    placeholder="Enter Applicant Address"
                                    required>{{ $noDue->applicant_full_address_mar }}</textarea>
                                <span class="text-danger is-invalid applicant_full_address_mar_err"></span>
                            </div> --}}
                            <div class="col-md-4">
                                <label class="col-form-label" for="applicant_mobile_no">Mobile Number / मोबाईल नंबर<span
                                        class="text-danger">*</span></label>
                                <input class="form-control" id="applicant_mobile_no" name="applicant_mobile_no"
                                    oninput="this.value = this.value.replace(/\D/g, '')" maxlength="10" minlength="10"
                                    type="text" value="{{ $noDue->applicant_mobile_no }}"
                                    placeholder="Enter Mobile Number" required>
                                <span class="text-danger is-invalid applicant_mobile_no_err"></span>
                            </div>
                            <div class="col-md-4">
                                <label class="col-form-label" for="email_id">Email ID / ई-मेल आयडी<span
                                        class="text-danger">*</span></label>
                                <input class="form-control" id="email_id" name="email_id" type="email"
                                    placeholder="Enter Email" value="{{ $noDue->email_id }}" required>
                                <span class="text-danger is-invalid email_id_err"></span>
                            </div>
                            <div class="col-md-4">
                                <label class="col-form-label" for="aadhar_no">Aadhar Number / आधार क्रमांक <span
                                        class="text-danger">*</span></label>
                                <input class="form-control" id="aadhar_no"
                                    oninput="this.value = this.value.replace(/\D/g, '')" maxlength="12" minlength="12"
                                    type="text" name="aadhar_no" value="{{ $noDue->aadhar_no }}"
                                    placeholder="Enter Aadhar Card No" required>
                                <span class="text-danger is-invalid aadhar_no_err"></span>
                            </div>
                            {{-- <div class="col-md-4">
                                <label class="col-form-label" for="zone">Zone / झोन<span
                                        class="text-danger">*</span></label>
                                <select class="form-select" name="zone" id="zone" required>
                                    <option value="">Select Zone</option>

                                    @foreach($zones as $zone)
                                    <option {{ ($noDue->zone == $zone->id) ? 'selected' : '' }} value="{{ $zone->name
                                        }}">{{ $zone->name }}</option>
                                    @endforeach
                                </select>
                                <span class="text-danger is-invalid zone_err"></span>
                            </div> --}}
                            <div class="card-header">
                                <h4 class="card-title">Connection Details</h4>
                            </div>
                            <div class="col-md-4">
                                <label class="col-form-label" for="index_number">Total Connections / एकूण
                                    कनेक्शन</label>
                                <input class="form-control" id="index_number" name="index_number" type="text"
                                    placeholder="Enter Total Connections" value="{{ $noDue->index_number }}">
                                <span class="text-danger is-invalid index_number_err"></span>
                            </div>
                            <div class="col-md-4">
                                <label class="col-form-label" for="connection_no">Connection Number/कनेक्शन नाही<span
                                        class="text-danger">*</span></label>
                                <input class="form-control" id="connection_no" name="connection_no" type="text"
                                    placeholder="Enter House Number"
                                    value="{{ old('connection_no', $noDue->connection_no ?? '') }}" required>
                                <span class="text-danger is-invalid connection_no_err"></span>
                            </div>

                            <div class="col-md-4">
                                <label class="col-form-label" for="owner_name">Owner Name / मालकाचे नाव<span
                                        class="text-danger">*</span></label>
                                <input class="form-control" id="owner_name" name="owner_name" type="text"
                                    placeholder="Enter Owner Name"
                                    value="{{ old('owner_name', $noDue->owner_name ?? '') }}" required>
                                <span class="text-danger is-invalid owner_name_err"></span>
                            </div>

                            <div class="col-md-4">
                                <label class="col-form-label" for="owner_full_add">Owner Full Address / मालकाचा पूर्ण
                                    पत्ता<span class="text-danger">*</span></label>
                                <input class="form-control" id="owner_full_add" name="owner_full_add" type="text"
                                    placeholder="Enter Full Address"
                                    value="{{ old('owner_full_add', $noDue->owner_full_add ?? '') }}" required>
                                <span class="text-danger is-invalid owner_full_add_err"></span>
                            </div>
                            <div class="col-md-4">
                                <label class="col-form-label" for="land_mark">Land Mark / लँडमार्क<span
                                        class="text-danger">*</span></label>
                                <input class="form-control" id="land_mark" name="land_mark" type="text"
                                    placeholder="Enter Landmark" value="{{ old('land_mark', $noDue->land_mark ?? '') }}"
                                    required>
                                <span class="text-danger is-invalid land_mark_err"></span>
                            </div>
                            <div class="col-md-4">
                                <label class="col-form-label" for="ward_area">Ward / प्रभाग<span
                                        class="text-danger">*</span></label>
                                <select class="form-select" name="ward_area" id="ward_area" required>
                                    <option value="">Select Ward Area</option>
                                    @foreach($wards as $ward)
                                    <option {{ ($noDue->ward_area == $ward->id) ? 'selected' : '' }} value="{{
                                        $ward->name }}">{{ $ward->name }}</option>
                                    @endforeach
                                </select>
                                <span class="text-danger is-invalid ward_area_err"></span>
                            </div>
                            <div class="col-md-4">
                                <label class="col-form-label" for="zone">Zone / झोन<span
                                        class="text-danger">*</span></label>
                                <select class="form-select" name="zone" id="zone" required>
                                    <option value="">Select Zone</option>
                                    @foreach($zones as $zone)
                                    <option {{ ($noDue->zone == $zone->id) ? 'selected' : '' }} value="{{ $zone->name
                                        }}">{{ $zone->name }}</option>
                                    @endforeach
                                </select>
                                <span class="text-danger is-invalid zone_err"></span>
                            </div>
                            <div class="col-md-4">
                                <label class="col-form-label" for="property_address">Property Number/मालमत्ता
                                    क्रमांक<span class="text-danger">*</span></label>
                                <textarea class="form-control" name="property_address" id="property_address" cols="30"
                                    rows="2" placeholder="Enter Property Address"
                                    required>{{ $noDue->property_address }}</textarea>
                                <span class="text-danger is-invalid property_address_err"></span>
                            </div>
                            {{-- <div class="col-md-4">
                                <label class="col-form-label" for="house_no">Usage of Water Connection / पाणी जोडणीचा
                                    वापर<span class="text-danger">*</span></label>
                                <input class="form-control" id="house_no" name="house_no" type="text"
                                    placeholder="Enter House Number" value="{{ $noDue->house_no }}" required>
                                <span class="text-danger is-invalid house_no_err"></span>
                            </div> --}}
                            <div class="col-md-4">
                                <label class="col-form-label" for="index_number">Water Sub Usage / पाणी उपवापर</label>
                                <input class="form-control" id="index_number" name="index_number" type="text"
                                    placeholder="Enter Index Number" value="{{ $noDue->index_number }}">
                                <span class="text-danger is-invalid index_number_err"></span>
                            </div>
                            <div class="col-md-4">
                                <label class="col-form-label" for="property_no">Connection Size / कनेक्शन आकार <span
                                        class="text-danger">*</span></label>
                                <input class="form-control" id="property_no" name="property_no" type="text"
                                    placeholder="Enter Property Number" value="{{ $noDue->property_no }}" required>
                                <span class="text-danger is-invalid property_no_err"></span>
                            </div>
                            <div class="col-md-4">
                                <label class="col-form-label" for="annual_period">वार्षिक कालावधी <span
                                        class="text-danger">*</span></label>
                                <select class="form-control" id="annual_period" name="annual_period" required>
                                    <option value="">Enter Annual Period</option>
                                    <option value="2023-2024" {{ isset($noDue) && $noDue->annual_period == '2023-2024' ?
                                        'selected' : '' }}>2023-2024</option>
                                    <option value="2025-2026" {{ isset($noDue) && $noDue->annual_period == '2025-2026' ?
                                        'selected' : '' }}>2025-2026</option>
                                </select>
                                <span class="text-danger is-invalid annual_period_err"></span>
                            </div>
                            <div class="col-md-4">
                                <label class="col-form-label" for="uploaded_applications">
                                    Total Outstanding Bill Payment Done? / एकूण थकबाकी बिल भरले? <span
                                        class="text-danger">*</span>
                                </label>
                                <select class="form-control" id="uploaded_applications" name="uploaded_applications"
                                    required>
                                    <option value="" disabled>-- Select --</option>
                                    <option value="yes" {{ isset($noDue) && $noDue->uploaded_applications == 'yes' ?
                                        'selected' : '' }}>Yes / होय</option>
                                    <option value="no" {{ isset($noDue) && $noDue->uploaded_applications == 'no' ?
                                        'selected' : '' }}>No / नाही</option>
                                </select>
                                <span class="text-danger is-invalid uploaded_applications_err"></span>
                            </div>
                        </div>
                        {{-- <div class="col-md-4">
                            <label class="col-form-label" for="receipt_doc">Upload Document Receipt / दस्तऐवजाची पावती
                                अपलोड करा<span class="text-danger">*</span></label>
                            <input type="file" class="form-control" name="receipt_doc" id="receipt_doc"
                                accept="image/*,.pdf">
                            @if($noDue->receipt_doc)
                            <a href="{{ asset('storage/' . $noDue->receipt_doc) }}" target="_blank">View Doc</a>
                            @endif
                            <span class="text-danger is-invalid receipt_doc_err"></span>
                        </div> --}}
                        {{-- <label for="work_completition_certificate">Work Completion Certificate (Last 3 years) /
                            साइट भेट फोटो<span class="text-danger">*</span></label>
                        <input type="file" name="work_completition_certificate" id="work_completition_certificate"
                            class="form-control" accept="image/*">
                        @if($completitioncertificate->work_completition_certificate)
                        <a href="{{ asset('storage/' . $completitioncertificate->work_completition_certificate) }}"
                            target="_blank">View Doc</a>
                        @endif
                        <span class="text-danger is-invalid work_completition_certificate_err"></span> --}}
                        {{-- <div class="col-md-3">
                            <label for="work_completition_certificate">Work Completion Certificate (Last 3 years) / साइट
                                भेट फोटो<span class="text-danger">*</span></label>
                            <input type="file" name="work_completition_certificate" id="work_completition_certificate"
                                class="form-control" accept="image/*">
                            @if($completitioncertificate->work_completition_certificate)
                            <a href="{{ asset('storage/' . $completitioncertificate->work_completition_certificate) }}"
                                target="_blank">View Doc</a>
                            @endif
                            <span class="text-danger is-invalid work_completition_certificate_err"></span>
                        </div> --}}
                        {{-- <div class="col-md-3">
                            <label for="property_doc">Property Document / मालमत्तेचे दस्तऐवज<span
                                    class="text-danger">*</span></label>
                            <input type="file" name="property_doc" id="property_doc" class="form-control"
                                accept="image/*,.pdf">
                            @if($stromwaterdrains->property_doc)
                            <a href="{{ asset('storage/' . $stromwaterdrains->property_doc) }}" target="_blank"
                                title="property_doc">View Doc</a>
                            @endif
                            <span class="text-danger is-invalid property_doc_err"></span>
                        </div> --}}

                        <div class="col-md-3">
                            <label for="remark">Remark<span class="text-danger">*</span></label>
                            <textarea id="Remark" name="remark" class="form-control" rows="4" required></textarea>
                        </div>

                        {{-- <label class="col-form-label" for="is_correct_info">Declaration / घोषणापत्र:</label>
                        <div class="col-md-12">
                            <div class="form-check d-flex align-items-start">
                                <input type="checkbox" class="form-check-input mt-1" id="is_correct_info"
                                    name="is_correct_info" checked value="yes" required>
                                <label class="form-check-label ms-2" for="is_correct_info">
                                    "All information provided above is correct and I shall be fully responsible for any
                                    discrepancy. <br> वरील पुरविलेली सर्व माहिती ही अचूक असून, त्यात कुठल्याही प्रकारची
                                    तफावत आढळल्यास त्यास मी पूर्णतः जबाबदार असेन."
                                </label>
                            </div>
                            <span class="text-danger is-invalid is_correct_info_err"></span>
                        </div> --}}

                    </div>
            </div>
            <div class="card-footer">
                <button type="button" class="btn btn-primary approveBtn" data-id="{{ $status->id }}">Approve</button>
                <button type="button" class="btn btn-danger rejectBtn" data-id="{{ $status->id }}">Reject</button>
                <button id="btnCancel" class="btn btn-warning">Cancel</button>
            </div>
            </form>
        </div>
    </div>
    </div>

</x-admin.layout>



<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

<script>
    document.getElementById('btnCancel').addEventListener('click', function() {
        window.location.href = "{{ route('pendinglist') }}";
    });
</script>
<script>
    $(document).ready(function() {
        $('.approveBtn').on('click', function() {
            let statusId = $(this).data('id');
            let remark = $('#Remark').val();

            if (remark.trim() !== '') {
                $.ajax({
                    url: '/approve-item/' + statusId,
                    type: 'POST',
                    data: {
                        _token: '{{ csrf_token() }}',
                        remark: remark
                    },
                    success: function(response) {
                        Swal.fire({
                            icon: 'success',
                            title: 'Success!',
                            text: response.message,
                            confirmButtonText: 'OK'
                        }).then(() => {
                            window.location.href = response.redirect_url;
                        });
                    },
                    error: function(xhr) {
                        Swal.fire({
                            icon: 'error',
                            title: 'Error!',
                            text: 'Error: ' + xhr.responseText,
                            confirmButtonText: 'OK'
                        });
                    }
                });
            } else {
                Swal.fire({
                    icon: 'warning',
                    title: 'Warning!',
                    text: 'Please Add Remark',
                    confirmButtonText: 'OK'
                });
            }
        });
    });


    $(document).ready(function() {
        $('.rejectBtn').on('click', function() {
            var statusId = $(this).data('id');
            let remark = $('#Remark').val();

            if (remark !== null && remark.trim() !== '') {
                $.ajax({
                    url: '/reject-item/' + statusId,
                    type: 'POST',
                    data: {
                        _token: '{{ csrf_token() }}',
                        remark: remark
                    },
                    success: function(response) {
                        Swal.fire({
                            icon: 'success',
                            title: 'Success!',
                            text: response.message,
                            confirmButtonText: 'OK'
                        }).then(() => {
                            window.location.href = response.redirect_url;
                        });
                    },
                    error: function(xhr) {
                        Swal.fire({
                            icon: 'error',
                            title: 'Error!',
                            text: 'Error: ' + xhr.responseText,
                            confirmButtonText: 'OK'
                        });
                    }
                });
            } else {
                Swal.fire({
                    icon: 'warning',
                    title: 'Warning!',
                    text: 'Please Add Remark',
                    confirmButtonText: 'OK'
                });
            }
        });
    });
</script>