import type { PropType } from 'vue'

export function typeValidator(type: string) {
  return ['text', 'password', 'number'].includes(type)
}

export type ValidateTriggers = 'onFocus' | 'onBlur' | 'onChange' | 'onClick' | 'onClear' | 'onInput'

export const props = {
  value: {
    type: String,
  },
  type: {
    type: String as PropType<'text' | 'password' | 'number'>,
    default: 'text',
    validator: typeValidator,
  },
  textarea: {
    type: Boolean,
    default: false,
  },
  rows: {
    type: [String, Number],
    default: 8,
  },
  placeholder: {
    type: String,
  },
  line: {
    type: Boolean,
    default: true,
  },
  hint: {
    type: Boolean,
    default: true,
  },
  textColor: {
    type: String,
  },
  focusColor: {
    type: String,
  },
  blurColor: {
    type: String,
  },
  maxlength: {
    type: [String, Number],
  },
  disabled: {
    type: Boolean,
    default: false,
  },
  readonly: {
    type: Boolean,
    default: false,
  },
  clearable: {
    type: Boolean,
    default: false,
  },
  resize: {
    type: Boolean,
    default: false,
  },
  validateTrigger: {
    type: Array as PropType<ValidateTriggers[]>,
    default: () => ['onInput', 'onClear'],
  },
  rules: {
    type: Array as PropType<Array<(v: string) => any>>,
  },
}
