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

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

const { t } = useI18n();
const route = useRoute();
const routeId = route.params?.id || null;
const warehouses = ref([]);
</script>
<template>
    <FetchData
        url="warehouses"
        sort-by="name"
        @on-fetch="(data) => (warehouses = data)"
        auto-load
    />
    <FormModel :url="`Agencies/${routeId}`" model="agency" auto-load>
        <template #form="{ data }">
            <VnRow>
                <VnInput v-model="data.name" :label="t('globals.name')" />
            </VnRow>
            <VnRow>
                <VnSelect
                    v-model="data.warehouseFk"
                    option-value="id"
                    option-label="name"
                    :label="t('globals.warehouse')"
                    :options="warehouses"
                    use-input
                    input-debounce="0"
                    :is-clearable="false"
                />
            </VnRow>
            <VnRow>
                <QCheckbox :label="t('agency.isOwn')" v-model="data.isOwn" />
            </VnRow>
            <VnRow>
                <QCheckbox
                    :label="t('agency.isAnyVolumeAllowed')"
                    v-model="data.isAnyVolumeAllowed"
                />
            </VnRow>
        </template>
    </FormModel>
</template>
