<script setup>
import { reactive, computed } from 'vue';
import { useI18n } from 'vue-i18n';
import { useRoute, useRouter } from 'vue-router';

import FormModel from 'components/FormModel.vue';
import VnRow from 'components/ui/VnRow.vue';
import VnInput from 'src/components/common/VnInput.vue';
import VnInputDate from 'src/components/common/VnInputDate.vue';

const { t } = useI18n();
const route = useRoute();
const routeId = computed(() => route.params.id);
const router = useRouter();

const initialData = reactive({
    started: Date.vnNew(),
    clientFk: routeId.value,
});

const toCustomerCreditContracts = () => {
    router.push({ name: 'CustomerCreditContracts' });
};
</script>

<template>
    <FormModel
        :form-initial-data="initialData"
        :observe-form-changes="false"
        url-create="creditClassifications/createWithInsurance"
        @on-data-saved="toCustomerCreditContracts()"
    >
        <template #moreActions>
            <QBtn
                :label="t('globals.cancel')"
                @click="toCustomerCreditContracts"
                color="primary"
                flat
                icon="close"
            />
        </template>

        <template #form="{ data }">
            <VnRow>
                <div class="col">
                    <VnInput
                        :label="t('Credit')"
                        clearable
                        type="number"
                        v-model.number="data.credit"
                    />
                </div>
                <div class="col">
                    <VnInput
                        :label="t('Grade')"
                        clearable
                        type="number"
                        v-model.number="data.grade"
                    />
                </div>
                <div class="col">
                    <VnInputDate :label="t('Since')" v-model="data.started" />
                </div>
            </VnRow>
        </template>
    </FormModel>
</template>

<i18n>
es:
    Credit: Crédito
    Grade: Grade
    Since: Desde
</i18n>
