<script setup>
import { ref, computed } from 'vue';
import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';
import VnRow from 'components/ui/VnRow.vue';
import FetchData from 'src/components/FetchData.vue';
import VnInput from 'src/components/common/VnInput.vue';
import FormModel from 'components/FormModel.vue';
import VnSelect from 'src/components/common/VnSelect.vue';

const { t } = useI18n();
const route = useRoute();
const parkingId = computed(() => route.params?.id || null);
const sectors = ref([]);
const sectorFilter = { fields: ['id', 'description'] };

const filter = {
    fields: ['sectorFk', 'code', 'pickingOrder', 'row', 'column'],
    include: [{ relation: 'sector', scope: sectorFilter }],
};
</script>
<template>
    <FetchData
        url="Sectors"
        :filter="sectorFilter"
        sort-by="description"
        @on-fetch="(data) => (sectors = data)"
        auto-load
    />
    <FormModel :url="`Parkings/${parkingId}`" model="parking" :filter="filter" auto-load>
        <template #form="{ data }">
            <VnRow>
                <VnInput v-model="data.code" :label="t('globals.code')" />
                <VnInput v-model="data.pickingOrder" :label="t('parking.pickingOrder')" />
            </VnRow>
            <VnRow>
                <VnInput v-model="data.row" :label="t('parking.row')" />
                <VnInput v-model="data.column" :label="t('parking.column')" />
            </VnRow>
            <VnRow>
                <VnSelect
                    v-model="data.sectorFk"
                    option-value="id"
                    option-label="description"
                    :label="t('parking.sector')"
                    :options="sectors"
                    use-input
                    input-debounce="0"
                    :is-clearable="false"
                />
            </VnRow>
        </template>
    </FormModel>
</template>
