import React from 'react';
import { Button, Space, Switch } from 'antd';
import { FormOutlined } from '@ant-design/icons';
import { jsonToArray } from '@/utils/utils';
import { getShopList } from '../service/bll';

export const layout = {
  labelCol: { span: 4 },
  wrapperCol: { span: 18 },
};
// 0-推荐 1-早餐 2-午餐 3-下午茶 4-晚餐
export const mealColumn = {
  // 0: '推荐',
  1: '早餐',
  2: '午餐',
  // 3: '晚餐',
  4: '晚餐',
};

// 商品类型
export const productType = {
  1: '实物商品',
  2: '虚拟商品',
  // 3: '电子卡券'（废弃）
  4: '服务类商品',
  5: '外卖商品',
};

export const weekOptions = {
  1: '周一',
  2: '周二',
  3: '周三',
  4: '周四',
  5: '周五',
  6: '周六',
  7: '周日',
};

export const takeawayGoodsColumn = options => {
  const {
    onDel,
    companyEnum,
    shopEnum,
    onChangeFlag,
    setVisibleSaleDate,
    enterprises,
    setRecordID,
    setVisiblePrice,
    setVisibleSaleSection,
    setVisibleSort,
    onChangeEnterprise,
  } = options;
  return [
    {
      title: '企业名称',
      dataIndex: 'enterpriseId',
      hideInTable: true,
      fieldProps: {
        showSearch: true,
        filterOption: (v, option) => (option?.label ?? '').toLowerCase().includes(v.toLowerCase()),
        onChange: onChangeEnterprise,
      },
      valueEnum: enterprises, // companyEnum,
    },
    {
      title: '微店名称',
      dataIndex: 'shopId',
      hideInTable: true,
      fieldProps: {
        showSearch: true,
      },
      // request: getShopList,
      // valueEnum: {}, // shopEnum,
    },
    {
      title: 'SKU编码',
      dataIndex: 'skuId',
      width: 120,
      align: 'center',
    },
    {
      title: '商品名称',
      dataIndex: 'skuName',
      width: 120,
      align: 'center',
    },
    {
      title: '商品图片',
      dataIndex: 'primaryImage',
      width: 120,
      align: 'center',
      hideInSearch: true,
      valueType: 'image',
    },
    {
      title: '可售日期',
      dataIndex: 'saleTimeType',
      width: 120,
      align: 'center',
      hideInSearch: true,
      render: (_, record) => (
        <Space>
          <span>{_}</span>
          <span
            onClick={() => {
              setRecordID(record.id);
              setVisibleSaleDate(true);
            }}
          >
            <FormOutlined />
          </span>
        </Space>
      ),
    },
    {
      title: '可售餐段',
      dataIndex: 'saleDate',
      width: 120,
      align: 'center',
      hideInSearch: true,
      render: (_, record) => (
        <Space>
          <span>{_}</span>
          <span
            onClick={() => {
              setRecordID(record.id);
              setVisibleSaleSection(true);
            }}
          >
            <FormOutlined />
          </span>
        </Space>
      ),
    },
    {
      title: '企业价格',
      dataIndex: 'activityPrice',
      width: 120,
      align: 'center',
      hideInSearch: true,
      render: (_, record) => (
        <Space>
          <span>{_}</span>
          <span
            onClick={() => {
              setRecordID(record.id);
              setVisiblePrice(true);
            }}
          >
            <FormOutlined />
          </span>
        </Space>
      ),
    },
    {
      title: '商品销售价',
      dataIndex: 'price',
      width: 120,
      align: 'center',
      hideInSearch: true,
    },
    {
      title: '状态',
      dataIndex: 'status',
      width: 120,
      align: 'center',
      hideInSearch: true,
      valueEnum: {
        1: '生效中',
        2: '已下架',
        3: '已售罄',
      },
    },
    {
      title: '排序',
      dataIndex: 'sort',
      width: 120,
      align: 'center',
      hideInSearch: true,
      render: (_, record) => (
        <Space>
          <span>{_}</span>
          <span
            onClick={() => {
              setRecordID(record.id);
              setVisibleSort(true);
            }}
          >
            <FormOutlined />
          </span>
        </Space>
      ),
    },
    {
      title: '列出商品',
      dataIndex: 'showFlag',
      width: 120,
      align: 'center',
      hideInSearch: true,
      render: (_, record) => (
        <Space>
          <span>
            <Switch checked={+_ === 1} onChange={e => onChangeFlag(record.id, e)} />
          </span>
        </Space>
      ),
    },
    {
      title: '餐品类型',
      dataIndex: 'mealType',
      width: 120,
      align: 'center',
      hideInSearch: true,
    },
    {
      title: '添加时间',
      dataIndex: 'createDate',
      width: 120,
      valueType: 'dateRange',
      align: 'center',
    },
    {
      title: '当日餐段',
      dataIndex: 'tabId',
      width: 120,
      align: 'center',
      valueEnum: mealColumn,
      hideInTable: true,
    },
    {
      title: '操作',
      hideInSearch: true,
      dataIndex: 'action',
      width: '100px',
      align: 'center',
      fixed: 'right',
      render: (val, r) => (
        <Button key="del" onClick={() => onDel(r.id)}>
          删除
        </Button>
      ),
    },
  ];
};

export const GoodsInfoColumn = options => {
  const { onDel, setVisibleSaleDate, setVisibleSaleSection, setEditID } = options;
  return [
    {
      title: '微店名称',
      dataIndex: 'shopId',
    },
    {
      title: '商品名称',
      dataIndex: 'skuName',
      align: 'center',
    },
    {
      title: '商品售价',
      dataIndex: 'price',
      width: 120,
      align: 'center',
    },
    {
      title: '企业价格',
      dataIndex: 'activityPrice',
      width: 120,
      align: 'center',
    },
    {
      title: '库存',
      dataIndex: 'status',
      width: 120,
      align: 'center',
    },
    {
      title: '可售日期',
      dataIndex: 'saleDate',
      align: 'center',
      hideInSearch: true,
      render: (_, record) => (
        <Space>
          {_ &&
            (_.length === 7 ? '不限制' : <span>{_.map(item => weekOptions[item]).join('/')}</span>)}
          <span
            onClick={() => {
              setEditID(record.skuId);
              setVisibleSaleDate(true);
            }}
          >
            <FormOutlined />
          </span>
        </Space>
      ),
    },
    {
      title: '可售餐段',
      dataIndex: 'mealType',
      align: 'center',
      hideInSearch: true,
      render: (_, record) => (
        <Space>
          <span>{_ && _.map(item => mealColumn[item]).join('/')}</span>
          <span
            onClick={() => {
              setEditID(record.skuId);
              setVisibleSaleSection(true);
            }}
          >
            <FormOutlined />
          </span>
        </Space>
      ),
    },
    {
      title: '餐品类型',
      dataIndex: 'mealType',
      width: 120,
      align: 'center',
      hideInSearch: true,
    },
    {
      title: '操作',
      hideInSearch: true,
      dataIndex: 'action',
      width: '100px',
      align: 'center',
      fixed: 'right',
      render: (val, r) => (
        <Button key="del" onClick={() => onDel(r, 'del')}>
          删除
        </Button>
      ),
    },
  ];
};

export const SelectGoodsColumn = [
  {
    title: '商品ID',
    width: 120,
    dataIndex: 'skuId',
  },
  {
    title: '商品名称',
    dataIndex: 'skuName',
    width: 120,
    align: 'center',
  },
  {
    title: '商品编号',
    dataIndex: 'skuNo',
    width: 120,
    align: 'center',
  },
  {
    title: '销售价',
    dataIndex: 'price',
    width: 120,
    align: 'center',
  },
  {
    title: '剩余库存',
    dataIndex: 'status',
    width: 120,
    align: 'center',
  },
  {
    title: '已参与活动',
    dataIndex: 'mealType',
    align: 'center',
    hideInSearch: true,
  },
];
