<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.w3.org/1999/xhtml"
      xmlns:uind="http://www.w3.org/1999/xhtml" xmlns:ctp="http://www.w3.org/1999/xhtml">
    <head th:replace="_fragments :: head('Stitching offline Items')"></head>
    <body>
        <div class="container-fluid">
            <header class="row page-header" th:replace="_fragments :: page-header"></header>
            <main class="row page-main">
                <!-- sidebar starts -->
                <aside class="col-sm-2" th:replace="/stitching/_stitching-sidebar :: sidebar"></aside>
                <!-- sidebar ends -->
                <!--header starts-->
                <div class="col-sm">
                    <div th:replace="_notices :: page-notices"></div>
                    <div th:replace="_fragments :: table-loading-skeleton"></div>
                    <form th:action="@{/cutting/generate-qrCode}" method="post">
                        <input hidden="hidden" name="artifactType" value="FinishedItem">
                        <table th:if="${ #lists != null && #lists.size(items) !=  0 }" class="table table-striped table-bordered" data-table
                               data-order="[[ 0, &quot;desc&quot; ]]">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>Item ID</th>
                                    <th>Bundle ID</th>
                                    <th>Sku</th>
                                    <th>Created At</th>
                                    <th>Created By</th>
                                    <th>Is QA</th>
                                    <th th:if="${!#strings.startsWith(#httpServletRequest.getRequestURI(), '/ctp/stitching/stitching-offline-items')}">
                                        <div class="mb-2" >
                                            <button class="btn btn-sm btn-outline-primary" type="submit">Generate QR code</button>
                                        </div>
                                        <div><input type="checkbox" data-checkbox-all></div>
                                    </th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr th:each="item : ${items}" th:object="${item}">
                                    <td th:text="*{id}"></td>
                                    <td th:text="*{itemId}"></td>
                                    <td th:text="*{bundleId}"></td>
                                    <td th:text="*{sku}"></td>
                                    <td ctp:formatdatetime="*{createdAt}"></td>
                                    <td th:text="*{createdBy}"></td>
                                    <td>
                                        <span th:if="${ not item.isQa}" class="badge badge-danger">NOT PERFORMED</span>
                                        <div th:if="${item.isQa}">
                                            <span class="badge badge-APPROVED">PERFORMED</span>
                                        </div>
                                        <div th:text="*{qaStatus}"></div>
                                        <div th:text="*{qaRemarks}"></div>
                                    </td>
                                    <td th:if="${!#strings.startsWith(#httpServletRequest.getRequestURI(), '/ctp/stitching/stitching-offline-items')}">
                                        <div class="form-group form-check mb-0">
                                            <input class="form-check-input" type="checkbox"
                                                   th:value="*{id}"
                                                   name="ids" th:id="*{id}">
                                            <label th:for="*{id}" class="form-check-label"></label>
                                        </div>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </form>
                    <h4 th:if="${#lists.size(items) == 0}">No Stitching Items found.</h4>
                </div>
            </main>
        </div>
        <div th:replace="_fragments :: page-footer-scripts"></div>
        <script th:inline="javascript">
            (async function () {
                const $selectAllCheckBox = $('[data-checkbox-all]');

                $selectAllCheckBox.change(function () {
                    if ($selectAllCheckBox.prop('checked')) {
                        // When parent checkbox is checked, check all child checkboxes
                        $('[name="ids"]').each(function () {
                            let $this = $(this);
                            $this.prop('checked', true);
                        });
                    } else {
                        // When parent checkbox is unchecked, uncheck all child checkboxes
                        $('[name="ids"]').each(function () {
                            let $this = $(this);
                            $this.prop('checked', false);
                        });
                    }
                });
            })(jQuery)
        </script>
    </body>
</html>