<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta content="width=device-width, initial-scale=1.0" name="viewport">

    <title>Ellia Cellular</title>
    <meta content="" name="description">
    <meta content="" name="keywords">

    <!-- Favicons -->
    <link href="{{ asset('assets/img/favicon.png') }}" rel="icon">
    <link href="{{ asset('assets/img/apple-touch-icon.png') }}" rel="apple-touch-icon">

    <!-- Google Fonts -->
    <link href="https://fonts.gstatic.com" rel="preconnect">
    <link
        href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Nunito:300,300i,400,400i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700i"
        rel="stylesheet">

    <!-- Tambahkan ini di bagian <head> atau sebelum penutup </body> -->
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>


    <!-- Vendor CSS Files -->
    <link href="{{ asset('assets/vendor/bootstrap/css/bootstrap.min.css') }}" rel="stylesheet">
    <link href="{{ asset('assets/vendor/bootstrap-icons/bootstrap-icons.css') }}" rel="stylesheet">
    <link href="{{ asset('assets/vendor/boxicons/css/boxicons.min.css') }}" rel="stylesheet">
    <link href="{{ asset('assets/vendor/quill/quill.snow.css') }}" rel="stylesheet">
    <link href="{{ asset('assets/vendor/quill/quill.bubble.css') }}" rel="stylesheet">
    <link href="{{ asset('assets/vendor/remixicon/remixicon.css') }}" rel="stylesheet">
    <link href="{{ asset('assets/vendor/simple-datatables/style.css') }}" rel="stylesheet">

    <!-- Template Main CSS File -->
    <link href="{{ asset('assets/css/style.css') }}" rel="stylesheet">
</head>

<body>

    <!-- ======= Header ======= -->
    @include('header')
    <!-- ======= Sidebar ======= -->
    @include('sidebar')

    <main id="main" class="main">
        <div class="pagetitle">
            <h1>Perhitungan & Hasil Prediksi</h1>
            <nav>
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="{{route('dashboard')}}">Home</a></li>
                    <li class="breadcrumb-item">Data Mining</li>
                    <li class="breadcrumb-item">Perhitungan & Hasil Prediksi</li>
                </ol>
            </nav>
        </div><!-- End Page Title -->

        <div class="alert alert-info alert-dismissible fade show" role="alert">
            <strong>Keterangan:</strong>
            <ol class="mb-0 ps-3">
                <li>Pada Bulan & Tahun merupakan bulan dan tahun prediksinya</li>
                <li>Pada Minggu 1 hingga 4 merupakan hasil dari jumlah prediksi penjualan berdasarkan bulan dan tahun.</li>
                <li>Pada Total merupakan total prediksi jumlah penjualan smartphone pada 1 bulan atau 4 minggu.</li>
                <li>Klik tombol Ambil Hasil Prediksi untuk menampilkan Hasil Prediksi yang dihitung dari Euclidean Distance antara Data Training dan Data Testing.</li>
                <li>Klik tombol Reset Hasil Prediksi untuk menghapus Hasil Prediksi yang sudah dihitung.</li>
                <li>Pilih Brand berfungsi untuk menampilkan Perhitungan dan Hasil Prediksi dari brand yang ingin ditampilkan.</li>
            </ol>
            {{-- <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> --}}
        </div>

        <section class="section">
            <div class="row">
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-body">
                            <h5 class="card-title">Perhitungan & Hasil Prediksi</h5>
                            <div class="mb-1 d-flex align-items-center">
                                {{-- <form method="GET" action="{{ route('hasil.index') }}" class="mb-3">
                                    <label for="entriesPerBrand" class="form-label">Pilih Brand:</label>
                                    <select name="brand" id="entriesPerBrand" class="form-select w-auto d-inline"
                                        onchange="this.form.submit()">
                                        @foreach ($brands as $b)
                                            <option value="{{ $b->id }}"
                                                {{ $brand == $b->id ? 'selected' : '' }}>
                                                {{ $b->nama_brand }}
                                            </option>
                                        @endforeach
                                    </select>
                                </form> --}}
                                {{-- Pilih Brand --}}
                                {{-- <form method="GET" action="{{ route('hasil.index') }}" class="mb-3">
                                    <label for="entriesPerBrand" class="form-label">Pilih Brand:</label>
                                    <select name="brand" id="entriesPerBrand" class="form-select w-auto d-inline" onchange="this.form.submit()">
                                        @foreach ($brands as $b)
                                            <option value="{{ $b->id }}" {{ $brand == $b->id ? 'selected' : '' }}>
                                                {{ $b->nama_brand }}
                                            </option>
                                        @endforeach
                                    </select>
                                </form> --}}


                                <form method="GET" action="{{ route('hasil.index') }}" class="mb-3">
                                    <label for="entriesPerBrand" class="form-label">Pilih Brand:</label>
                                    <select name="brand" id="entriesPerBrand" class="form-select w-auto d-inline"
                                        onchange="this.form.submit()">
                                        @foreach ($brands as $b)
                                            <option value="{{ $b->id }}"
                                                {{ $brandId == $b->id ? 'selected' : '' }}>
                                                {{ $b->nama_brand }}
                                            </option>
                                        @endforeach
                                    </select>
                                </form>
                            </div>
                            {{-- Ambil Prediksi --}}
                            {{-- <form action="{{ route('hasil.proses') }}" method="POST">
                                @csrf
                                <input type="hidden" name="brand" value="{{ $brand }}">
                                <button type="submit" class="btn btn-success" {{ $hasData ? 'disabled' : '' }}>
                                    Ambil Hasil Prediksi
                                </button>
                            </form> --}}

                            <div class="d-flex justify-content-end align-items-center mb-3 gap-2">
                                <form action="{{ route('hasil.reset') }}" method="POST">
                                    @csrf
                                    <button type="submit" class="btn btn-danger">
                                        Reset Hasil Prediksi
                                    </button>
                                </form>
                                <form action="{{ route('hasil.proses') }}" method="POST">
                                    @csrf
                                    <button type="submit" class="btn btn-success" {{ $hasData ? 'disabled' : '' }}>
                                        Ambil Hasil Prediksi
                                    </button>
                                </form>
                            </div>
                            {{-- Tabel Hasil Prediksi
<table class="table table-striped table-bordered" id="hasilTable" style="text-align: center;">
    <tr>
        <th colspan="5" style="text-align: center;">HASIL PREDIKSI</th>
        <th>TOTAL</th>
    </tr>
    @php
        $totalAllMonths = 0;
    @endphp
    @foreach ($data as $row)
        @php
            $totalBulan = 0;
        @endphp
        <tr>
            <td><strong>{{ $row['bulan'] }}</strong></td>
            @php
                $total = 0;
            @endphp
            @foreach ($row['minggu'] as $nilai)
                @php
                    $total += $nilai ?? 0;
                    $totalBulan += $nilai ?? 0;
                @endphp
                <td>{{ $nilai ?? '' }}</td>
            @endforeach
            <td><strong>{{ $totalBulan }}</strong></td>
        </tr>
        @php
            $totalAllMonths += $totalBulan;
        @endphp
    @endforeach
    <tr>
        <th colspan="5">TOTAL</th>
        <th><strong>{{ $totalAllMonths }}</strong></th>
    </tr>
</table> --}}

                            <table class="table table-striped table-bordered" id="hasilTable">
                                <thead>
                                    <tr>
                                        <th>Bulan & Tahun</th>
                                        <th>Minggu 1</th>
                                        <th>Minggu 2</th>
                                        <th>Minggu 3</th>
                                        <th>Minggu 4</th>
                                        <th>TOTAL</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @forelse ($dataPerBulan as $bulan => $mingguData)
                                        <tr>
                                            <td>{{ $bulan }}</td>
                                            <td>{{ $mingguData['minggu_1'] ?? '-' }}</td>
                                            <td>{{ $mingguData['minggu_2'] ?? '-' }}</td>
                                            <td>{{ $mingguData['minggu_3'] ?? '-' }}</td>
                                            <td>{{ $mingguData['minggu_4'] ?? '-' }}</td>
                                            <td>{{ array_key_exists('total', $mingguData) ? $mingguData['total'] : '-' }}
                                            </td>
                                        </tr>
                                    @empty
                                        <tr>
                                            <td colspan="6" class="text-center">Belum ada hasil yang tersedia.</td>
                                        </tr>
                                    @endforelse
                                </tbody>
                            </table>

                            {{-- <table class="table table-striped table-bordered" id="hasilTable">
    <thead>
        <tr>
            <th>BULAN</th>
            <th>Minggu 1</th>
            <th>Minggu 2</th>
            <th>Minggu 3</th>
            <th>Minggu 4</th>
            <th>TOTAL</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Januari</td>
            <td>14</td>
            <td>13</td>
            <td>14</td>
            <td>14</td>
            <td>55</td>
        </tr>
        <tr>
            <td>Februari</td>
            <td>15</td>
            <td>21</td>
            <td>16</td>
            <td>11</td>
            <td>63</td>
        </tr>
        <tr>
            <td>Maret</td>
            <td>16</td>
            <td>15</td>
            <td>12</td>
            <td>11</td>
            <td>54</td>
        </tr>
        <tr>
            <td>April</td>
            <td>15</td>
            <td>11</td>
            <td>18</td>
            <td>11</td>
            <td>55</td>
        </tr>
    </tbody>
</table> --}}



                            {{-- <table class="table table-striped table-bordered text-center" id="hasilTable">
    <thead class="table-secondary">
        <tr>
            <th colspan="6" class="text-center">HASIL PREDIKSI</th>
        </tr>
        <tr>
            <th>BULAN</th>
            <th>Minggu 1</th>
            <th>Minggu 2</th>
            <th>Minggu 3</th>
            <th>Minggu 4</th>
            <th>TOTAL</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><strong>Januari</strong></td>
            <td>14</td>
            <td>13</td>
            <td>14</td>
            <td>14</td>
            <td><strong>55</strong></td>
        </tr>
        <tr>
            <td><strong>Februari</strong></td>
            <td>15</td>
            <td>21</td>
            <td>16</td>
            <td>11</td>
            <td><strong>63</strong></td>
        </tr>
        <tr>
            <td><strong>Maret</strong></td>
            <td>16</td>
            <td>15</td>
            <td>12</td>
            <td>11</td>
            <td><strong>54</strong></td>
        </tr>
        <tr>
            <td><strong>April</strong></td>
            <td>15</td>
            <td>11</td>
            <td>18</td>
            <td>11</td>
            <td><strong>55</strong></td>
        </tr>
        <tr class="table-secondary fw-bold">
            <td colspan="5" class="text-center">TOTAL</td>
            <td>227</td>
        </tr>
    </tbody>
</table> --}}

                            {{-- <tbody>
                                @if ($hasData)
                                    @foreach ($data as $row)
                                        <tr>
                                            <td>{{ $row['bulan'] }}</td>
                                            @foreach ($row['minggu'] as $nilai)
                                                <td>{{ $nilai ?? '' }}</td>
                                            @endforeach
                                        </tr>
                                    @endforeach
                                @else
                                    <tr>
                                        <td colspan="5" class="text-center">Belum ada data yang tersedia.</td>
                                    </tr>
                                @endif
                            </tbody> --}}
                            {{-- </table> --}}
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </main><!-- End #main -->

    <!-- Modal Tambah-->
    {{-- <div class="modal fade" id="tambahProduct" tabindex="-1" aria-labelledby="modaltambahproductLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="modalTambahProductLabel">Tambah Data Produk</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <form action="{{ route('product.store') }}" method="POST" enctype="multipart/form-data">
                        @csrf
                        <div class="mb-3">
                            <label for="nama_produk" class="form-label">Nama Produk</label>
                            <input type="text" class="form-control" id="nama_produk" name="nama_produk" required>
                        </div>
                        <div class="mb-3">
                            <label for="brand_id" class="form-label">Brand</label>
                            <select class="form-select" id="brand_id" name="brand_id" required>
                                <option value="" disabled selected>Pilih Brand</option>
                                @foreach ($brand as $b)
                                    <option value="{{ $b->id }}">{{ $b->nama_brand }}</option>
                                @endforeach
                            </select>
                        </div>
                        
                        <div class="mb-3">
                            <label for="category_id" class="form-label">Kategori</label>
                            <select class="form-select" id="category_id" name="category_id" required>
                                <option value="" disabled selected>Pilih Kategori</option>
                                @foreach ($category as $c)
                                    <option value="{{ $c->id }}">{{ $c->nama_kategori }}</option>
                                @endforeach
                            </select>
                        </div>
                        
                        <div class="mb-3">
                            <label for="harga" class="form-label">Harga Produk</label>
                            <input type="text" class="form-control" id="harga" name="harga" required>
                        </div>
                        <div class="mb-3">
                            <label for="stok" class="form-label">Stok Produk</label>
                            <input type="text" class="form-control" id="stok" name="stok" required>
                        </div>
                        <div class="mb-3">
                            <label for="image" class="form-label">Foto Produk</label>
                            <input type="file" class="form-control" id="image" name="image"
                                accept="image/*">
                        </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Tutup</button>
                    <button type="submit" class="btn btn-primary">Simpan Data</button>
                </div>
                </form>
            </div>
        </div>
    </div> --}}




    <!-- ======= Footer ======= -->
    @include('footer')

    <a href="#" class="back-to-top d-flex align-items-center justify-content-center"><i
            class="bi bi-arrow-up-short"></i></a>

    <!-- Vendor JS Files -->
    <script src="{{ asset('assets/vendor/apexcharts/apexcharts.min.js') }}"></script>
    <script src="{{ asset('assets/vendor/bootstrap/js/bootstrap.bundle.min.js') }}"></script>
    <script src="{{ asset('assets/vendor/chart.js/chart.umd.js') }}"></script>
    <script src="{{ asset('assets/vendor/echarts/echarts.min.js') }}"></script>
    <script src="{{ asset('assets/vendor/quill/quill.js') }}"></script>
    <script src="{{ asset('assets/vendor/simple-datatables/simple-datatables.js') }}"></script>
    <script src="{{ asset('assets/vendor/tinymce/tinymce.min.js') }}"></script>
    <script src="{{ asset('assets/vendor/php-email-form/validate.js') }}"></script>

    <!-- Template Main JS File -->
    <script src="{{ asset('assets/js/main.js') }}"></script>

    <style>
        #sampleTable th,
        #sampleTable td {
            text-align: center;
            vertical-align: middle;
        }
    </style>


</body>

</html>
