<template>
    <div class="row p-t-25 text-left">
        <div class="col">
            <div class="row">
                <div class="col">
                    <div class="b-l b-success p-l-15 m-b-15" style="border-left-width: 3px;">
                        <h6 class="bold all-caps no-margin text-success">New Address</h6>
                        <div class="muted all-caps fs-12">Create A New Delivery Address</div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col">
                    <validation-wrapper-component :validator="$v.parameters.street_one">
                        <label class="muted">Address Line 1</label>
                        <input class="form-control" name="street_one" v-model="parameters.street_one">
                    </validation-wrapper-component>
                    <validation-wrapper-component :validator="$v.parameters.street_two">
                        <label class="muted">Address Line 2</label>
                        <input class="form-control" name="street_two" v-model="parameters.street_two">
                    </validation-wrapper-component>
                    <div class="row">
                        <div class="col p-r-5">
                            <validation-wrapper-component :validator="$v.parameters.city">
                                <label class="muted">City</label>
                                <input class="form-control" name="city" v-model="parameters.city">
                            </validation-wrapper-component>
                        </div>
                        <div class="col p-l-5">
                            <validation-wrapper-component :validator="$v.parameters.state">
                                <label class="muted">State</label>
                                <input class="form-control" name="State" v-model="parameters.state">
                            </validation-wrapper-component>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col p-r-5">
                            <validation-wrapper-component :validator="$v.parameters.post_code">
                                <label class="muted">Post Code</label>
                                <input class="form-control" name="post_code" v-model="parameters.post_code">
                            </validation-wrapper-component>
                        </div>
                        <div class="col p-l-5">
                            <validation-wrapper-component :validator="$v.parameters.country">
                                <label class="muted">Country</label>
                                <input class="form-control" name="country" v-model="parameters.country">
                            </validation-wrapper-component>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row mb-3">
                <div class="col">
                    <div class="row">
                        <div class="col text-right">
                            <button type="button" class="btn btn-outline-dark float-left" @click="closeModal()">Cancel</button>
                            <button type="button" class="btn btn-success" @click="submitForm()">Submit</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
    import { required } from "vuelidate/lib/validators";
    export default {
        props: {
            id: {
                type: Number,
                required: true
            }
        },
        watch: {
            'id': function() {
                this.parameters.company_id = this.id;
            }
        },
        data() {
			return {
                parameters : {
                    company_id: this.id,
                    street_one: '',
                    street_two: '',
                    city: '',
                    state: '',
                    post_code: '',
                    country: ''
				}

			}
		},
        validations: {
            parameters: {
                street_one: { required },
                street_two: {},
                city: { required },
                state: { required },
                post_code: { required },
                country: { required }
            }
        },
        methods:{
            submitForm(){
                this.submit((this.route('api.address.create')), 'post', 'address.form', true, true)
            },
            successHandler(){
                this.crudSuccess();
                EventBus.$emit('updateAddress')
            }
        }
    }
</script>
