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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>QualityFlow - Endline Table</title>
    <link rel="icon" type="image/png" href="{{ asset('gplogofinal.png') }}">
    <!-- Bootstrap 5 CSS -->
    <link href="{{ asset('css/bootstrap.min.css') }}" rel="stylesheet">
    <!-- Bootstrap Icons -->
    <link rel="stylesheet" href="{{ asset('css/bootstrap-icons.css') }}">
    <!-- Google Fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700;900&display=swap" rel="stylesheet">

    <style>
        body {
            font-family: 'Roboto', sans-serif;
            background-color: #f5f6f8;
            /* Light gray background */
        }

        /* Summary Card Styling */
        .summary-card {
            background-color: white;
            border-radius: 12px;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.03);
            /* Soft shadow */
            border: 1px solid rgba(0, 0, 0, 0.05);
            /* very subtle border */
            padding: 1.5rem;
            display: flex;
            align-items: center;
            justify-content: space-between;
            height: 100%;
            transition: transform 0.2s, box-shadow 0.2s;
        }

        .summary-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 25px rgba(0, 0, 0, 0.06);
        }

        .summary-card-left {
            display: flex;
            align-items: center;
            gap: 1rem;
        }

        .summary-icon-wrapper {
            width: 45px;
            height: 45px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            background-color: #f8f9fa;
            /* minimal gray circle */
            border: 1px solid #e9ecef;
        }

        .summary-icon-wrapper i {
            font-size: 1.25rem;
            color: #adb5bd;
            /* subtle gray icon color */
        }

        .summary-title {
            font-size: 0.70rem;
            font-weight: 700;
            color: #8c98a4;
            letter-spacing: 0.8px;
            text-transform: uppercase;
            margin: 0;
            white-space: nowrap;
        }

        .summary-value {
            font-size: 2.2rem;
            font-weight: 700;
            margin: 0;
            line-height: 1;
            color: #d32f2f;
        }

        /* Metric Specific Colors for Values */
        .val-checked {
            color: #1a1e23;
        }

        /* Black/Dark Gray */
        .val-passed {
            color: #0d9656;
        }

        /* Green */
        .val-first-pass {
            color: #00c853;
        }

        /* Lighter Green */
        .val-rejection {
            color: #d32f2f;
        }

        /* Red */
        .val-rework-total {
            color: #2b4cc4;
        }

        /* Blue */
        .val-rework-completed {
            color: #1976d2;
        }

        /* Lighter Blue */
        .val-rework-pending {
            color: #e65100;
        }

        /* Orange */
        .val-rework-pending-yesterday {
            color: #a1640e;
        }

        /* Brown/Dark Orange */

        /* Table Card Styling */
        .table-card {
            background-color: white;
            border-radius: 12px;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.03);
            /* Soft shadow */
            border: 1px solid rgba(0, 0, 0, 0.05);
            /* very subtle border */
            overflow: hidden;
            /* round corners for table */
            margin-top: 1rem;
            margin-bottom: 4rem;
        }

        .table-responsive {
            margin: 0;
        }

        .custom-table {
            margin-bottom: 0;
            width: 100%;
        }

        .custom-table th {
            font-size: 0.75rem;
            font-weight: 700;
            color: #8c98a4;
            letter-spacing: 0.8px;
            text-transform: uppercase;
            padding: 1.2rem 1.5rem;
            border-bottom: 1px solid #e2e6f0;
            background-color: transparent;
            text-align: center;
        }

        /* Metric Column Header Align Left */
        .custom-table th:first-child {
            text-align: left;
        }

        .custom-table td {
            font-size: 1.1rem;
            font-weight: 600;
            padding: 1.5rem 1.5rem;
            border-bottom: 1px solid #f0f2f5;
            vertical-align: middle;
            text-align: center;
        }

        /* Metric Column Value Align Left & Styling */
        .custom-table td:first-child {
            text-align: left;
            font-size: 0.8rem;
            font-weight: 600;
            color: #495057;
            /* Darker gray for row labels */
            text-transform: uppercase;
        }

        .custom-table tr:last-child td {
            border-bottom: none;
        }
    </style>
</head>

<body>

    @php
        $emp_checker = session('endline_checker');
        $emp_id_from_session = $emp_checker ? $emp_checker['employee_id'] : '';
    @endphp

    <!-- Injecting the navigation bar blade components -->
    @include('Quality.Endline_nav')

    <!-- Dashboard Content -->
    <div class="container-fluid px-4 px-lg-5 mt-3">

        <!-- <div class="card border-0 shadow-sm p-3 mb-3" style="max-width: 200px; margin-left: auto;">
        <div id="date" class="d-flex flex-column align-items-end">
            <small class="text-muted text-uppercase fw-bold" style="font-size: 0.7rem; letter-spacing: 1px;">Issue Date</small>
            <span class="fs-5 fw-semibold text-primary">
            {{ date('d-m-y') }}
            </span>
        </div>
        </div> -->




        <!-- Top Metrics Cards Row 1 -->
        <div class="row g-4 mb-2">
            <!-- Checked -->
            <div class="col-12 col-md-6 col-lg-3">
                <div class="summary-card">
                    <div class="summary-card-left">
                        <div class="summary-icon-wrapper">
                            <i class="bi bi-bullseye"></i>
                        </div>
                        <h3 class="summary-title">CHECKED</h3>
                    </div>
                    <p class="summary-value val-checked">{{ $resultdata[0]->checked }}</p>
                </div>
            </div>

            <!-- Passed -->
            <div class="col-12 col-md-6 col-lg-3">
                <div class="summary-card">
                    <div class="summary-card-left">
                        <div class="summary-icon-wrapper">
                            <i class="bi bi-check2"></i>
                        </div>
                        <h3 class="summary-title">PASSED</h3>
                    </div>
                    <p class="summary-value val-passed">{{ $resultdata[0]->passed ?? 0 }}</p>
                </div>
            </div>

            <!-- First Pass -->
            <div class="col-12 col-md-6 col-lg-3">
                <div class="summary-card">
                    <div class="summary-card-left">
                        <div class="summary-icon-wrapper">
                            <i class="bi bi-shield-check"></i>
                        </div>
                        <h3 class="summary-title">FIRST PASS</h3>
                    </div>
                    <p class="summary-value val-first-pass">{{ $resultdata[0]->first_pass ?? 0 }}</p>
                </div>
            </div>

            <!-- Rejection -->
            <div class="col-12 col-md-6 col-lg-3">
                <div class="summary-card">
                    <div class="summary-card-left">
                        <div class="summary-icon-wrapper">
                            <i class="bi bi-exclamation-octagon"></i>
                        </div>
                        <h3 class="summary-title">REJECTION</h3>
                    </div>
                    <p class="summary-value val-rejection">{{ $resultdata[0]->rejection ?? 0 }}</p>
                </div>
            </div>
        </div>

        <!-- Top Metrics Cards Row 2 -->
        <div class="row g-4">
            <!-- Rework Total -->
            <div class="col-12 col-md-6 col-lg-3">
                <div class="summary-card">
                    <div class="summary-card-left">
                        <div class="summary-icon-wrapper">
                            <i class="bi bi-arrow-repeat"></i>
                        </div>
                        <h3 class="summary-title">REWORK TOTAL</h3>
                    </div>
                    <p class="summary-value val-rework-total">{{ $resultdata[0]->rework_total ?? 0 }}</p>
                </div>
            </div>

            <!-- Rework Completed -->
            <div class="col-12 col-md-6 col-lg-3">
                <div class="summary-card">
                    <div class="summary-card-left">
                        <div class="summary-icon-wrapper">
                            <i class="bi bi-check-circle"></i>
                        </div>
                        <h3 class="summary-title">REWORK COMPLETED</h3>
                    </div>
                    <p class="summary-value val-rework-completed">{{ $resultdata[0]->rework_passed }}</p>
                </div>
            </div>

            <!-- Rework Pending -->
            <div class="col-12 col-md-6 col-lg-3">
                <div class="summary-card">
                    <div class="summary-card-left">
                        <div class="summary-icon-wrapper">
                            <i class="bi bi-clock-history"></i>
                        </div>
                        <h3 class="summary-title">REWORK PENDING</h3>
                    </div>
                    <p class="summary-value val-rework-pending">{{ $resultdata[0]->rework_pending }}</p>
                </div>
            </div>

            <!-- Rework Pending Yesterday -->
            <div class="col-12 col-md-6 col-lg-3">
                <div class="summary-card">
                    <div class="summary-card-left">
                        <div class="summary-icon-wrapper">
                            <i class="bi bi-arrow-counterclockwise"></i>
                        </div>
                        <h3 class="summary-title">REWORK PENDING YESTERDAY</h3>
                    </div>
                    <p class="summary-value val-rework-pending-yesterday">{{ $resultdata[0]->rework_pending_yesterday }}
                    </p>
                </div>
            </div>
        </div>

        <!-- Hourly Metrics Data Table -->
        <div class="table-card">
            <div class="table-responsive">
                <table class="table custom-table table-borderless">
                    <thead>
                        <tr>
                            <th>METRIC</th>
                            <th>H1</th>
                            <th>H2</th>
                            <th>H3</th>
                            <th>H4</th>
                            <th>H5</th>
                            <th>H6</th>
                            <th>H7</th>
                            <th>H8</th>
                        </tr>
                    </thead>
                    <tbody>
                        <!-- Checked Row -->

                        <!-- Passed Row -->
                        @foreach($resultdata_hourly as $hourly)
                            <tr>
                                <td>{{ $hourly->Metric }}</td>
                                <td class="val-checked">{{ $hourly->H1 }}</td>
                                <td class="val-checked">{{ $hourly->H2 }}</td>
                                <td class="val-checked">{{ $hourly->H3 }}</td>
                                <td class="val-checked">{{ $hourly->H4 }}</td>
                                <td class="val-checked">{{ $hourly->H5 }}</td>
                                <td class="val-checked">{{ $hourly->H6 }}</td>
                                <td class="val-checked">{{ $hourly->H7 }}</td>
                                <td class="val-checked">{{ $hourly->H8 }}</td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
        </div>

    </div>

    <!-- External Script Dependencies (jQuery & Bootstrap) -->
    <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
    <script src="{{ asset('js/bootstrap.bundle.min.js') }}"></script>

    <script>
        $(document).ready(function () {
            $('#datecard').removeClass('d-none');
            // Document is ready
            console.log("Endline Table page initialized.");
            $('#garmentIdDiv').addClass('d-none');


            // Prefer sessionStorage, but fall back to server session if user bypassed the scan page
            var serverEmpId = "{{ $emp_id_from_session }}";
            var JSempId = sessionStorage.getItem('emp_id');
            var empId = JSempId ? JSempId : serverEmpId;

            // Sync it back to storage if it was missing
            if (empId && !JSempId) {
                sessionStorage.setItem('emp_id', empId);
            }

            var lineNo = sessionStorage.getItem('endline_line_no');
            var group = sessionStorage.getItem('endline_group');

            $('#navScanNext').click(function () {
                window.location.href = "{{ route('endline.selection') }}";
            });

            console.log("Employee ID: " + empId);
            console.log("Line No: " + lineNo + ", Group: " + group);

        });
    </script>
</body>

</html>