<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 VnSelect from 'src/components/common/VnSelect.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>
                <VnInput v-model="data.ref" :label="t('travel.basicData.reference')" />
                <VnSelect
                    :label="t('travel.basicData.agency')"
                    v-model="data.agencyModeFk"
                    :options="agenciesOptions"
                    option-value="id"
                    option-label="name"
                    map-options
                    hide-selected
                />
            </VnRow>
            <VnRow>
                <VnInputDate
                    v-model="data.shipped"
                    :label="t('travel.basicData.shipped')"
                />
                <VnInputDate
                    v-model="data.landed"
                    :label="t('travel.basicData.landed')"
                />
            </VnRow>
            <VnRow>
                <VnSelect
                    :label="t('travel.basicData.warehouseOut')"
                    v-model="data.warehouseOutFk"
                    :options="agenciesOptions"
                    option-value="id"
                    option-label="name"
                    map-options
                    hide-selected
                />
                <VnSelect
                    :label="t('travel.basicData.warehouseIn')"
                    v-model="data.warehouseInFk"
                    :options="agenciesOptions"
                    option-value="id"
                    option-label="name"
                    map-options
                    hide-selected
                />
            </VnRow>
            <VnRow>
                <VnInput v-model="data.m3" label="m3" />
            </VnRow>
            <VnRow>
                <QCheckbox
                    :label="t('travel.basicData.delivered')"
                    v-model="data.isDelivered"
                />
                <QCheckbox
                    :label="t('travel.basicData.received')"
                    v-model="data.isReceived"
                />
            </VnRow>
        </template>
    </FormModel>
</template>
