<script setup>
import { ref } from 'vue';
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';

const route = useRoute();
const { t } = useI18n();

const workersOptions = ref([]);
</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('supplier.basicData.alias')"
                    :rules="validate('supplier.nickname')"
                    clearable
                />
                <VnSelect
                    :label="t('supplier.basicData.workerFk')"
                    v-model="data.workerFk"
                    :options="workersOptions"
                    option-value="id"
                    option-label="name"
                    hide-selected
                    map-options
                    url="Workers/search"
                    sort-by="nickname ASC"
                    :rules="validate('supplier.workerFk')"
                >
                    <template #append>
                        <QIcon name="info" class="cursor-pointer">
                            <QTooltip>{{
                                t('Responsible for approving invoices')
                            }}</QTooltip>
                        </QIcon>
                    </template>
                    <template #option="scope">
                        <QItem v-bind="scope.itemProps">
                            <QItemSection>
                                <QItemLabel>{{ scope.opt?.name }}</QItemLabel>
                                <QItemLabel caption>
                                    {{ scope.opt?.nickname }}, {{ scope.opt?.id }}
                                </QItemLabel>
                            </QItemSection>
                        </QItem>
                    </template>
                </VnSelect>
            </VnRow>
            <VnRow>
                <QCheckbox
                    v-model="data.isSerious"
                    :label="t('supplier.basicData.isSerious')"
                />
                <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:
    Responsible for approving invoices: Responsable de aprobar las facturas
</i18n>
