<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>
                <div class="col">
                    <VnSelect
                        :label="t('warehouses.warehouse')"
                        v-model="ZoneWarehouseFormData.warehouseFk"
                        :options="warehousesOptions"
                        option-value="id"
                        option-label="name"
                        hide-selected
                        :required="true"
                    />
                </div>
            </VnRow>
        </template>
    </FormPopup>
</template>
