<!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('Bundles')"></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="/cutting/_bundle-sidebar :: sidebar"></aside>
                <!-- sidebar ends -->
                <!--header starts-->
                <div class="col-sm">
                    <div th:replace="_notices :: page-notices"></div>
                    <div class="mb-4 d-flex justify-content-between">
                        <h3>Bundles</h3>
                    </div>
                    <div th:replace="_fragments :: table-loading-skeleton"></div>
                    <form th:action="@{/cutting/generate-bundle-barcodes}" method="post">
                        <input hidden="hidden" name="artifactType" value="Bundle">
                        <table class="table table-striped" data-table data-order="[[ 0, &quot;desc&quot; ]]">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>Item ID</th>
                                    <th>Sku</th>
                                    <th>Is tagged</th>
                                    <th>Master Barcode ID</th>
                                    <th>JC ID</th>
                                    <th>Wrap Quantity</th>
                                    <th>Type</th>
                                    <th>Created At</th>
                                    <th>Created By</th>
                                    <th>
                                        <div class="mb-2">
                                            <button class="btn btn-sm btn-outline-primary" type="submit">Generate Bundle Barcode</button>
                                        </div>
                                        <div><input type="checkbox" data-checkbox-all></div>
                                    </th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr th:each="bundle : ${bundles}">
                                    <td th:text="${bundle.id}"></td>
                                    <td th:text="${bundle.itemId}"></td>
                                    <td th:text="${bundle.sku}"></td>
                                    <td>
                                        <span th:if="${bundle.masterBundleId == 0}" class="badge badge-UN_TAGGED">NOT TAG YET</span>
                                        <div th:if="${bundle.masterBundleId != 0}">
                                            <span class="badge badge-TAGGED">TAGGED</span>
                                        </div>
                                    </td>
                                    <td th:text="${bundle.masterBundleId}"></td>
                                    <td th:text="${bundle.jobCardId}"></td>
                                    <td th:text="${bundle.wrapQuantity}"></td>
                                    <td th:text="${bundle.type}"></td>
                                    <td ctp:formatdatetime="${bundle.createdAt}"></td>
                                    <td th:text="${bundle.createdBy}"></td>
                                    <td>
                                        <div class="form-group form-check mb-0">
                                            <input class="form-check-input" type="checkbox"
                                                   th:value="*{bundle.id}"
                                                   name="ids" th:id="*{id}">
                                            <label th:for="*{id}" class="form-check-label"></label>
                                        </div>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </form>
                </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>