<script setup>
import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';
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 VnSelectWorker from 'src/components/common/VnSelectWorker.vue';

const route = useRoute();
const { t } = useI18n();
const companySizes = [
    { id: 'small', name: t('globals.small'), size: '1-5' },
    { id: 'medium', name: t('globals.medium'), size: '6-50' },
    { id: 'big', name: t('globals.big'), size: '>50' },
];
</script>
<template>
    <FormModel
        :url="`Suppliers/${route.params.id}`"
        :url-update="`Suppliers/${route.params.id}`"
        model="supplier"
        auto-load
        :clear-store-on-unmount="false"
    >
        <template #form="{ data, validate }">
            <VnRow>
                <VnInput
                    v-model="data.nickname"
                    :label="t('globals.alias')"
                    :rules="validate('supplier.nickname')"
                    clearable
                />
                <VnSelectWorker
                    v-model="data.workerFk"
                    has-info="Responsible for approving invoices"
                    :rules="validate('supplier.workerFk')"
                />
                <VnSelect
                    :label="t('supplier.basicData.size')"
                    v-model="data.companySize"
                    :options="companySizes"
                    sort-by="nickname ASC"
                    :rules="validate('supplier.workerFk')"
                >
                    <template #option="scope">
                        <QItem v-bind="scope.itemProps">
                            <QItemSection>
                                <QItemLabel>{{ scope.opt?.name }}</QItemLabel>
                                <QItemLabel caption>
                                    {{ scope.opt?.size }}
                                </QItemLabel>
                            </QItemSection>
                        </QItem>
                    </template>
                </VnSelect>
            </VnRow>
            <VnRow>
                <QCheckbox
                    v-model="data.isReal"
                    :label="t('supplier.basicData.isReal')"
                />
                <QCheckbox
                    v-model="data.isActive"
                    :label="t('supplier.basicData.isActive')"
                />
                <QCheckbox
                    v-model="data.isPayMethodChecked"
                    :label="t('supplier.basicData.isPayMethodChecked')"
                />
            </VnRow>
            <VnRow>
                <QInput
                    :label="t('supplier.basicData.note')"
                    type="textarea"
                    v-model="data.note"
                    fill-input
                />
            </VnRow>
        </template>
    </FormModel>
</template>

<i18n>
es:
    Small(1-5), Medium(6-50), Big(> 50): Pequeño(1-5), Mediano(6-50), Grande(> 50)
</i18n>
