//做市商搜索配置

export const marketSearch = [
  {
    label: '账户名',
    prop: 'accountName',
    type: 'input' as const,
    placeholder: '请输入账户名',
    width: '340px',
  },
]

export const marketTableColumns = [
  // id
  { label: 'ID', prop: 'id', align: 'center' as const, width: '100px',filterable:false },
  //代理关系
  { label: '代理关系', prop: 'agentRelation', align: 'center' as const, width: '290' },
  //账户名
  { label: '账户名', prop: 'accountName', align: 'center' as const, width: '120px' },
  //级别
  { label: '级别', prop: 'level', align: 'center' as const, width: '120px' },
  { label: '邮箱', prop: 'email', align: 'center' as const, width: '160px' },
  { label: '手机号', prop: 'mobile', align: 'center' as const, width: '180' },
  { label: '风险率', prop: 'ratio', align: 'center' as const, width: '120px' },
  //基本账户
  { label: '基本账户', prop: 'basicAccount', align: 'center' as const, isNumber: true , width: '200px' },
  //保证金
  { label: '保证金', prop: 'margin', align: 'center' as const, width: '200px', isNumber: true },
  //停止接单保证金
  { label: '停止接单保证金', prop: 'stopOrderMargin', align: 'center' as const, width: '200px', isNumber: true },
  //持仓转移保证金
  {
    label: '持仓转移保证金',
    prop: 'positionTransferMargin',
    align: 'center' as const,
    width: '200px',
    isNumber: true,
  },
  //头寸比率
  { label: '头寸比率', prop: 'positionRatio', align: 'center' as const, width: '150px', isNumber: true },
  //点差返佣
  { label: '点差返佣', prop: 'pointSpreadCommission', align: 'center' as const, width: '200px', isNumber: true },
  //点差
  { label: '点差', slotName: 'pointSpread', align: 'center' as const, width: '150px' },
  //手续费比例
  { label: '手续费比例', prop: 'commissionRatio', align: 'center' as const, width: '150px', isNumber: true },
  //手续费返佣
  { label: '手续费返佣', prop: 'commissionReturn', align: 'center' as const, width: '150px', isNumber: true },
  //浮动盈亏
  { label: '浮动盈亏', slotName: 'floatProfitLoss', align: 'center' as const, width: '100px', isNumber: true },
  //平仓盈亏
  { label: '平仓盈亏', slotName: 'closeProfitLoss', align: 'center' as const, width: '150px', isNumber: true },
  //风险金
  { label: '风险金', prop: 'riskMargin', align: 'center' as const, width: '150px', isNumber: true },
  //服务费
  { label: '服务费', prop: 'serviceFee', align: 'center' as const, width: '150px', isNumber: true },
]

//做市商添加配置
export const marketFormItem = [
    //邮箱或手机号
    { prop: 'phoneOrEmail', label: '', type: 'slot' as const, slotName: 'phoneOrEmail' },
    //账户名称
    { label: '账户名称', prop: 'accountName', type: 'input' as const, placeholder: '请输入账户名称', },
    //级别
    { label: '级别', prop: 'level', type: 'select' as const, placeholder: '请选择级别' },
    //是否为承接特殊做市
    { label: '是否为承接特殊做市', labelWidth:"160px", prop: 'is_base_ts', type: 'radio' as const, show: false },
    //承接特殊做市
    { label: '承接特殊做市',  prop: 'base_ts', type: 'select' as const, placeholder: '请选择承接特殊做市', show: false },
    //所属上级
    { label: '所属上级', prop: 'parentAccountName', type: 'select' as const, placeholder: '请选择所属上级账户名称', },
    // 风控模板
    { label: '风控模板', prop: 'riskControlTemplate', type: 'select' as const, placeholder: '请选择风控模板' },
    //头寸
    { label: '头寸', prop: 'positionRatio', type: 'input' as const, placeholder: '请输入头寸', },
    //手续费
    { label: '手续费', prop: 'commissionRatio', type: 'input' as const, placeholder: '请输入手续费', },
]

// 国家码选项
interface CountryItem {
    name: string
    code: string
}
export const countryOptions = ref<CountryItem[]>([
    { name: '中国', code: '+86' },
    { name: '中国台湾', code: '+886' },
    { name: '中国香港', code: '+852' },
    { name: '中国澳门', code: '+853' },
    { name: '韩国', code: '+82' },
    { name: '美国', code: '+1' },
    { name: '新加坡', code: '+65' }
])

//编辑点差表格列配置
export const marketPointTableColumns = [
  { prop: 'varietyName', label: '名称', align: 'center' as const },
  { prop: 'varietyCode', label: '编号', align: 'center' as const },
  { prop: 'point_diff', label: '可分配点差', align: 'center' as const },
  {
    prop: 'pointDifference',
    label: '已分配点差',
    align: 'center' as const,
    slotName: 'assignedPointDiff',
  },
]

// 查看点差表格列配置
export const viewMarketPointTableColumns = [
  { prop: 'varietyName', label: '名称', align: 'center' as const },
  { prop: 'varietyCode', label: '编号', align: 'center' as const },
  { prop: 'pointDifference', label: '可分配点差', align: 'center' as const },
  { prop: 'assignedPointDifference', label: '已分配点差', align: 'center' as const },
]

export const accountFormItemList = [
  { label: '账户名', prop: 'username', type: 'input' as const, disabled: true },
  { label: '币种', prop: 'currency', type: 'input' as const, disabled: true },
  { label: '当前余额', prop: 'amount_old', type: 'input' as const, disabled: true },
  { label: '调整金额', prop: 'amount', type: 'input' as const },
  { label: '调整后余额', prop: 'amount_new', type: 'input' as const, disabled: true },
]
export const accountFormItemRules = {
  amount: [{ required: true, message: '请输入调整金额', trigger: ['blur', 'change'] }],
}

export const acceptOrdersFormItemList = [
  { label: '账户名', prop: 'username', type: 'input' as const, disabled: true },
  { label: '币种', prop: 'currency', type: 'input' as const, disabled: true },
  { label: '当前停止接单金额', prop: 'bail_stop_order_old', type: 'input' as const, disabled: true },
  { label: '调整金额', prop: 'bail_stop_order', type: 'input' as const },
]

export const acceptOrdersFormItemRules = {
  bail_stop_order: [{ required: true, message: '请输入调整金额', trigger: ['blur', 'change'] }],
}

export const transferFormItemList = [
  { label: '账户名', prop: 'username', type: 'input' as const, disabled: true },
  { label: '币种', prop: 'currency', type: 'input' as const, disabled: true },
  { label: '当前持仓转移金额', prop: 'bail_change_order_old', type: 'input' as const, disabled: true },
  { label: '调整金额', prop: 'bail_change_order', type: 'input' as const },
]

export const transferFormItemRules = {
  bail_change_order: [{ required: true, message: '请输入调整金额', trigger: ['blur', 'change'] }],
}

// 取款表单配置（根据不同角色显示不同字段）
// 平台(1): 币种、手续费佣金、点差佣金、服务费、风险金
// 承包商(2): 币种、手续费佣金、点差佣金、服务费
// 特殊做市商(3): 币种、手续费佣金、点差佣金、服务费、盈利
// 普通做市商(4): 币种、手续费佣金、点差佣金、盈利
// 代理(5): 币种、手续费佣金、点差佣金

export interface WithdrawFormConfig {
  prop: string
  label: string
  type: 'input' | 'select'
  disabled?: boolean
  required?: boolean
  placeholder?: string
  max?: number | string
}

export const getWithdrawFormConfig = (roleId: number): WithdrawFormConfig[] => {
  const baseConfig: WithdrawFormConfig[] = [
    { prop: 'currency', label: '币种', type: 'input', disabled: true },
  ]

  // 手续费佣金（所有角色都有）
  const feeHandlingConfig: WithdrawFormConfig = {
    prop: 'withdraw_fee_handle',
    label: '手续费佣金',
    type: 'input',
    required: true,
    placeholder: '请输入手续费佣金',
  }

  // 点差佣金（所有角色都有）
  const pointDiffConfig: WithdrawFormConfig = {
    prop: 'withdraw_point_diff',
    label: '点差佣金',
    type: 'input',
    required: true,
    placeholder: '请输入点差佣金',
  }

  // 服务费（平台、承包商、特殊做市商）
  const serviceFeeConfig: WithdrawFormConfig = {
    prop: 'withdraw_service_fee',
    label: '服务费',
    type: 'input',
    required: true,
    placeholder: '请输入服务费',
  }

  // 风险金（仅平台）
  const riskFeeConfig: WithdrawFormConfig = {
    prop: 'withdraw_risk_fee',
    label: '风险金',
    type: 'input',
    required: true,
    placeholder: '请输入风险金',
  }

  // 盈利（特殊做市商、普通做市商）
  const headFeeConfig: WithdrawFormConfig = {
    prop: 'withdraw_head_fee',
    label: '盈利',
    type: 'input',
    required: true,
    placeholder: '请输入盈利',
  }

  switch (roleId) {
    case 1: // 平台
      return [
        ...baseConfig,
        feeHandlingConfig,
        pointDiffConfig,
        serviceFeeConfig,
        riskFeeConfig,
      ]
    case 2: // 承包商
      return [
        ...baseConfig,
        feeHandlingConfig,
        pointDiffConfig,
        serviceFeeConfig,
      ]
    case 3: // 特殊做市商
      return [
        ...baseConfig,
        feeHandlingConfig,
        pointDiffConfig,
        serviceFeeConfig,
        headFeeConfig,
      ]
    case 4: // 普通做市商
      return [
        ...baseConfig,
        feeHandlingConfig,
        pointDiffConfig,
        headFeeConfig,
      ]
    case 5: // 一级代理
      return [
        ...baseConfig,
        feeHandlingConfig,
        pointDiffConfig,
      ]
    default:
      return baseConfig
  }
}

// 取款表单验证规则
export const getWithdrawFormRules = (roleId: number) => {
  const rules: Record<string, any[]> = {
    withdraw_address: [{ required: true, message: '请输入钱包地址', trigger: ['blur', 'change'] }],
    channel_id: [{ required: true, message: '请选择取款渠道', trigger: ['change'] }],
    withdraw_fee_handle: [
      { required: false, message: '请输入手续费佣金', trigger: ['blur', 'change'] },
      { pattern: /^\d+(\.\d{0,2})?$/, message: '请输入正确的金额格式', trigger: ['blur', 'change'] }
    ],
    withdraw_point_diff: [
      { required: false, message: '请输入点差佣金', trigger: ['blur', 'change'] },
      { pattern: /^\d+(\.\d{0,2})?$/, message: '请输入正确的金额格式', trigger: ['blur', 'change'] }
    ],
  }

  // 服务费（平台、承包商、特殊做市商）
  if ([1, 2, 3].includes(roleId)) {
    rules.withdraw_service_fee = [
      { required: false, message: '请输入服务费', trigger: ['blur', 'change'] },
      { pattern: /^\d+(\.\d{0,2})?$/, message: '请输入正确的金额格式', trigger: ['blur', 'change'] }
    ]
  }

  // 风险金（仅平台）
  if (roleId === 1) {
    rules.withdraw_risk_fee = [
      { required: false, message: '请输入风险金', trigger: ['blur', 'change'] },
      { pattern: /^\d+(\.\d{0,2})?$/, message: '请输入正确的金额格式', trigger: ['blur', 'change'] }
    ]
  }

  // 盈利（特殊做市商、普通做市商）
  if ([3, 4].includes(roleId)) {
    rules.withdraw_head_fee = [
      { required: false, message: '请输入盈利', trigger: ['blur', 'change'] },
      { pattern: /^\d+(\.\d{0,2})?$/, message: '请输入正确的金额格式', trigger: ['blur', 'change'] }
    ]
  }

  return rules
}