<script setup>
import { useI18n } from 'vue-i18n';
import FormModel from 'src/components/FormModel.vue';
import VnRow from 'components/ui/VnRow.vue';
import VnInput from 'src/components/common/VnInput.vue';
import VnInputTime from 'src/components/common/VnInputTime.vue';
import VnSelect from 'src/components/common/VnSelect.vue';

const { t } = useI18n();
</script>

<template>
    <FormModel :url="`Zones/${$route.params.id}`" auto-load model="zone">
        <template #form="{ data, validate }">
            <VnRow>
                <VnInput
                    data-cy="zone-basic-data-name"
                    :label="t('Name')"
                    clearable
                    v-model="data.name"
                />
            </VnRow>

            <VnRow>
                <VnSelect
                    v-model="data.agencyModeFk"
                    :rules="validate('zone.agencyModeFk')"
                    url="AgencyModes/isActive"
                    :fields="['id', 'name']"
                    :label="t('Agency')"
                    emit-value
                    map-options
                    use-input
                    hide-bottom-space
                    sort-by="name"
                />
                <VnInput
                    class="mw-10"
                    v-model="data.itemMaxSize"
                    :label="t('Max m³')"
                    clearable
                    type="number"
                    min="0"
                />
                <VnInput
                    class="mw-10"
                    v-model="data.m3Max"
                    :label="t('Maximum m³')"
                    clearable
                    type="number"
                    min="0"
                />

                <VnInput
                    class="mw-10"
                    v-model="data.itemMaxLength"
                    :label="t('Max length m³')"
                    clearable
                    type="number"
                    min="0"
                />
            </VnRow>

            <VnRow>
                <VnInput
                    v-model="data.travelingDays"
                    :label="t('Traveling days')"
                    clearable
                    type="number"
                    min="0"
                />
                <VnInputTime v-model="data.hour" :label="t('Closing')" />
            </VnRow>

            <VnRow>
                <VnInput
                    v-model="data.price"
                    :label="t('Price')"
                    type="number"
                    min="0"
                    required="true"
                    clearable
                />
                <VnInput
                    v-model="data.priceOptimum"
                    :label="t('Price optimum')"
                    type="number"
                    min="0"
                    required="true"
                    clearable
                />
            </VnRow>
            <VnRow>
                <VnInput
                    v-model="data.bonus"
                    :label="t('Bonus')"
                    type="number"
                    min="0"
                    clearable
                />
                <VnSelect
                    :label="t('Distribution point')"
                    v-model="data.addressFk"
                    option-value="id"
                    option-label="nickname"
                    url="Addresses"
                    :fields="['id', 'nickname']"
                    sort-by="id"
                    hide-selected
                    map-options
                    :rules="validate('data.addressFk')"
                />
            </VnRow>
            <VnRow>
                <VnInput
                    v-model="data.inflation"
                    :label="t('Inflation')"
                    type="number"
                    clearable
                />
                <QCheckbox
                    v-model="data.isVolumetric"
                    :label="t('Volumetric')"
                    :toggle-indeterminate="false"
                />
            </VnRow>
        </template>
    </FormModel>
</template>
<style lang="scss" scoped>
.mw-10 {
    max-width: 10vw;
}
</style>
<i18n>
es:
    Name: Nombre
    Agency: Agencia
    Max m³: Medida máxima
    Maximum m³: M³ maximo
    Traveling days: Dias de viaje
    Closing: Cierre
    Price: Precio
    Price optimum: Precio óptimo
    Bonus: Bonificación
    Inflation: Inflación
    Volumetric: Volumétrico
    Max length m³: Medida máxima tumbado
    Distribution point: Punto de distribución
</i18n>
