import { BasicColumn } from '/@/components/Table/src/types/table';
import { h, computed } from 'vue';
import { Time } from '/@/components/Time';
import { useMessage } from '/@/hooks/web/useMessage';
import { useI18n } from '/@/hooks/web/useI18n';
import { Switch } from 'ant-design-vue';
import { EditAndUpload, SpaceSdkTop } from '/@/api/product/index';
import { useLocaleStore } from '/@/store/modules/locale';
const localeStore = useLocaleStore();
const { createMessage } = useMessage();
const { t } = useI18n();
const isJA = computed(() => localeStore.getLocale === 'en');

export const refundTimeTableSchema: BasicColumn[] = [
  {
    title: '版本号',
    width: 150,
    dataIndex: 'version',
  },
  {
    title: '版本更新说明',
    width: 150,
    dataIndex: 'description',
  },
  {
    title: '最低版本号',
    width: 150,
    dataIndex: 'minVersion',
  },{
    title: '创建人',
    width: 150,
    dataIndex: 'recStatus',
  },{
    title: '创建时间',
    width: 150,
    dataIndex: 'createTime',
    customRender: ({ record }) => {
      return (
        record.createTime &&
        h(Time, {
          value: record.createTime,
          mode: 'datetime',
        })
      );
    },
  },{
    title: '状态',
    dataIndex: 'status',
    width: 80,
    customRender: ({ record }) => {
      if (!Reflect.has(record, 'pendingStatus')) {
        record.pendingStatus = false;
      }
      return h(Switch, {
        checked: record.status === 'A',
        checkedChildren: '启用',
        unCheckedChildren: '禁用',
        loading: false,
        onChange: async (checked: boolean) => {
          record.pendingStatus = true;
          const newStatus = checked ? 'A' : 'I';
          await EditAndUpload({...record,status:newStatus});
          if (checked) {
            Reflect.set(record, 'status', newStatus);
          } else {
            Reflect.set(record, 'status', newStatus);
          }
          createMessage.success(t('common.optSuccess'));
        },
      });
    },
  },
];

export const sdkTableSchema: BasicColumn[] = [
  {
    title: '版本号',
    width: 80,
    dataIndex: 'version',
  },
  {
    title: '版本更新说明',
    width: 240,
    dataIndex: 'imprintCh',
  },
  {
    title: '版本更新说明',
    width: 150,
    ifShow:true,
    dataIndex: 'status',
  },
  {
    title: '首次发布时间',
    width: 120,
    dataIndex: 'publishTime',
    customRender: ({ record }) => {
      return (
        record.publishTime &&
        h(Time, {
          value: record.publishTime,
          mode: 'datetime',
        })
      );
    },
  },{
    title: '创建人',
    width: 80,
    dataIndex: 'recStatus',
  },{
    title: '创建时间',
    width: 120,
    dataIndex: 'createTime',
    customRender: ({ record }) => {
      return (
        record.createTime &&
        h(Time, {
          value: record.createTime,
          mode: 'datetime',
        })
      );
    },
  },{
    title: '置顶',
    dataIndex: 'isTop',
    width: 80,
    customRender: ({ record }) => {
      if (!Reflect.has(record, 'isTop')) {
        record.pendingStatus = false;
      }
      return h(Switch, {
        checked: record.isTop == 1 ? true : false,
        checkedChildren: '启用',
        unCheckedChildren: '禁用',
        loading: false,
        onChange: async (checked: boolean) => {
          record.pendingStatus = true;
          const newStatus = checked?1:0;
          await SpaceSdkTop({...record,isTop:newStatus});
          Reflect.set(record, 'isTop', checked);
          createMessage.success(t('common.optSuccess'));
        },
      });
    },
  },{
    title: '发布状态',
    dataIndex: 'status',
    width: 80,
    customRender: ({ record }) => {
      return renderType(record.status)
    },
  },
];
export const refundTimeTableData: any[] = [
  {
    t1: '2017-10-01 14:10',
    t2: '联系客户',
    t3: '进行中',
    t4: '取货员 ID1234',
    t5: '5mins',
  },
  {
    t1: '2017-10-01 14:10',
    t2: '取货员出发',
    t3: '成功',
    t4: '取货员 ID1234',
    t5: '5mins',
  },
  {
    t1: '2017-10-01 14:10',
    t2: '取货员接单',
    t3: '成功',
    t4: '系统',
    t5: '5mins',
  },
  {
    t1: '2017-10-01 14:10',
    t2: '申请审批通过',
    t3: '成功',
    t4: '用户',
    t5: '1h',
  },
];
function renderType(type: number): string {
  switch (type) {
    case 0:
      return t(`routes.product.statusType.0`);
    case 1:
      return t(`routes.product.statusType.1`);
    default:
      return t(`routes.product.statusType.1`);
  }
}
