<x-admin.layout>
    <x-slot name="title">Tax Assessment On Demolishing And Reconstruction Of The property/मालमत्ता पाडणे व पुनः बांधणी
        कर आकारणी</x-slot>
    <x-slot name="heading">Tax Assessment On Demolishing And Reconstruction Of The 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">Edit Details</h4>
                    </div>
                    <div class="card-body">


                        {{-- <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 @if ($demolishingprop->zone == $zone->name) selected @endif value="{{ $zone->name }}">{{ $zone->name }}</option>
                                @endforeach
                            </select>
                            <span class="text-danger is-invalid zone_err"></span>
                        </div> --}}

                        {{-- {{ dd($demolishingprop) }} --}}

                        <div class="mb-3 row">
                            <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="f_name">First Name <span
                                        class="text-danger">*</span></label>
                                <input class="form-control" id="f_name" name="f_name" type="text"
                                    placeholder="Enter First Name" value="{{ $demolishingprop->f_name }}" readonly>
                                <span class="text-danger is-invalid applicant_name_err"></span>
                            </div>

                            {{-- <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="m_name">Middle Name <span class="text-danger">*</span></label>
                                <input class="form-control" id="m_name" name="m_name" type="text" placeholder="Enter Middle Name" value="{{ $demolishingprop->m_name }}" readonly>
                                <span class="text-danger is-invalid applicant_name_err"></span>
                            </div>

                            <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="l_name">Last Name <span class="text-danger">*</span></label>
                                <input class="form-control" id="l_name" name="l_name" type="text" placeholder="Enter Last Name" value="{{ $demolishingprop->l_name }}" readonly>
                                <span class="text-danger is-invalid applicant_name_err"></span>
                            </div> --}}

                            {{-- <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="marathi_f_name">प्रथम नाव (मराठी) <span class="text-danger">*</span></label>
                                <input class="form-control" id="marathi_f_name" name="marathi_f_name" type="text" placeholder="नाव प्रविष्ट करा प्रथम" value="{{ $demolishingprop->marathi_f_name }}" readonly>
                                <span class="text-danger is-invalid applicant_name_err"></span>
                            </div>

                            <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="marathi_m_name">मधले नाव (मराठी)<span class="text-danger">*</span></label>
                                <input class="form-control" id="marathi_m_name" name="marathi_m_name" type="text" placeholder="प्रविष्ट करा मधले नाव" value="{{ $demolishingprop->marathi_m_name }}" readonly>
                                <span class="text-danger is-invalid applicant_name_err"></span>
                            </div>

                            <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="marathi_l_name">आडनाव (मराठी) <span class="text-danger">*</span></label>
                                <input class="form-control" id="marathi_l_name" name="marathi_l_name" type="text" placeholder="आडनाव प्रविष्ट करा" value="{{ $demolishingprop->marathi_l_name }}" readonly>
                                <span class="text-danger is-invalid applicant_name_err"></span>
                            </div> --}}


                            <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="mobile_num">Mobile Number <span
                                        class="text-danger">*</span></label>
                                <input class="form-control" id="mobile_num" name="mobile_num" type="text"
                                    oninput="this.value = this.value.replace(/\D/g, '')" maxlength="10" minlength="10"
                                    placeholder="Enter Mobile Number" value="{{ $demolishingprop->mobile_num }}"
                                    readonly>
                                <span class="text-danger is-invalid applicant_mobile_no_err"></span>
                            </div>
                            <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="aadhar_num">Aadhar Card No</label>
                                <input class="form-control" id="aadhar_num" name="aadhar_num" type="text"
                                    oninput="this.value = this.value.replace(/\D/g, '')" maxlength="12" minlength="12"
                                    placeholder="Enter Aadhar  Card Number" value="{{ $demolishingprop->aadhar_num }}"
                                    readonly>
                                <span class="text-danger is-invalid applicant_mobile_no_err"></span>
                            </div>
                            <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="email">Email<span
                                        class="text-danger">*</span></label>
                                <input class="form-control" id="email" name="email" type="email"
                                    placeholder="Enter Email" value="{{ $demolishingprop->email }}" readonly>
                                <span class="text-danger is-invalid email_err"></span>
                            </div>
                            <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="address"> Address <span
                                        class="text-danger">*</span></label>
                                <textarea class="form-control" name="address" id="address" cols="30" rows="2" placeholder="Enter Address"
                                    readonly>{{ $demolishingprop->address }}</textarea>
                                <span class="text-danger is-invalid address_err"></span>
                            </div>

                            {{-- <div class="col-md-5">
                                <label class="col-form-label" for="marathi_address"> पत्ता (मराठी) <span class="text-danger">*</span></label>
                                <textarea class="form-control" name="marathi_address" id="marathi_address" cols="30" rows="2" placeholder="पत्ता" value="" readonly>{{ $demolishingprop->marathi_address }}</textarea>
                                <span class="text-danger is-invalid applicant_full_address_err"></span>
                            </div> --}}

                            <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="property_owner_name">Property Owner Name /
                                    मालमत्ता मालकाचे नाव <span class="text-danger">*</span></label>
                                <input class="form-control" id="property_owner_name" name="property_owner_name"
                                    type="text" placeholder="Enter Owner Name" readonly
                                    value="{{ $demolishingprop->property_owner_name ?? '' }}">
                                <span class="text-danger is-invalid property_owner_name_err"></span>
                            </div>

                            <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="property_address">Property Address / मालमत्ता
                                    पत्ता <span class="text-danger">*</span></label>
                                <textarea class="form-control" id="property_address" name="property_address" rows="2"
                                    placeholder="Enter Property Address" readonly> {{ $demolishingprop->property_address ?? '' }} </textarea>
                                <span class="text-danger is-invalid property_address_err"></span>
                            </div>

                            <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="ward">Ward No. / प्रभाग क्षेत्र <span
                                        class="text-danger">*</span></label>
                                <input class="form-control" name="ward" id="ward"
                                    placeholder="Enter Ward Area" readonly value="{{ $demolishingprop->ward ?? '' }}">
                                <span class="text-danger is-invalid ward_err"></span>
                            </div>

                            <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="zone">Zone / झोन<span
                                        class="text-danger">*</span></label>
                                <input class="form-control" name="zone" id="zone" placeholder="Enter Zone"
                                    value="{{ $demolishingprop->zone ?? '' }}" readonly>
                                <span class="text-danger is-invalid zone_err"></span>
                            </div>

                            <input type="hidden" id="warddata" name="ward_area"
                                value="{{ $demolishingprop->ward_area ?? '' }}">

                            <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="survey_number">Property Survey Number /
                                    मालमत्ता सर्व्हे नंबर</label>
                                <input class="form-control" id="survey_number" name="survey_number" type="text"
                                    placeholder="Enter Survey Number"
                                    value="{{ $demolishingprop->survey_number ?? '' }}" readonly>
                                <span class="text-danger is-invalid survey_number_err"></span>
                            </div>

                            <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="m_name">Flat Number <span
                                        class="text-danger">*</span></label>
                                <input class="form-control" id="m_name" name="m_name" type="text"
                                    placeholder="Enter Middle Name" value="{{ $demolishingprop->m_name }}" readonly>
                                <span class="text-danger is-invalid m_name_err"></span>
                            </div>

                            <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="property_area">Property Area (sq. mtr) /
                                    मालमत्ता क्षेत्रफळ (स्के. मी) <span class="text-danger">*</span></label>
                                <input class="form-control" id="property_area" name="property_area" type="number"
                                    step="0.01" placeholder="Enter Area in sq. mtr"
                                    value="{{ $demolishingprop->property_area ?? '' }}" readonly>
                                <span class="text-danger is-invalid property_area_err"></span>
                            </div>

                            <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="property_usage">Property Usage / मालमत्ता
                                    वापर <span class="text-danger">*</span></label>
                                <input class="form-control" id="property_usage" name="property_usage" type="text"
                                    placeholder="Enter Usage Type"
                                    value="{{ $demolishingprop->property_usage ?? '' }}" readonly>
                                <span class="text-danger is-invalid property_usage_err"></span>
                            </div>

                            <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="l_name">Total Outstanding Payable / एकूण देय
                                    थकबाकी?</label>
                                <input class="form-control" id="l_name" name="l_name" type="text"
                                    placeholder="Outstanding Amount" value="{{ $demolishingprop->l_name ?? '' }}"
                                    readonly>
                                <span class="text-danger is-invalid l_name_err"></span>
                            </div>



                            <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="purpose">Purpose <span
                                        class="text-danger">*</span></label>
                                <textarea class="form-control" name="purpose" id="purpose" cols="30" rows="2"
                                    placeholder="Enter purpose" value="" readonly>{{ $demolishingprop->marathi_purpose }}</textarea>
                                <span class="text-danger is-invalid applicant_full_address_err"></span>
                            </div>

                            <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="marathi_purpose">उद्देश (मराठी) <span
                                        class="text-danger">*</span></label>
                                <textarea class="form-control" name="marathi_purpose" id="marathi_purpose" cols="30" rows="2"
                                    placeholder="उद्देश" value="" readonly>{{ $demolishingprop->marathi_purpose }}</textarea>
                                <span class="text-danger is-invalid applicant_full_address_err"></span>
                            </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 class="col-md-4 mb-3">
                                <label class="col-form-label" for="property_owner_name">Property Owner Name / मालमत्ता मालकाचे नाव <span class="text-danger">*</span></label>
                                <input class="form-control" id="property_owner_name" name="property_owner_name" type="text" placeholder="Enter Owner Name" value="{{ $demolishingprop->property_owner_name }}" required>
                            </div>

                            <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="property_address">Property Address / मालमत्ता पत्ता <span class="text-danger">*</span></label>
                                <textarea class="form-control" id="property_address" name="property_address" rows="2" required>{{ $demolishingprop->property_address }}</textarea>
                            </div> --}}

                            {{-- <div class="col-md-4 mb-3">
                                <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 value="{{ $zone->id }}" @if ($demolishingprop->zone == $zone->id) selected @endif>{{ $zone->name }}</option>
                                    @endforeach
                                </select>
                            </div> --}}

                            {{-- <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="ward">Ward Area / प्रभाग क्षेत्र <span class="text-danger">*</span></label>
                                <select class="form-select" name="ward" id="ward" required>
                                    <option value="">Select Ward</option>
                                    @foreach ($wards as $ward)
                                        <option value="{{ $ward->id }}" @if ($demolishingprop->ward == $ward->id) selected @endif>{{ $ward->name }}</option>
                                    @endforeach
                                </select>
                            </div> --}}

                            {{-- <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="survey_number">Property Survey Number / मालमत्ता सर्व्हे नंबर</label>
                                <input class="form-control" id="survey_number" name="survey_number" type="text" placeholder="Enter Survey Number" value="{{ $demolishingprop->survey_number }}">
                            </div> --}}

                            {{-- <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="property_number">Property Number / मालमत्ता क्र</label>
                                <input class="form-control" id="property_number" name="property_number" type="text" placeholder="Enter Property Number" value="{{ $demolishingprop->property_number }}">
                            </div> --}}

                            {{-- <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="property_area">Property Area (sq. mtr) / मालमत्ता क्षेत्रफळ (स्के. मी)</label>
                                <input class="form-control" id="property_area" name="property_area" type="number" step="0.01" placeholder="Enter Area in sq. mtr" value="{{ $demolishingprop->property_area }}">
                            </div> --}}

                            {{-- <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="property_usage">Property Usage / मालमत्ता वापर</label>
                                <input class="form-control" id="property_usage" name="property_usage" type="text" placeholder="Enter Usage Type" value="{{ $demolishingprop->property_usage }}">
                            </div> --}}

                            {{-- <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="construction_type">Construction Type / बांधकाम प्रकार</label>
                                <input class="form-control" id="construction_type" name="construction_type" type="text" placeholder="Enter Construction Type" value="{{ $demolishingprop->construction_type }}">
                            </div> --}}

                            {{-- <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="is_authorized_construction">Is Construction Authorized? / बांधकाम अधिकृत आहे का?</label>
                                <select class="form-select" id="is_authorized_construction" name="is_authorized_construction">
                                    <option value="">Select</option>
                                    <option value="yes" @if ($demolishingprop->is_authorized_construction == 'yes') selected @endif>Yes / होय</option>
                                    <option value="no" @if ($demolishingprop->is_authorized_construction == 'no') selected @endif>No / नाही</option>
                                </select>
                            </div> --}}

                            {{-- <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="has_water_connection">Is there a Water (Tap) Connection? / पाणी (नळ) कनेक्शन आहे का?</label>
                                <select class="form-select" id="has_water_connection" name="has_water_connection">
                                    <option value="">Select</option>
                                    <option value="yes" @if ($demolishingprop->has_water_connection == 'yes') selected @endif>Yes / होय</option>
                                    <option value="no" @if ($demolishingprop->has_water_connection == 'no') selected @endif>No / नाही</option>
                                </select>
                            </div> --}}

                            <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="application_file">Upload Application In Prescribed
                                    Format / विहित नमुन्यातील अर्ज अपलोड करा</label>
                                {{-- <input type="file" class="form-control" name="application_file" id="application_file" accept=".pdf,.doc,.docx,.jpg,.png"> --}}
                                @if ($demolishingprop->application_file)
                                    <a class="btn btn-sm btn-outline-primary mb-2" target="__blank"
                                        href="{{ asset('storage/' . $demolishingprop->application_file) }}"
                                        target="_blank">View current file</a>
                                @endif
                            </div>

                            <div class="col-md-4 mb-3">
                                <label class="col-form-label" for="no_dues_certificate">Upload Certificate Of No Dues
                                    / थकबाकी नसल्याचा दाखला अपलोड करा</label>
                                {{-- <input type="file" class="form-control" name="no_dues_certificate" id="no_dues_certificate" accept=".pdf,.doc,.docx,.jpg,.png"> --}}
                                @if ($demolishingprop->no_dues_certificate)
                                    <a class="btn btn-sm btn-outline-primary mb-2" target="__blank"
                                        href="{{ asset('storage/' . $demolishingprop->no_dues_certificate) }}"
                                        target="_blank">View current file</a>
                                @endif
                            </div>

                            <div class="col-md-4 mb-3">
                                <label for="remark">Remark<span class="text-danger">*</span></label>
                                <textarea id="Remark" name="remark" class="form-control" rows="6" placeholder="Type your remark here..."></textarea>
                            </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 type="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>



{{-- Add --}}
{{-- <script>
    $("#addForm").submit(function(e) {
        e.preventDefault();
        $("#addSubmit").prop('disabled', true);


        var formdata = new FormData(this);
        var updateUrl = '{{ route('demolishingproperty.update', $demolishingprop->id) }}';
        formdata.append('_method', 'PUT');
        $.ajax({
            url: updateUrl,
            type: 'POST',
            data: formdata,
            contentType: false,
            processData: false,
            beforeSend: function() {
                $('#preloader').css('opacity', '0.5');
                $('#preloader').css('visibility', 'visible');
            },
            success: function(data) {
                $("#addSubmit").prop('disabled', false);
                if (!data.error)
                    swal("Successful!", data.success, "success")
                    .then((action) => {
                        window.location.href = '{{ route('my-application') }}';
                    });
                else
                    swal("Error!", data.error, "error");
            },
            statusCode: {
                422: function(responseObject, textStatus, jqXHR) {
                    $("#addSubmit").prop('disabled', false);
                    resetErrors();
                    printErrMsg(responseObject.responseJSON.errors);
                },
                500: function(responseObject, textStatus, errorThrown) {
                    $("#addSubmit").prop('disabled', false);
                    swal("Error occured!", "Something went wrong please try again", "error");
                }
            },
            complete: function() {
                $('#preloader').css('opacity', '0');
                $('#preloader').css('visibility', 'hidden');
            },
        });

    });
</script> --}}
