<script setup lang="ts">
import { ref } from "vue";
import { formRules } from "./utils/rule";
import { FormProps } from "./utils/types";

const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    roleName: "",
    roleCode: "",
    roleType: "custom",
    description: "",
    dataScope: 1,
    sortOrder: 0,
    status: 1
  })
});

const ruleFormRef = ref();
const newFormInline = ref(props.formInline);

function getRef() {
  return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
  <el-form
    ref="ruleFormRef"
    :model="newFormInline"
    :rules="formRules"
    label-width="82px"
  >
    <el-form-item label="角色名称" prop="roleName">
      <el-input
        v-model="newFormInline.roleName"
        clearable
        placeholder="请输入角色名称"
      />
    </el-form-item>

    <el-form-item label="角色编码" prop="roleCode">
      <el-input
        v-model="newFormInline.roleCode"
        clearable
        placeholder="请输入角色编码"
      />
    </el-form-item>

    <el-form-item label="角色类型">
      <el-radio-group v-model="newFormInline.roleType">
        <el-radio label="system">系统角色</el-radio>
        <el-radio label="custom">自定义角色</el-radio>
      </el-radio-group>
    </el-form-item>

    <el-form-item label="数据权限">
      <el-select v-model="newFormInline.dataScope" placeholder="请选择数据权限">
        <el-option :value="1" label="全部数据" />
        <el-option :value="2" label="本部门及以下" />
        <el-option :value="3" label="本部门" />
        <el-option :value="4" label="仅本人" />
        <el-option :value="5" label="自定义" />
      </el-select>
    </el-form-item>

    <el-form-item label="描述">
      <el-input
        v-model="newFormInline.description"
        placeholder="请输入描述信息"
        type="textarea"
      />
    </el-form-item>
  </el-form>
</template>
