import { reactive, computed } from 'vue'
import type { FormInstance, FormRules, TabsPaneContext } from 'element-plus'

export interface RuleForm {
  name: string
  adMix: string
  count: string
  date1: string
  date2: string
  budget: string
  delivery: boolean
  type: string
  bidStrategy: string
  placeBid: string
  firstPage: string
  other: string
  adGroupName: string
  autoRedirect: string
  defaultBidInp: string
  closeMatch: boolean
  broadMatch: boolean
  similarProducts: boolean
  relatedProducts: boolean
  closeMatchInp: string
  broadMatchInp: string
  similarProductsInp: string
  relatedProductsInp: string
  phraseNegation: boolean
  preciseNegation: boolean
  negativeTextarea: string
  negativeGoodsTextarea: string
  targetType: string
}
export const ruleForm = reactive<RuleForm>({
  name: 'Hello',
  adMix: '',
  count: '',
  date1: '',
  date2: '',
  budget: '',
  delivery: false,
  type: 'auto',
  bidStrategy: 'dynamicBid_Low',
  placeBid: '',
  firstPage: '',
  other: '',
  adGroupName: '',
  autoRedirect: 'defaultBid',
  defaultBidInp: '',
  closeMatch: true,
  broadMatch: true,
  similarProducts: true,
  relatedProducts: true,
  closeMatchInp: '666',
  broadMatchInp: '666',
  similarProductsInp: '666',
  relatedProductsInp: '666',
  phraseNegation: true,
  preciseNegation: true,
  negativeTextarea: '',
  negativeGoodsTextarea: '',
  targetType: 'keyWords',
})
export const rules = computed(() => ({
  name: [{ required: true, message: 'Please input Activity name', trigger: 'blur' }],
  adMix: [{ required: false, message: 'Please select Activity zone', trigger: 'change' }],
  count: [{ required: true, message: 'Please select Activity count', trigger: 'change' }],
  date1: [{ required: true, type: 'date', message: 'Please pick a date', trigger: 'change' }],
  date2: [{ required: false, type: 'date', message: 'Please pick a time', trigger: 'change' }],
  budget: [
    { required: true, message: '请输入预算', trigger: 'blur' },
    { pattern: /^(?:[1-9]\d{0,5}|1000000)(?:\.\d{1,2})?$/, message: '预算必须是1到1000000之间的数字，小数点后最多两位', trigger: 'blur' },
  ],
  type: [{ required: false, trigger: 'change' }],
  bidStrategy: [{ required: true, message: 'Please select activity resource', trigger: 'change' }],
  placeBid: [{ required: false, pattern: /^[0-9]{1,3}$/, message: '必须是0~900之间的整数百分比', trigger: 'change' }],
  firstPage: [{ required: false, pattern: /^[0-9]{1,3}$/, message: '必须是0~900之间的整数百分比', trigger: 'change' }],
  other: [{ required: false, pattern: /^[0-9]{1,3}$/, message: '必须是0~900之间的整数百分比', trigger: 'change' }],
  adGroupName: [{ required: true, message: 'Please input Activity name', trigger: 'blur' }],
  autoRedirect: [{ required: true, trigger: 'change' }],
  defaultBidInp: getValidationRules('defaultBidInp'),
  relatedProductsInp: getValidationRules('relatedProductsInp'),
  similarProductsInp: getValidationRules('similarProductsInp'),
  broadMatchInp: getValidationRules('broadMatchInp'),
  closeMatchInp: getValidationRules('closeMatchInp'),
}))