<!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('Store Receive Inventory')"></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>
            <div class="mb-4 d-flex justify-content-between">
                <h3>Receive Rejected Items</h3>
            </div>
            <form th:action="'/ctp/store/store-items'" method="post" id="packagingApp" th:object="${wrapper}">
                <div class="bg-light p-3 mb-3">
                    <div class="form-row">
                        <div class="col-sm-3 form-group">
                            <search-item
                                    :is-segregated="false"
                                    url="/ctp/rest/finished-items/search-store"
                                    v-on:finished-item-select="onItemSelect">
                            </search-item>
                        </div>
                        <input type="hidden" name="rejectReason" v-model="reason">
                        <div class="col-sm-3 form-group">
                            <label>Store Account</label>
                            <select class="form-control" name="accountId" th:field="*{accountId}" required>
                                <option value="">PLease select</option>
                                <option th:each="account : ${accounts}"
                                        th:value="${account.id}"
                                        th:text="${account.title}"></option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="bg-light p-3 mb-3">
                    <h6 class="mb-3">Search Finished Items</h6>
                    <finish-item-table
                            v-bind:items="items"
                            v-on:remove-item="removeItem"
                    ></finish-item-table>
                </div>
                <div class="alert alert-danger" v-if="hasDuplicates()">Duplicate Item Selected</div>
                <button class="btn btn-primary mr-2" type="button" :disabled="hasDuplicates() || items.length === 0"
                        @click="submitWithRejectReason('Cut To Pack')">Cut To Pack
                </button>
                <button class="btn btn-danger mr-2" type="button" :disabled="hasDuplicates() || items.length === 0"
                        @click="submitWithRejectReason('Knitting')">Knitting
                </button>
                <button class="btn btn-danger mr-2" type="button" :disabled="hasDuplicates() || items.length === 0"
                        @click="submitWithRejectReason('Dying')">Dying
                </button>
                <a th:href="@{/store/receive-inventory}" class="btn btn-light">Cancel</a>
            </form>
            <script th:inline="javascript">
                window.ctp.accounts = [[${accounts}]];
            </script>
            <script th:src="@{/js/vendor/compressor.min.js}"></script>
            <script th:src="@{/js/packaging/packaging-item-form.js}"></script>
        </div>
    </main>
</div>
<div th:replace="_fragments :: page-footer-scripts"></div>
</body>
</html>