<script setup lang="ts">
import { ref } from 'vue';
import OperateModel from '@/components/advanced/operate-model.vue';
import { useFormRules } from '@/hooks/common/form';

defineOptions({
  name: 'ConfigOperateModel',
  inheritAttrs: false
});

defineProps<{ typeOptions: Api.SystemManage.DictInfo[] }>();

const { defaultRequiredRule } = useFormRules();

type Model = Omit<Api.SystemManage.Config, 'configId' | 'params'>;
type RuleKey = keyof Pick<Model, 'configName' | 'configKey' | 'configValue'>;

const model = ref<Model>({
  configName: '',
  configKey: '',
  configValue: '',
  configType: 'Y',
  remark: ''
});

const rules: Record<RuleKey, App.Global.FormRule> = {
  configName: defaultRequiredRule,
  configKey: defaultRequiredRule,
  configValue: defaultRequiredRule
};
</script>

<template>
  <OperateModel v-model:model="model" :rules="rules" title="参数" v-bind="$attrs">
    <template #formItem>
      <NFormItemGi span="24 m:12" label="参数名称" path="configName">
        <NInput v-model:value="model.configName" placeholder="请输入参数名称" />
      </NFormItemGi>
      <NFormItemGi span="24 m:12" label="参数键名" path="configKey">
        <NInput v-model:value="model.configKey" placeholder="请输入参数键名" />
      </NFormItemGi>
      <NFormItemGi span="24 m:12" label="参数键值" path="configValue">
        <NInput v-model:value="model.configValue" placeholder="请输入参数键值" />
      </NFormItemGi>
      <NFormItemGi span="24 m:12" label="系统内置" path="configType">
        <NRadioGroup v-model:value="model.configType">
          <NRadio
            v-for="item in typeOptions"
            :key="item.dictValue"
            :value="item.dictValue"
            :label="item.dictLabel"
          ></NRadio>
        </NRadioGroup>
      </NFormItemGi>
      <NFormItemGi span="24" label="备注" path="remark">
        <NInput v-model:value="model.remark" type="textarea" placeholder="请输入备注" />
      </NFormItemGi>
    </template>
  </OperateModel>
</template>

<style scoped>

</style>
