@extends('website.layouts.app')

@section('title')
    Kalkukasi kecamatan
@endsection

@section('content')
    <div class="row">
        <div class="col-12">
            <div class="page-title-box d-sm-flex align-items-center justify-content-between">
                <h4 class="mb-sm-0">Perhitungan TOPSIS</h4>

                <div class="page-title-right">
                    <ol class="breadcrumb m-0">
                        <li class="breadcrumb-item"><a href="javascript: void(0);">Perhitungan TOPSIS</a></li>
                        <li class="breadcrumb-item active">Alternatif (Kecamatan)</li>
                    </ol>
                </div>

            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-lg-12">
            {{-- <div class="card border card-border-warning">
                <div class="card-header">
                    <h6 class="card-title mb-0">Baca Terlebih Dahulu !!!</h6>
                </div>
                <div class="card-body">
                    <p class="card-text">
                        Berikut adalah pengambilan parameter pada setiap kecamatan di Kabupaten Bondowoso.
                        Parameter dibawah ini terdapat data ketinggian per kecamatan. Data ketinggian bersumber dari
                        publikasi <a href="https://bondowosokab.bps.go.id/id/publication" target="_blank">Website BPS
                            Kabupaten Bondowoso</a>.
                    </p>
                </div>
            </div> --}}
            <div class="card">
                <div class="card-header d-flex flex-column flex-sm-row align-items-sm-center justify-content-between gap-2">
                    <h4 class="card-title mb-0 flex-grow-1 mb-2">Perhitungan Topsis | Alternatif Kecamatan
                    </h4>

                    <div class="d-flex flex-column flex-sm-row justify-content-between gap-2 w-100">
                        <div class="d-flex flex-column flex-sm-row gap-2 w-100">
                            <select class="form-select w-100" id="choiceMonth" aria-label="pilih-bulan">
                                <option selected value="01">01</option>
                                <option value="02">02</option>
                                <option value="03">03</option>
                                <option value="04">04</option>
                                <option value="05">05</option>
                                <option value="06">06</option>
                                <option value="07">07</option>
                                <option value="08">08</option>
                                <option value="09">09</option>
                                <option value="10">10</option>
                                <option value="11">11</option>
                                <option value="12">12</option>
                            </select>
                            @php
                                // Tahun yang sudah ada di dropdown
                                $existingYears = [2021, 2022, 2023];

                                // Tahun tambahan dari Controller (misal dari database)
                                $newYears = $years; // Data ini bisa berasal dari database atau controller

                                // Gabungkan array dan hapus duplikat
                                $allYears = array_unique(array_merge($existingYears, $newYears));

                                // Urutkan tahun secara ascending
                                sort($allYears);
                            @endphp
                            <select class="form-select w-100" id="choiceYear" aria-label="pilih-tahun">
                                @foreach ($allYears as $year)
                                    <option value="{{ $year }}">{{ $year }}</option>
                                @endforeach
                            </select>
                        </div>

                        <div class="d-flex w-100">
                            <div class="ms-1">
                                <span id="btn-update-alternatif-sub-district"
                                    class="btn btn-warning waves-effect waves-light">
                                    Perbarui
                                </span>
                            </div>
                            <div class="ms-1">
                                <button class="btn btn-md btn-primary" id="btn-add-alternatif" data-bs-toggle="modal"
                                    data-bs-target="#btn-add">
                                    tambah alternatif
                                </button>
                            </div>
                        </div>
                    </div>
                </div><!-- end card header -->

                <div class="card-body">
                    <div id="table-alternatif-sub-district" class="table-responsive">
                    </div>
                    <div class="mt-2 d-flex justify-content-end">
                        <span id="btn-count-topsis" class="btn btn-success waves-effect waves-light d-none">
                            Hitung
                        </span>
                    </div>
                </div><!-- end card-body -->
            </div><!-- end card -->
        </div>

        {{-- matriks ternomalisasi --}}
        <div class="col-lg-12 d-none" id="matriks-ternomalisasi-id">
            <div class="card">
                <div class="card-header d-flex align-items-center justify-content-between">
                    <h4 class="card-title mb-0 flex-grow-1">Perhitungan Topsis | Matriks Ternomalisasi
                    </h4>
                </div><!-- end card header -->

                <div class="card-body">
                    <div id="table-matriks-ternomalisasi-sub-district" class="table-responsive">
                    </div>
                </div><!-- end card-body -->
            </div><!-- end card -->
        </div>

        {{-- matriks ternomalisasi terbobot --}}
        <div class="col-lg-12 d-none" id="matriks-ternomalisasi-terbobot-id">
            <div class="card">
                <div class="card-header d-flex align-items-center justify-content-between">
                    <h4 class="card-title mb-0 flex-grow-1">Perhitungan Topsis | Matriks Ternomalisasi Terbobot
                    </h4>
                </div><!-- end card header -->

                <div class="card-body">
                    <div id="table-ternomalisasi-terbobot-sub-district" class="table-responsive">
                    </div>
                </div><!-- end card-body -->
            </div><!-- end card -->
        </div>

        {{-- solusi ideal positif dan negatif --}}
        <div class="col-lg-12 d-none" id="solusi-ideal-id">
            <div class="card">
                <div class="card-header d-flex align-items-center justify-content-between">
                    <h4 class="card-title mb-0 flex-grow-1">Perhitungan Topsis | Solusi Ideal
                    </h4>
                </div><!-- end card header -->

                <div class="card-body">
                    <div id="table-solusi-ideal-sub-district" class="table-responsive">
                    </div>
                </div><!-- end card-body -->
            </div><!-- end card -->
        </div>

        {{-- solusi ideal terbobot --}}
        <div class="col-lg-12 d-none" id="solusi-ideal-terbobot-id">
            <div class="card">
                <div class="card-header d-flex align-items-center justify-content-between">
                    <h4 class="card-title mb-0 flex-grow-1">Perhitungan Topsis | Solusi Ideal Terbobot
                    </h4>
                </div><!-- end card header -->

                <div class="card-body">
                    <div id="table-solusi-ideal-terbobot-sub-district" class="table-responsive">
                    </div>
                </div><!-- end card-body -->
            </div><!-- end card -->
        </div>

        {{-- hasil preferensi kecamatan --}}
        <div class="col-lg-12 d-none" id="hasil-preferensi-id">
            <div class="card">
                <div class="card-header d-flex align-items-center justify-content-between">
                    <h4 class="card-title mb-0 flex-grow-1">Perhitungan Topsis | Hasil Preferensi
                    </h4>
                </div><!-- end card header -->

                <div class="card-body">
                    <div id="table-hasil-preferensi-sub-district" class="table-responsive">
                    </div>
                </div><!-- end card-body -->
            </div><!-- end card -->
        </div>

        {{-- hasil tanaman per kecamatan --}}
        <div class="col-lg-12 d-none" id="hasil-plantBySubDistrict-id">
            <div class="card">
                <div class="card-header d-flex align-items-center justify-content-between">
                    <h4 class="card-title mb-0 flex-grow-1">Perhitungan Topsis | Hasil Tanaman Per Kecamatan
                    </h4>
                </div><!-- end card header -->

                <div class="card-body">
                    <div id="table-hasil-plantBySubDistrict" class="table-responsive">
                    </div>
                </div><!-- end card-body -->
            </div><!-- end card -->
        </div>
    </div>

    <!-- update alternatif referensi modals -->
    <div class="modal fade" id="modal-edit" tabindex="-1" aria-labelledby="btn-editLabel" aria-modal="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="btn-editLabel">Ubah Data Alternatif (Kecamatan)</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <form action="{{ route('sub-district-alternatif.updateAlternatifBySubDistrict') }}" method="POST">
                        @csrf
                        <div class="row g-3">
                            <input type="hidden" name="subDistrictId" id="subDistrictId">
                            <div class="col-lg-12">
                                <div>
                                    <label for="subDistrict" class="form-label">
                                        Kecamatan
                                    </label>
                                    <input type="text" class="form-control mb-1" id="subDistrict" name="subDistrict"
                                        placeholder="masukkan nilai kriteria" required readonly>
                                </div>
                            </div><!--end col-->

                            <div class="col-lg-6">
                                <div>
                                    <label for="month" class="form-label">
                                        Bulan
                                    </label>
                                    <input type="text" class="form-control mb-1" id="month" name="month"
                                        required readonly>
                                </div>
                            </div><!--end col-->
                            <div class="col-lg-6">
                                <div>
                                    <label for="year" class="form-label">
                                        Tahun
                                    </label>
                                    <input type="text" class="form-control mb-1" id="year" name="year"
                                        required readonly>
                                </div>
                            </div><!--end col-->


                            <div class="col-lg-12">
                                <div class="row" id="criteriaFields"></div>
                            </div>

                            <div class="col-lg-12">
                                <div class="hstack gap-2 justify-content-end">
                                    <button type="button" class="btn btn-light" data-bs-dismiss="modal">Close</button>
                                    <button type="submit" class="btn btn-primary">Submit</button>
                                </div>
                            </div><!--end col-->
                        </div><!--end row-->
                    </form>
                </div>
            </div>
        </div>
    </div>

    <!-- add alternatif referensi modals -->
    <div class="modal fade" id="btn-add" tabindex="-1" aria-labelledby="btn-addLabel" aria-modal="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="btn-addLabel">Tambah Data Alternatif (Kecamatan)</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <form action="{{ route('sub-district-alternatif.addAlternatifSubDistrict') }}" method="POST">
                        @csrf
                        <div class="row g-3">
                            @if ($subDistricts->count() == 0)
                                <div class="col-lg-12">
                                    <div class="d-flex align-items-center justify-content-center text-success">
                                        <span>data alternatif kecamatan sudah lengkap</span>
                                    </div>
                                </div>
                            @else
                                <div class="col-lg-12">
                                    <div>
                                        <label for="subDistrictId" class="form-label">Pilih Kecamatan</label>
                                        <select class="form-select mb-3" aria-label="Default select example"
                                            name="subDistrictId" id="subDistrictId">
                                            @foreach ($subDistricts as $subDistrict)
                                                <option value="{{ $subDistrict->id }}">{{ $subDistrict->sub_district }}
                                                </option>
                                            @endforeach
                                        </select>
                                    </div>
                                </div><!--end col-->
                                <div class="col-lg-6">
                                    <div>
                                        <label for="month" class="form-label">
                                            Bulan
                                        </label>
                                        {{-- <input type="text" class="form-control mb-1" id="month" name="month"
                                            required> --}}
                                        <select class="form-select mb-3" aria-label="Default select example"
                                            name="month" id="month">
                                            <option selected value="01">Januari</option>
                                            <option value="02">Februari</option>
                                            <option value="03">Maret</option>
                                            <option value="04">April</option>
                                            <option value="05">Mei</option>
                                            <option value="06">Juni</option>
                                            <option value="07">Juli</option>
                                            <option value="08">Agustus</option>
                                            <option value="09">September</option>
                                            <option value="10">Oktober</option>
                                            <option value="11">November</option>
                                            <option value="12">Desember</option>
                                        </select>
                                    </div>
                                </div><!--end col-->
                                <div class="col-lg-6">
                                    <div>
                                        <label for="year" class="form-label">
                                            Tahun
                                        </label>
                                        <input type="text" class="form-control mb-1 year-input" id="year"
                                            name="year" required>
                                    </div>
                                </div><!--end col-->
                                @foreach ($criterias as $criteria)
                                    <div class="col-lg-6">
                                        <div>
                                            <label for="criteria{{ $criteria->criteria }}" class="form-label">
                                                Masukkan {{ $criteria->criteria }}
                                            </label>
                                            <input type="text" class="form-control mb-1"
                                                id="criteria{{ $criteria->criteria }}" name="{{ $criteria->criteria }}"
                                                placeholder="masukkan nilai kriteria" required
                                                oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/^\.+|\.\.+/g, '').replace(/(\.\d*)\./g, '$1')">
                                        </div>
                                    </div><!--end col-->
                                @endforeach
                                <div class="col-lg-12">
                                    <div class="hstack gap-2 justify-content-end">
                                        <button type="button" class="btn btn-light"
                                            data-bs-dismiss="modal">Close</button>
                                        <button type="submit" class="btn btn-primary">Submit</button>
                                    </div>
                                </div><!--end col-->
                            @endif
                        </div><!--end row-->
                    </form>
                </div>
            </div>
        </div>
    </div>

    <script src="{{ asset('assets/libs/prismjs/prism.js') }}"></script>
    <script src="{{ asset('assets/libs/gridjs/gridjs.umd.js') }}"></script>
    <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>

    {{-- <script src="{{ asset('assets/js/pages/gridjs.init.js') }}"></script> --}}

    {{-- custom js --}}
    <script src="{{ asset('assets/js/custom/sub-district-alternatif.js') }}"></script>
@endsection
