<template>
    <div class="row" @keyup.enter="submitForm">
        <div class="col">
            <div class="row m-b-20 text-info">
                <div class="col">
                    <h3 class="text-left">Create Warehouse Packing List</h3>
                </div>
            </div>
            <error-message-component class="m-b-20" :error="error"></error-message-component>
            <div class="row m-b-25">
                <div class="col p-r-5">
                    <validation-wrapper-component :validator="$v.parameters.receive_date">
                        <label class="text-primary">Receive Date</label>
                        <date-picker-component v-model="parameters.receive_date"></date-picker-component>
                    </validation-wrapper-component>
                </div>
                <div class="col p-l-5">
                    <validation-wrapper-component :validator="$v.parameters.tracking">
                        <label class="text-primary">Tracking</label>
                        <input type="text" class="form-control fs-12" v-model.trim="parameters.tracking">
                    </validation-wrapper-component>
                </div>
            </div>
            <div class="row">
                <div class="col">
                    <package-form-component :section="section" :packages="parameters.packages"></package-form-component>
                </div>
            </div>
            <div class="row m-t-15 align-items-center justify-content-center" v-if="parameters.packages.length > 0">
                <div class="col">
                    <div class="btn btn-block btn-lg btn-primary b-rad-none no-border" @click="submitForm">Submit</div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
    import createPackageListFormValidation from '../../../general/mixins/orders/validation/createPackageListFormValidation';
    import componentHandler from '../../../general/mixins/componentHandler';
    import modalFormHandler from '../../../general/mixins/modalFormHandler';

    export default {
        props: {
            id: {
                type: Number,
                required: true
            },
            section:{
                type: String,
                required: true
            }
        },
        data() {
            return {
                error: '',
                parameters: {
                    order_id: this.id,
                    tracking: this.tracking,
                    receive_date: this.receive_date,
                    packages: []
                }
            };
        },
        watch: {
            'id': function () {
                this.parameters.order_id = this.id;
            }
        },
        methods: {
            submitForm(){
                this.submit(this.route('api.order.create.warehouse.packing_list'), 'post', this.section, true, true)
            }
        },
        mixins: [createPackageListFormValidation, componentHandler, modalFormHandler]
    }

</script>