<script setup lang="ts">
import { computed, reactive, ref, shallowRef } from 'vue';
import dayjs from 'dayjs';

import UseGuidance from '@/layout/UseGuidance.vue';
import CreateAccount from '@/views/create-customer/CreateAccount.vue';
import CreateCharacter from '@/views/create-customer/CreateCharacter.vue';
import EstablishOrganization from '@/views/create-customer/EstablishOrganization.vue';
import { t } from '@/i18n';

import type { CreateCustomer, FormRules, RegisterGatewayForm, UseGuideStepItem } from '@/types';

const useForm = reactive<CreateCustomer>({
  orgName: '',
  logo: '',
  themeColor: '#32bac0',
  id: undefined,
  imageUrl: '',
  selectedColor: '#e2550d',
  leaseTerm: [dayjs(), dayjs()],
  stationsNumber: 0,
  dataValidityPeriod: '',
});

const rules = computed<FormRules<RegisterGatewayForm>>(() => {
  return {
    orgName: [
      {
        required: true,
        message: t('common.cannotEmpty'),
        trigger: 'change',
      },
    ],
    leaseTerm: [
      {
        required: true,
        message: t('common.cannotEmpty'),
        trigger: 'change',
      },
    ],
    stationsNumber: [
      {
        required: true,
        message: t('common.cannotEmpty'),
        trigger: 'change',
      },
    ],
    dataValidityPeriod: [
      {
        required: true,
        message: t('common.cannotEmpty'),
        trigger: 'change',
      },
    ],
  };
});

const steps = ref<UseGuideStepItem[]>([
  {
    title: t('createCustomer.establishOrganization'),
    component: shallowRef(EstablishOrganization),
    stepDescription: t('organizationManage.custom'),
    labelAlign: 'left',
    labelCol: { span: 2 },
  },
  {
    title: t('createCustomer.createCharacter'),
    component: shallowRef(CreateCharacter),
    stepDescription: t('roleManage.customRole'),
  },
  {
    title: t('createCustomer.createAccount'),
    component: shallowRef(CreateAccount),
    stepDescription: '创建账号，并为账号选择角色类型',
    nextStepButtonText: t('common.finishSetup'),
    isLastStep: true,
  },
]);
</script>

<template>
  <UseGuidance :title="$t('createCustomer.createCustomer')" :steps="steps" :form="useForm" :rules="rules" />
</template>
