import { type PropType } from "vue";
import { formProps } from "naive-ui/es/form/src/Form";
import type {
  FormItemRuleValidator,
  LabelAlign,
  LabelPlacement,
} from "naive-ui/es/form/src/interface";
import type { FormItemOptions } from "./indexface";
import { type FormItemProps, type GridProps } from "naive-ui";
import { isEmpty } from "lodash-es";

export const formProProps = {
  ...formProps,
  labelWidth: {
    type: [Number, String] as PropType<number | string>,
  },
  labelPlacement: {
    type: String as PropType<LabelPlacement>,
    default: "left",
  },
  labelAlign: {
    type: String as PropType<LabelAlign>,
    default: "left",
  },
  value: {
    type: Object as PropType<any>,
  },
  gridProps: {
    type: Object as PropType<GridProps>,
    default: {
      cols: 1,
      xGap: 8,
      itemResponsive: true,
      responsive: "self",
    },
  },
  formItemOptions: {
    type: Object as PropType<FormItemOptions<any>>,
  },
};

// 定义通用校验规则
export const universalValidator: FormItemRuleValidator = (_, value) => {
  if (value === null || value === undefined) {
    return false;
  } else if (typeof value === "string" && value.trim() === "") {
    return false;
  } else if (Array.isArray(value) && value.length === 0) {
    return false;
  }
};
