<!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('Home Page')"></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"  th:fragment="cardFragment">
                    <div th:replace="_notices :: page-notices"></div>
                    <form th:action="@{ ${jobCard.id} ? ('/job-cards/edit/' + ${jobCard.id}) : '/job-cards/edit' }"
                          method="POST"
                          th:object="${jobCard}"
                          id="jobCardApp">
                        <input hidden="hidden" th:field="*{id}">
                        <input hidden="hidden" th:field="*{code}">
                        <input hidden="hidden" th:field="*{createdAt}">
                        <input hidden="hidden" th:field="*{createdBy}">
                        <input hidden="hidden" th:field="*{status}">
                        <input hidden="hidden" th:field="*{inventoryStatus}">
                        <div class="bg-light p-3 mb-3">
                            <h6 class="mb-3">Info</h6>
                            <div class="form-row">
                                <div class="col-sm-3 form-group">
                                    <label>Job Order</label>
                                    <input type="number" class="form-control" th:field="*{jobOrderId}" required>
                                </div>
                                <div class="col-sm-3 form-group">
                                    <label>Customer</label>
                                    <input class="form-control" th:field="*{customer}" required>
                                </div>
                                <div class="col-sm-3 form-group">
                                    <label>Lot Number</label>
                                    <input class="form-control" th:field="*{lotNumber}" required>
                                </div>
                            </div>
                            <div class="form-row">
                                <div class="col-sm-3 form-group" th:with="title=*{purchaseOrderTitle},id=*{purchaseOrderId}">
                                    <purchase-order-search th:attr="id=${id},title=${title}"
                                        v-bind:id-field-name="'purchaseOrderId'"
                                    >
                                    </purchase-order-search>
                                </div>
                                <div class="col-sm-3 form-group" th:with="title=*{locationTitle},id=*{locationSiteId}">
                                    <location-site-search th:attr="id=${id},title=${title}"
                                            v-bind:id-field-name="'locationSiteId'">
                                    </location-site-search>
                                </div>
                                <div class="col-sm-3 form-group">
                                    <label>Generated Date</label>
                                    <span class="form-control" ctp:formatdatetime="*{createdAt}" readonly>
                                </div>
                            </div>
                            <div class="form-row">
                                <div class="col-sm-6 form-group">
                                    <label>Description*</label>
                                    <textarea class="form-control" rows="2" th:field="*{description}"></textarea>
                                </div>
                            </div>
                        </div>
                        <div class="bg-light p-3 mb-3">
                            <h6 class="mb-3">Items</h6>
                            <job-card-item
                                    v-for="(item,index) in items"
                                    v-bind:item="item"
                                    v-bind:key="index"
                                    v-bind:index="index"
                                    v-bind:items.sync="items">
                            </job-card-item>
                            <div class="alert alert-danger" v-if="hasDuplicates()"><b>Duplicate Items Selected</b></div>
                            <button class="btn btn-secondary btn-sm" v-on:click="addItem">
                                Add Item
                            </button>
                        </div>
                        <div>
                            <button class="btn btn-secondary" type="submit" name="user" value="draft" v-bind:disabled="hasEmptyItems()">Save Draft</button>
                            <button class="btn btn-primary" type="submit" name="user" value="post"  v-bind:disabled="hasEmptyItems()">Post</button>
                            <a th:href="@{/job-cards}" class="btn btn-light">Cancel</a>
                        </div>
                    </form>
                    <script th:inline="javascript">
                        window.ctp.jobCard = [[${jobCard}]];
                        window.ctp.types = [[${cutPieceTypes}]]
                        window.ctp.accounts = [[${accounts}]]
                    </script>
                    <script th:src="@{/js/vendor/compressor.min.js}"></script>
                    <script th:src="@{/js/job-card-form.js}"></script>
                </div>
            </main>
        </div>
        <div th:replace="_fragments :: page-footer-scripts"></div>
    </body>
</html>