<template>
    <section v-if="!addBool" :class="['accounting-information', darkMode ? 'section-darkmode' : 'section-lightmode']">
        <div :class="['label', darkMode ? 'label-darkmode' : 'label-lightmode']" id="accounting">Accounting:
            <div class="asset-data">
                <table class="data-table" id="asset-table-no-client">
                    <tbody>
                        <tr :class="['table-row', darkMode ? 'tr-head-darkmode' : 'tr-head-lightmode']" id="table-head">
                            <th
                                :class="['Action', darkMode ? 'th-darkmode' : 'th-lightmode', darkMode ? 'Action-darkmode' : 'Action-lightmode']">
                                Action</th>
                            <th
                                :class="['Date', darkMode ? 'th-darkmode' : 'th-lightmode', darkMode ? 'Date-darkmode' : 'Date-lightmode']">
                                Date</th>
                            <th :class="['Comments', darkMode ? 'th-darkmode' : 'th-lightmode']">Comments</th>
                        </tr>
                        <tr :class="['table-row', darkMode ? 'first-tr-darkmode' : 'first-tr-lightmode']" id="row-1">
                            <td
                                :class="['Action', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Action-darkmode' : 'Action-lightmode']">
                                Supplier request</td>
                            <td v-if="!editable"
                                :class="['Date', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Date-darkmode' : 'Date-lightmode']">
                                {{
        issueSlip.supplierRequestDate }}</td>
                            <td v-if="editable"
                                :class="['Date', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Date-darkmode' : 'Date-lightmode']">
                                <input type="text" v-model="issueSlip.supplierRequestDate" @change="updateIssueSlip()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                            <td v-if="!editable" :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']">{{
        issueSlip.supplierRequest }}</td>
                            <td v-if="editable" :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']">
                                <input type="text" v-model="issueSlip.supplierRequest" @change="updateIssueSlip()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                        </tr>
                        <tr :class="['table-row', darkMode ? 'tr-darkmode' : 'tr-lightmode']" id="row-1">
                            <td
                                :class="['Action', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Action-darkmode' : 'Action-lightmode']">
                                Supplier offer</td>
                            <td v-if="!editable"
                                :class="['Date', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Date-darkmode' : 'Date-lightmode']">
                                {{
        issueSlip.supplierOfferDate }}</td>
                            <td v-if="editable"
                                :class="['Date', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Date-darkmode' : 'Date-lightmode']">
                                <input type="text" v-model="issueSlip.supplierOfferDate" @change="updateIssueSlip()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                            <td v-if="!editable" :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']">{{
        issueSlip.supplierOffer }}</td>
                            <td v-if="editable" :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']">
                                <input type="text" v-model="issueSlip.supplierOffer" @change="updateIssueSlip()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                        </tr>
                        <tr :class="['table-row', darkMode ? 'tr-darkmode' : 'tr-lightmode']" id="row-1">
                            <td
                                :class="['Action', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Action-darkmode' : 'Action-lightmode']">
                                Customer offer</td>
                            <td v-if="!editable"
                                :class="['Date', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Date-darkmode' : 'Date-lightmode']">
                                {{
        issueSlip.clientOfferDate }}</td>
                            <td v-if="editable"
                                :class="['Date', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Date-darkmode' : 'Date-lightmode']">
                                <input type="text" v-model="issueSlip.clientOfferDate" @change="updateIssueSlip()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                            <td v-if="!editable" :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']">{{
        issueSlip.clientOffer }}</td>
                            <td v-if="editable" :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']">
                                <input type="text" v-model="issueSlip.clientOffer" @change="updateIssueSlip()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                        </tr>
                        <tr :class="['table-row', darkMode ? 'tr-darkmode' : 'tr-lightmode']" id="row-1">
                            <td
                                :class="['Action', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Action-darkmode' : 'Action-lightmode']">
                                Customer order</td>
                            <td v-if="!editable"
                                :class="['Date', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Date-darkmode' : 'Date-lightmode']">
                                {{
        issueSlip.clientOrderDate }}</td>
                            <td v-if="editable"
                                :class="['Date', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Date-darkmode' : 'Date-lightmode']">
                                <input type="text" v-model="issueSlip.clientOrderDate" @change="updateIssueSlip()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                            <td v-if="!editable" :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']">{{
        issueSlip.clientOrder }}</td>
                            <td v-if="editable" :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']">
                                <input type="text" v-model="issueSlip.clientOrder" @change="updateIssueSlip()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                        </tr>
                        <tr :class="['table-row', darkMode ? 'tr-darkmode' : 'tr-lightmode']" id="row-1">
                            <td
                                :class="['Action', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Action-darkmode' : 'Action-lightmode']">
                                Supplier order</td>
                            <td v-if="!editable"
                                :class="['Date', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Date-darkmode' : 'Date-lightmode']">
                                {{
        issueSlip.supplierOrderDate }}</td>
                            <td v-if="editable"
                                :class="['Date', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Date-darkmode' : 'Date-lightmode']">
                                <input type="text" v-model="issueSlip.supplierOrderDate" @change="updateIssueSlip()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                            <td v-if="!editable" :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']">{{
        issueSlip.supplierOrder }}</td>
                            <td v-if="editable" :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']">
                                <input type="text" v-model="issueSlip.supplierOrder" @change="updateIssueSlip()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                        </tr>
                        <tr :class="['table-row', darkMode ? 'tr-darkmode' : 'tr-lightmode']" id="row-1">
                            <td
                                :class="['Action', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Action-darkmode' : 'Action-lightmode']">
                                Ingress</td>
                            <td v-if="!editable"
                                :class="['Date', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Date-darkmode' : 'Date-lightmode']">
                                {{
        issueSlip.ingressDate }}</td>
                            <td v-if="editable"
                                :class="['Date', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Date-darkmode' : 'Date-lightmode']">
                                <input type="text" v-model="issueSlip.ingressDate" @change="updateIssueSlip()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                            <td v-if="!editable" :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']">{{
        issueSlip.ingress }}</td>
                            <td v-if="editable" :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']">
                                <input type="text" v-model="issueSlip.ingress" @change="updateIssueSlip()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                        </tr>
                        <tr :class="['table-row', darkMode ? 'tr-darkmode' : 'tr-lightmode']" id="row-1">
                            <td
                                :class="['Action', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Action-darkmode' : 'Action-lightmode']">
                                Egress</td>
                            <td v-if="!editable"
                                :class="['Date', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Date-darkmode' : 'Date-lightmode']">
                                {{
        issueSlip.egressDate }}</td>
                            <td v-if="editable"
                                :class="['Date', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Date-darkmode' : 'Date-lightmode']">
                                <input type="text" v-model="issueSlip.egressDate" @change="updateIssueSlip()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                            <td v-if="!editable" :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']">{{
        issueSlip.egress }}</td>
                            <td v-if="editable" :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']">
                                <input type="text" v-model="issueSlip.egress" @change="updateIssueSlip()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                        </tr>
                        <tr :class="['table-row', darkMode ? 'final-tr-darkmode' : 'final-tr-lightmode']" id="row-2">
                            <td
                                :class="['Action', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Action-darkmode' : 'Action-lightmode']">
                                Ingress bill</td>
                            <td v-if="!editable"
                                :class="['Date', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Date-darkmode' : 'Date-lightmode']">
                                {{
        issueSlip.ingressBillDate }}</td>
                            <td v-if="editable"
                                :class="['Date', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Date-darkmode' : 'Date-lightmode']">
                                <input type="text" v-model="issueSlip.ingressBillDate" @change="updateIssueSlip()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                            <td v-if="!editable" :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']">{{
        issueSlip.ingressBill }}</td>
                            <td v-if="editable" :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']">
                                <input type="text" v-model="issueSlip.ingressBill" @change="updateIssueSlip()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                        </tr>
                        <tr :class="['table-row', darkMode ? 'final-tr-darkmode' : 'final-tr-lightmode']" id="row-1">
                            <td
                                :class="['Action', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Action-darkmode' : 'Action-lightmode']">
                                Egress bill</td>
                            <td v-if="!editable"
                                :class="['Date', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Date-darkmode' : 'Date-lightmode']">
                                {{
        issueSlip.egressBillDate }}</td>
                            <td v-if="editable"
                                :class="['Date', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Date-darkmode' : 'Date-lightmode']">
                                <input type="text" v-model="issueSlip.egressBillDate" @change="updateIssueSlip()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                            <td v-if="!editable" :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']">{{
        issueSlip.egressBill }}</td>
                            <td v-if="editable" :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']">
                                <input type="text" v-model="issueSlip.egressBill" @change="updateIssueSlip()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </section>
    <section v-if="addBool" :class="['accounting-information', darkMode ? 'section-darkmode' : 'section-lightmode']">
        <div :class="['label', darkMode ? 'label-darkmode' : 'label-lightmode']" id="accounting">Accounting:
            <div class="asset-data">
                <table class="data-table" id="asset-table-no-client">
                    <tbody>
                        <tr :class="['table-row', darkMode ? 'tr-head-darkmode' : 'tr-head-lightmode']" id="table-head">
                            <th
                                :class="['Action', darkMode ? 'th-darkmode' : 'th-lightmode', darkMode ? 'Action-darkmode' : 'Action-lightmode']">
                                Action</th>
                            <th
                                :class="['Date', darkMode ? 'th-darkmode' : 'th-lightmode', darkMode ? 'Date-darkmode' : 'Date-lightmode']">
                                Date</th>
                            <th :class="['Comments', darkMode ? 'th-darkmode' : 'th-lightmode']">Comments</th>
                        </tr>
                        <tr :class="['table-row', darkMode ? 'first-tr-darkmode' : 'first-tr-lightmode']" id="row-1">
                            <td
                                :class="['Action', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Action-darkmode' : 'Action-lightmode']">
                                Supplier request</td>
                            <td
                                :class="['Date', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Date-darkmode' : 'Date-lightmode']">
                                <input type="text" v-model="newSupplierRequestDate" @change="updateIS()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                            <td :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']">
                                <input type="text" v-model="newSupplierRequest" @change="updateIS()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                        </tr>
                        <tr :class="['table-row', darkMode ? 'tr-darkmode' : 'tr-lightmode']" id="row-1">
                            <td
                                :class="['Action', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Action-darkmode' : 'Action-lightmode']">
                                Supplier offer</td>
                            <td
                                :class="['Date', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Date-darkmode' : 'Date-lightmode']">
                                <input type="text" v-model="newSupplierOfferDate" @change="updateIS()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                            <td :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']">
                                <input type="text" v-model="newSupplierOffer" @change="updateIS()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                        </tr>
                        <tr :class="['table-row', darkMode ? 'tr-darkmode' : 'tr-lightmode']" id="row-1">
                            <td
                                :class="['Action', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Action-darkmode' : 'Action-lightmode']">
                                Customer offer</td>
                            <td
                                :class="['Date', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Date-darkmode' : 'Date-lightmode']">
                                <input type="text" v-model="newClientOfferDate" @change="updateIS()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                            <td :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']">
                                <input type="text" v-model="newClientOffer" @change="updateIS()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                        </tr>
                        <tr :class="['table-row', darkMode ? 'tr-darkmode' : 'tr-lightmode']" id="row-1">
                            <td
                                :class="['Action', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Action-darkmode' : 'Action-lightmode']">
                                Customer order</td>
                            <td
                                :class="['Date', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Date-darkmode' : 'Date-lightmode']">
                                <input type="text" v-model="newClientOrderDate" @change="updateIS()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                            <td :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']">
                                <input type="text" v-model="newClientOrder" @change="updateIS()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                        </tr>
                        <tr :class="['table-row', darkMode ? 'tr-darkmode' : 'tr-lightmode']" id="row-1">
                            <td
                                :class="['Action', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Action-darkmode' : 'Action-lightmode']">
                                Supplier order</td>
                            <td
                                :class="['Date', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Date-darkmode' : 'Date-lightmode']">
                                <input type="text" v-model="newSupplierOrderDate" @change="updateIS()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                            <td :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']">
                                <input type="text" v-model="newSupplierOrder" @change="updateIS()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                        </tr>
                        <tr :class="['table-row', darkMode ? 'tr-darkmode' : 'tr-lightmode']" id="row-1">
                            <td
                                :class="['Action', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Action-darkmode' : 'Action-lightmode']">
                                Ingress</td>
                            <td
                                :class="['Date', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Date-darkmode' : 'Date-lightmode']">
                                <input type="text" v-model="newIngressDate" @change="updateIS()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                            <td :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']">
                                <input type="text" v-model="newIngress" @change="updateIS()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                        </tr>
                        <tr :class="['table-row', darkMode ? 'tr-darkmode' : 'tr-lightmode']" id="row-1">
                            <td
                                :class="['Action', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Action-darkmode' : 'Action-lightmode']">
                                Egress</td>
                            <td
                                :class="['Date', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Date-darkmode' : 'Date-lightmode']">
                                <input type="text" v-model="newEgressDate" @change="updateIS()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                            <td :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']">
                                <input type="text" v-model="newEgress" @change="updateIS()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                        </tr>
                        <tr :class="['table-row', darkMode ? 'final-tr-darkmode' : 'final-tr-lightmode']" id="row-2">
                            <td
                                :class="['Action', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Action-darkmode' : 'Action-lightmode']">
                                Ingress bill</td>
                            <td
                                :class="['Date', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Date-darkmode' : 'Date-lightmode']">
                                <input type="text" v-model="newIngressBillDate" @change="updateIS()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                            <td :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']">
                                <input type="text" v-model="newIngressBill" @change="updateIS()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                        </tr>
                        <tr :class="['table-row', darkMode ? 'final-tr-darkmode' : 'final-tr-lightmode']" id="row-1">
                            <td
                                :class="['Action', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Action-darkmode' : 'Action-lightmode']">
                                Egress bill</td>
                            <td
                                :class="['Date', darkMode ? 'td-darkmode' : 'td-lightmode', darkMode ? 'Date-darkmode' : 'Date-lightmode']">
                                <input type="text" v-model="newEgressBillDate" @change="updateIS()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                            <td :class="['Comments', darkMode ? 'td-darkmode' : 'td-lightmode']">
                                <input type="text" v-model="newEgressBill" @change="updateIS()"
                                    :class="['data', 'input', darkMode ? 'data-darkmode' : 'data-lightmode']">
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </section>
    <section v-if="addBool" id="saveNewItem">
        <button :class="[darkMode ? 'saveNewItem-darkmode' : 'saveNewItem-lightmode']"
            @click="addIssueSlip()">Save</button>
    </section>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import Axios from '../axios.config.js';
import clientsideConfig from '../../clientsideConfig.js';
import { useStore } from 'vuex';
import { computed } from 'vue';

const store = useStore();
const editable = computed(() => store.state.editable);
const chosenIssueSlipId = computed(() => store.state.chosenIssueSlipId);
const addBool = computed(() => store.state.new);
const newTicketNoIS = computed(() => store.state.newTicketNoIS);
const newCustomerIdIS = computed(() => store.state.newCustomerIdIS);
const newCustomerIS = computed(() => store.state.newCustomerIS);
const newNotesIS = computed(() => store.state.newNotesIS);
const newUserIS = computed(() => store.state.newUserIS);
const newDeliveryAddressIS = computed(() => store.state.newDeliveryAddressIS);
const newAddRowOI = computed(() => store.state.newAddRowOI);
const newOIs = computed(() => store.state.newOIs);

const newClientOffer = ref('');
const newClientOrder = ref('');
const newSupplierOffer = ref('');
const newSupplierOrder = ref('');
const newSupplierRequest = ref('');
const newIngress = ref('');
const newIngressBill = ref('');
const newEgress = ref('');
const newEgressBill = ref('');
const newClientOfferDate = ref('');
const newClientOrderDate = ref('');
const newSupplierOfferDate = ref('');
const newSupplierOrderDate = ref('');
const newSupplierRequestDate = ref('');
const newIngressDate = ref('');
const newIngressBillDate = ref('');
const newEgressDate = ref('');
const newEgressBillDate = ref('');

const darkMode = ref(true)
const issueSlip = ref({});

// get issue slip from id
const getIssueSlipById = async () => {
    try {
        const response = await Axios.get(
            `https://${clientsideConfig.url}:${clientsideConfig.port}/api/getIssueSlip/${chosenIssueSlipId.value}`
        );
        issueSlip.value = response.data;
    } catch (err) {
        console.log(err.response.statusText);
    }
}

// update accounting fields in the store
const updateIS = () => {
    const is = {
        supplierRequestDate: newSupplierRequestDate.value,
        supplierRequest: newSupplierRequest.value,
        supplierOfferDate: newSupplierOfferDate.value,
        supplierOffer: newSupplierOffer.value,
        clientOfferDate: newClientOfferDate.value,
        clientOffer: newClientOffer.value,
        clientOrderDate: newClientOrderDate.value,
        clientOrder: newClientOrder.value,
        supplierOrderDate: newSupplierOrderDate.value,
        supplierOrder: newSupplierOrder.value,
        ingressDate: newIngressDate.value,
        ingress: newIngress.value,
        egressDate: newEgressDate.value,
        egress: newEgress.value,
        ingressBillDate: newIngressBillDate.value,
        ingressBill: newIngressBill.value,
        egressBillDate: newEgressBillDate.value,
        egressBill: newEgressBill.value,
    };
    store.commit('updateAccountingComponent', is);
}

//update data
const updateIssueSlip = async () => {
    try {
        await Axios.put(
            `https://${clientsideConfig.url}:${clientsideConfig.port}/api/updateIssueSlip`,
            {
                primaryID: issueSlip.value.primaryID,
                customerID: issueSlip.value.customerID,
                customer: issueSlip.value.customer,
                ticketNo: issueSlip.value.ticketNo,
                creationDate: issueSlip.value.creationDate,
                lastView: issueSlip.value.lastView,
                user: issueSlip.value.user,
                notes: issueSlip.value.notes,
                deliveryAddress: issueSlip.value.deliveryAddress,
                supplierRequestDate: issueSlip.value.supplierRequestDate,
                supplierRequest: issueSlip.value.supplierRequest,
                supplierOfferDate: issueSlip.value.supplierOfferDate,
                supplierOffer: issueSlip.value.supplierOffer,
                clientOfferDate: issueSlip.value.clientOfferDate,
                clientOffer: issueSlip.value.clientOffer,
                clientOrderDate: issueSlip.value.clientOrderDate,
                clientOrder: issueSlip.value.clientOrder,
                supplierOrder: issueSlip.value.supplierOrder,
                supplierOrderDate: issueSlip.value.supplierOrderDate,
                ingressDate: issueSlip.value.ingressDate,
                ingress: issueSlip.value.ingress,
                egressDate: issueSlip.value.egressDate,
                egress: issueSlip.value.egress,
                ingressBillDate: issueSlip.value.ingressBillDate,
                ingressBill: issueSlip.value.ingressBill,
                egressBillDate: issueSlip.value.egressBillDate,
                egressBill: issueSlip.value.egressBill,
            }
        )
        await getIssueSlipById();
    } catch (err) {
        console.log(err.response.statusText);
    }
}

// add new issue slip
const addIssueSlip = async () => {
    if (newTicketNoIS.value.length === 0) {
        alert("Please add a ticket number!");
        return;
    }
    if (newCustomerIS.value.length === 0) {
        alert("Please choose a customer!");
        return;
    }
    // get the time and date
    const today = new Date();
    const date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
    const time = today.getHours() + ":" + today.getMinutes();
    const dateTime = date + ' ' + time;
    let allFine = true;
    newOIs.value.forEach(oi => {
        if (oi.article.length === 0 && oi.amount.length === 0 && oi.price.length === 0 && oi.comment.length === 0) {
            alert(`Please add data for all ordering info.`);
            allFine = false
        }
    })
    if (!allFine) {
        return
    }
    try {
        const response = await Axios.post(`https://${clientsideConfig.url}:${clientsideConfig.port}/api/addIssueSlip`,
            {
                customerID: newCustomerIdIS.value,
                customer: newCustomerIS.value,
                ticketNo: newTicketNoIS.value,
                creationDate: dateTime,
                lastView: '',
                user: newUserIS.value,
                notes: newNotesIS.value,
                deliveryAddress: newDeliveryAddressIS.value,
                supplierRequestDate: newSupplierRequestDate.value,
                supplierRequest: newSupplierRequest.value,
                supplierOfferDate: newSupplierOfferDate.value,
                supplierOffer: newSupplierOffer.value,
                clientOfferDate: newClientOfferDate.value,
                clientOffer: newClientOffer.value,
                clientOrderDate: newClientOrderDate.value,
                clientOrder: newClientOrder.value,
                supplierOrderDate: newClientOrderDate.value,
                supplierOrder: newSupplierOrder.value,
                ingressDate: newIngressDate.value,
                ingress: newIngress.value,
                egressDate: newEgressDate.value,
                egress: newEgress.value,
                ingressBillDate: newIngressBillDate.value,
                ingressBill: newIngressBill.value,
                egressBillDate: newEgressBillDate.value,
                egressBill: newEgressBill.value,
            });
        newOIs.value.forEach(async oi => {
            try {
                const res = await Axios.post(`https://${clientsideConfig.url}:${clientsideConfig.port}/api/addOrderingInfo`,
                    {
                        issueSlipID: response.data,
                        article: oi.article,
                        amount: oi.amount,
                        price: oi.price,
                        comment: oi.comment,
                    });
            } catch (err) {
                console.log(err);
            }
            store.commit('resetStore');
            store.commit('changeToIssueSliplist');
        })
    } catch (err) {
        console.log(err.response.statusText);
    }
}

onMounted(() => {
    getIssueSlipById();
});
</script>

<script>
export default {
    name: "Accounting",
};
</script>


<style scoped>
.accounting-information {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    width: 100%;
    padding: 1.25rem 1.875rem;
    border-radius: 0.625rem;
    box-shadow: 0.25rem 0.25rem 0.25rem 0rem rgba(0, 0, 0, 0.25);
}

.section-darkmode {
    background-color: #2c2c2c;
}

.section-lightmode {
    background-color: #fff;
}

.input {
    border: none;
}

.data-darkmode {
    background-color: #212121;
    color: #fff;
}

.data-lightmode {
    background-color: #EBEBEB;
    color: #000;
}

.data {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    padding: 0 0.625rem;
    border-radius: 0.3125rem;
    box-shadow: 0.0625rem 0.0625rem 0.25rem 0rem rgba(0, 0, 0, 0.25) inset;
    letter-spacing: 5%;
    font: 400 0.75rem/250% Overpass, sans-serif;
}

.label {
    letter-spacing: 5%;
    font: 400 1rem/1.875rem Overpass, sans-serif;
}

.label-darkmode {
    color: #FFFFFF;
}

.label-lightmode {
    color: #000;
}

.label#accounting {
    padding-top: 1rem;
    padding-bottom: 1rem;
}

.asset-data {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    align-self: stretch;
    padding-left: 0.625rem;
    padding-top: 1rem;
}

.data-table {
    width: 100%;
    padding: 0 0.625rem;
    table-layout: fixed;
    border-collapse: collapse;
}

.table-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    height: 3.125rem;
    padding: 0.625rem;
    gap: 0.625rem;
}

.tr-head-darkmode {
    border-top: none;
    border-bottom: 0.0625rem solid #000000;
}

.tr-head-lightmode {
    border-top: none;
    border-bottom: 0.0625rem solid #8e8e8e;
}

.first-tr-darkmode {
    border-top: 0.0625rem solid #000000;
}

.first-tr-lightmode {
    border-top: 0.0625rem solid #8e8e8e;
}

.final-tr-darkmode {
    background-color: #212121;
}

.final-tr-lightmode {
    background-color: #EBEBEB;
}

.saveNewItem-darkmode {
    background: #2c2c2c;
    color: #fff;
    font: 400 0.875rem/1.875rem Overpass, sans-serif;
    border: none;
    padding: 1rem 1.875rem;
    width: 8%;
    border-radius: 0.625rem;
    box-shadow: 0.25rem 0.25rem 0.25rem 0rem rgba(0, 0, 0, 0.25);
}

.saveNewItem-lightmode {
    background: #EBEBEB;
    color: #212121;
    font: 400 0.875rem/1.875rem Overpass, sans-serif;
    border: none;
    padding: 1rem 1.875rem;
    width: 8%;
    border-radius: 0.625rem;
    box-shadow: 0.25rem 0.25rem 0.25rem 0rem rgba(0, 0, 0, 0.25);
}

.saveNewItem-darkmode:hover {
    background-color: #444444;
    cursor: pointer;
}

.saveNewItem-lightmode:hover {
    background-color: #ACACAC;
    cursor: pointer;
}

#saveNewItem {
    text-align: center;
}

th,
td {
    height: 1.875rem;
    text-align: left;
    padding: 0;
    letter-spacing: 5%;
    font: 400 0.875rem/1.875rem Overpass, sans-serif;
}

.th-darkmode,
.td-darkmode {
    color: #ffffff;
}

.th-lightmode,
.td-lightmode {
    color: #000;
}

th {
    font: 700 0.875rem/1.875rem Overpass, sans-serif;
}

tr#row-2 {
    margin-bottom: 0.75rem;
}


.Action {
    width: 40%;
}

.Action-darkmode {
    border-right: 0.0625rem solid #000000;
}

.Action-lightmode {
    border-right: 0.0625rem solid #8e8e8e;
}

.Date {
    width: 20%;
}

.Date-darkmode {
    border-right: 0.0625rem solid #000000;
}

.Date-lightmode {
    border-right: 0.0625rem solid #8e8e8e;
}

.Comments {
    width: 40%;
}
</style>