<script setup>
import { reactive, ref } from 'vue';
import { useI18n } from 'vue-i18n';

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

const emit = defineEmits(['onSubmitCreateWarehouse']);
const { t } = useI18n();

const ZoneWarehouseFormData = reactive({
    warehouseFk: null,
});

const warehousesOptions = ref([]);
</script>

<template>
    <FetchData
        url="Warehouses"
        :filter="{ order: 'name' }"
        auto-load
        @on-fetch="(data) => (warehousesOptions = data)"
    />
    <FormPopup
        model="ZoneWarehouse"
        @on-submit="emit('onSubmitCreateWarehouse', ZoneWarehouseFormData)"
    >
        <template #form-inputs>
            <VnRow>
                <VnSelect
                    :label="t('list.warehouse')"
                    v-model="ZoneWarehouseFormData.warehouseFk"
                    :options="warehousesOptions"
                    option-value="id"
                    option-label="name"
                    hide-selected
                    :required="true"
                />
            </VnRow>
        </template>
    </FormPopup>
</template>
