import { ProColumns } from '@ant-design/pro-components';
import { Tag, Button, Popconfirm, Space, Switch, Tooltip } from 'antd';
import Users from './user'
import { InfoCircleOutlined } from '@ant-design/icons';
export const columns = (
  edit: (b: boolean, v: any) => void,
  del: (id: any) => void,
  stateUpdata: (id: any, ck: boolean) => void,
  mimiAssign: (b: any) => void,
): ProColumns<any>[] => {
  return [
    {
      title: 'ID',
      dataIndex: 'id',
      key: 'id',
      align: 'center',
      width: 70,
      ellipsis: true,
      hideInSearch: true,
    },
    {
      title: '小程序appId',
      dataIndex: 'wechatAppId',
      key: 'wechatAppId',
      align: 'center',
      width: 70,
      ellipsis: true,
    },
    // {
    //   title: '小程序秘钥',
    //   dataIndex: 'appSecret',
    //   key: 'appSecret',
    //   align: 'center',
    //   width: 80,
    //   ellipsis: true,
    //   hideInSearch: true,
    // },
    {
      title: '小程序名称',
      dataIndex: 'appName',
      key: 'appName',
      width: 80,
      ellipsis: true,
      align: 'center',
    },
    {
      title: '小程序页面模板',
      dataIndex: 'templateName',
      key: 'templateName',
      width: 80,
      ellipsis: true,
      align: 'center',
    },
    {
      title: '小程序首页链接',
      dataIndex: 'homePage',
      key: 'homePage',
      width: 80,
      ellipsis: true,
      align: 'center',
      hideInSearch: true,
    },
    {
      title: '小程序版本号',
      dataIndex: 'appVersion',
      key: 'appVersion',
      width: 80,
      ellipsis: true,
      align: 'center',
      hideInSearch: true,
    },
    {
      title: 'ios支付版本号',
      width: 80,
      ellipsis: true,
      align: 'center',
      tooltip: "ios的特殊性,此版本号与IOS支付模块关联,小程序版本号<=此版本号IOS才会出现支付功能,(微信)小程序发布线上后必须设置",
      dataIndex: 'iosPayment',
      hideInSearch: true,
      render: (_, d) => {
        return d.iosPayment ? <Tag color={d.iosPayment === d.appVersion ? "processing" : "error"} bordered={false}> {d.iosPayment} </Tag> : <Tag color="error" bordered={false}>IOS无法支付</Tag>
      }
    },
    {
      title: '备注',
      dataIndex: 'remark',
      key: 'remark',
      width: 80,
      align: 'center',
      ellipsis: true,
      hideInSearch: true,
    },

    {
      title: '状态',
      dataIndex: 'enabled',
      key: 'enabled',
      width: 80,
      align: 'center',
      ellipsis: true,
      hideInSearch: true,
      render: (a: any, b: any) => {
        return (
          <Switch
            checkedChildren="正常"
            unCheckedChildren="停用"
            checked={b?.enabled}
            onChange={(ck) => {
              stateUpdata(b.id, ck);
            }}
          />
        );
      },
    },
    {
      title: '已指派(分销商)',
      dataIndex: 'distributorInfo',
      width: 80,
      align: 'center',
      ellipsis: true,
      hideInSearch: true,
      render: (a, b: any) => {
        return <a>{b?.distributorInfo?.companyName}</a>;
      },
    },
    {
      title: '商户',
      dataIndex: 'mchName',
      width: 80,
      align: 'center',
      ellipsis: true,
      hideInSearch: true,
      render: (a, b: any) => {
        return <a>{b?.mchInfo?.mchName}</a>;
      },
    },
    {
      title: '操作',
      dataIndex: 'cz',
      key: 'cz',
      width: 160,
      align: 'center',
      hideInSearch: true,
      render: (a: any, b: any) => {
        return (
          <Space size={[0, 0]}>
            <Button
              onClick={() => {
                edit(true, b);
              }}
              size="small"
              type="link"
            >
              编辑
            </Button>
            <Popconfirm
              title={
                <div>
                  确定要删除<span style={{ color: 'red' }}>{b.appName}</span>小程序?
                </div>
              }
              onConfirm={() => {
                del(b.id);
              }}
            >
              <Button size="small" danger type="link">
                删除
              </Button>
            </Popconfirm>
            <Button
              onClick={() => {
                mimiAssign(b);
              }}
              size="small"
              type="link"
            >
              指派
            </Button>
            <Users data={b} />
          </Space>
        );
      },
    },
  ];
};
