<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.w3.org/1999/xhtml"
      xmlns:v-bind="http://www.w3.org/1999/xhtml">
    <head th:replace="_fragments :: head('Create Stitching Item')"></head>
    <body>
        <div class="container-fluid">
            <header class="row page-header" th:replace="_fragments :: page-header"></header>
            <main class="row page-main">
                <div class="col-sm">
                    <div th:replace="_notices :: page-notices"></div>
                    <h3 class="pb-2">Create Stitching Items</h3>
                    <form th:action="@{/stitching/create-stitching-items}"
                          method="POST"
                          id="finishedItemApp"
                          th:object="${jobCard}">
                        <div class="bg-light p-3 mb-3 col-sm-8">
                            <div class="form-row">
                                <div class="col-sm-5 p-0">
                                    <job-card-search
                                            v-bind:id-field-name="'id'"
                                            v-bind:filter="false"
                                            v-bind:items="true"
                                            v-on:job-card-select="onJobCardSelect">
                                    </job-card-search>
                                </div>
                                <div class="col-sm-4">
                                    <label>Stitching Account</label>
                                    <select class="form-control" name="toAccountId" required>
                                        <option value="">Please Select</option>
                                        <option th:each="account :${accounts}"
                                                th:value="${account.id}"
                                                th:text="${account.title}"
                                                th:title="${account.notes}"></option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="bg-light p-3 mb-3 col-sm-8">
                            <h6>Items</h6>
                            <div class="form-row col-sm-12">
                                <table class="table mt-2 table-bordered table-hover bg-white">
                                    <tr>
                                        <th></th>
                                        <th>ID</th>
                                        <th>Item ID</th>
                                        <th>Sku</th>
                                        <th>Expected Production</th>
                                        <th>Actual  Production</th>
                                        <th>Current Production</th>
                                        <th>Production</th>
                                    </tr>
                                    <tbody>
                                        <tr v-if="(item.actualProduction !== item.totalProduction)" v-for="(item,index) in items">
                                            <td  >
                                                <div class="form-group form-check mb-0">
                                                    <input class="form-check-input" type="checkbox" v-bind:name="'items[' + index + '].isSelected'" v-model="item.isSelected">
                                                    <label th:for="*{id}" class="form-check-label"></label>
                                                </div>
                                            </td>
                                            <td>
                                                <input hidden="hidden" v-bind:name="'items[' + index + '].id'" v-bind:value="item.id">
                                                <span class="form-control">{{item.id}}</span>
                                            </td>
                                            <td>
                                                <input hidden="hidden" v-bind:name="'items[' + index + '].itemId'" v-bind:value="item.itemId">
                                                <span class="form-control">{{item.itemId}}</span>
                                            </td>
                                            <td>
                                                <input hidden="hidden" v-bind:name="'items[' + index + '].sku'" v-bind:value="item.sku">
                                                <span class="form-control">{{item.sku}}</span>
                                            </td>
                                            <td>
                                                <input hidden="hidden"  v-bind:name="'items[' + index + '].expectedProduction'" v-bind:value="item.expectedProduction">
                                                <span class="form-control">{{item.expectedProduction}}</span>
                                            </td>
                                            <td>
                                                <input hidden="hidden"  v-bind:name="'items[' + index + '].actualProduction'" v-bind:value="item.actualProduction">
                                                <span class="form-control">{{item.actualProduction}}</span>
                                            </td>
                                            <td>
                                                <input hidden="hidden"   v-bind:name="'items[' + index + '].totalProduction'" v-bind:value="item.totalProduction">
                                                <span class="form-control">{{item.totalProduction}}</span>
                                            </td>
                                            <td>
                                                <input class="form-control" v-bind:name="'items[' + index + '].production'"
                                                       type="number"
                                                       v-bind:value="item.production"
                                                       v-bind:min="0"
                                                       v-bind:max="item.actualProduction - item.totalProduction"
                                                       v-bind:readonly="!item.isSelected"
                                                       >
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div>
                            <button class="btn btn-primary" type="submit">Receive Inventory</button>
                            <a th:href="@{/stitching/stitching-offline-items}" class="btn btn-light">Cancel</a>
                        </div>
                    </form>
                    <script th:inline="javascript">
                    </script>
                    <script th:src="@{/js/vendor/compressor.min.js}"></script>
                    <script th:src="@{/js/stitching/create-finished-item.js}"></script>
                </div>
            </main>
        </div>
        <div th:replace="_fragments :: page-footer-scripts"></div>
    </body>
</html>