import type { VbenFormProps } from '#/adapter/form';

import { useUserStore } from '@vben/stores';

/**
 * 资金变动筛选：门店现金账户无 frozen（未确认收货），筛选项需按角色裁剪
 * 须在组件 setup 内调用，保证 Pinia 已就绪
 */
export function getAccountChangeSearchOptions(): VbenFormProps {
  const userStore = useUserStore();
  const isStoreUser =
    Number(
      (userStore.userInfo as Record<string, any> | null)?.roles?.user_type,
    ) === 1;
  const fieldNameOptions = [
    { label: '可提现金额', value: 'able_cash' },
    { label: '可提现余额', value: 'balance' },
    // 仅供应商/配送仓余额账户有「确认收货前冻结」
    ...(!isStoreUser
      ? [{ label: '冻结金额（用户未确认收货）', value: 'frozen' }]
      : []),
    { label: '审核中金额', value: 'frozen_cash' },
    { label: '审核中金额（余额账户）', value: 'withdrawn_frozen' },
  ];
  return {
    collapsed: false,
    schema: [
      {
        component: 'VbenSelect',
        componentProps: {
          placeholder: '来源类型',
          allowClear: true,
          options: [
            { label: '分账', value: 'settle' },
            { label: '提现', value: 'withdraw' },
            { label: '退款', value: 'refund' },
          ],
        },
        defaultValue: '',
        fieldName: 'source_type',
        label: '来源类型',
      },
      {
        component: 'VbenSelect',
        componentProps: {
          placeholder: '变更字段',
          allowClear: true,
          options: fieldNameOptions,
        },
        defaultValue: '',
        fieldName: 'field_name',
        label: '变更字段',
      },
      {
        component: 'VbenInput',
        componentProps: {
          placeholder: '输入订单号',
        },
        defaultValue: '',
        fieldName: 'order_no',
        label: '订单号',
      },
    ],
    showCollapseButton: true,
    submitButtonOptions: {
      content: '查询',
    },
    submitOnChange: true,
    submitOnEnter: false,
  };
}
