<script setup>
import { ref } from 'vue';
import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';

import FetchData from 'components/FetchData.vue';
import FormModel from 'components/FormModel.vue';
import VnRow from 'components/ui/VnRow.vue';
import VnInput from 'src/components/common/VnInput.vue';
import VnSelectFilter from 'src/components/common/VnSelectFilter.vue';
import VnInputDate from 'components/common/VnInputDate.vue';

const route = useRoute();
const { t } = useI18n();

const agenciesOptions = ref([]);
</script>
<template>
    <FetchData
        url="AgencyModes"
        @on-fetch="(data) => (agenciesOptions = data)"
        auto-load
    />
    <FormModel
        :url="`Travels/${route.params.id}`"
        :url-update="`Travels/${route.params.id}`"
        model="travel"
        auto-load
    >
        <template #form="{ data }">
            <VnRow class="row q-gutter-md q-mb-md">
                <div class="col">
                    <VnInput
                        v-model="data.ref"
                        :label="t('travel.basicData.reference')"
                    />
                </div>
                <div class="col">
                    <VnSelectFilter
                        :label="t('travel.basicData.agency')"
                        v-model="data.agencyModeFk"
                        :options="agenciesOptions"
                        option-value="id"
                        option-label="name"
                        map-options
                        hide-selected
                    />
                </div>
            </VnRow>
            <VnRow class="row q-gutter-md q-mb-md">
                <div class="col">
                    <VnInputDate
                        v-model="data.shipped"
                        :label="t('travel.basicData.shipped')"
                    />
                </div>
                <div class="col">
                    <VnInputDate
                        v-model="data.landed"
                        :label="t('travel.basicData.landed')"
                    />
                </div>
            </VnRow>
            <VnRow class="row q-gutter-md q-mb-md">
                <div class="col">
                    <VnSelectFilter
                        :label="t('travel.basicData.warehouseOut')"
                        v-model="data.warehouseOutFk"
                        :options="agenciesOptions"
                        option-value="id"
                        option-label="name"
                        map-options
                        hide-selected
                    />
                </div>
                <div class="col">
                    <VnSelectFilter
                        :label="t('travel.basicData.warehouseIn')"
                        v-model="data.warehouseInFk"
                        :options="agenciesOptions"
                        option-value="id"
                        option-label="name"
                        map-options
                        hide-selected
                    />
                </div>
            </VnRow>
            <VnRow class="row q-gutter-md q-mb-md">
                <div class="col">
                    <QCheckbox
                        :label="t('travel.basicData.delivered')"
                        v-model="data.isDelivered"
                    />
                </div>
                <div class="col">
                    <QCheckbox
                        :label="t('travel.basicData.received')"
                        v-model="data.isReceived"
                    />
                </div>
            </VnRow>
        </template>
    </FormModel>
</template>
