import {
  MyButtons,
  MyColumns,
  MyPageContainer,
  MyProTableProps,
  usePageTabs,
} from '@/common';
import { Apis } from '@/gen/Apis';
import {
  CustomerMomentsChannelEnum,
  CustomerMomentsContentTypeEnum,
  CustomerMomentsPushTypeEnum,
  CustomerMomentsTaskEndTypeEnum,
} from '@/gen/Enums';
import { ProTable } from '@ant-design/pro-components';
import { Card, Space } from 'antd';
import Create from './modals/Create';

export default function Index({ title = '创建内容' }) {
  // 注册当前页面为标签页
  usePageTabs({
    tabKey: 'moments-list',
    tabLabel: title,
  });

  return (
    <MyPageContainer
      title={title}
      enableTabs={true}
      tabKey="moments-list"
      tabLabel={title}
    >
      <ProTable
        {...MyProTableProps.props}
        expandable={{
          defaultExpandAllRows: true,
        }}
        request={async (params, sort) =>
          MyProTableProps.request(
            params,
            sort,
            Apis.Customer.CustomerMoments.List,
          )
        }
        toolBarRender={(action) => [
          <Create key="Create" reload={action?.reload} title={title} />,
        ]}
        columns={[
          MyColumns.ID(),
          {
            title: '名称',
            dataIndex: 'title',
            render: (_, i: any) => {
              return (
                <Card size="small">
                  <Space align="start">
                    <img src={i?.cover_image[0]?.url} width={45} height={45} />
                    <div>{i?.title}</div>
                  </Space>
                </Card>
              );
            },
          },
          MyColumns.EnumTag({
            title: '发送渠道',
            dataIndex: 'channel',
            valueEnum: CustomerMomentsChannelEnum,
          }),
          MyColumns.EnumTag({
            title: '内容类型',
            dataIndex: 'content_type',
            valueEnum: CustomerMomentsContentTypeEnum,
          }),
          MyColumns.EnumTag({
            title: '推送类型',
            dataIndex: 'push_type',
            valueEnum: CustomerMomentsPushTypeEnum,
          }),
          {
            title: '定时发送时间',
            dataIndex: 'scheduled_time',
            search: false,
          },

          MyColumns.EnumTag({
            title: '任务结束类型',
            dataIndex: 'task_end_type',
            valueEnum: CustomerMomentsTaskEndTypeEnum,
            search: false,
          }),
          {
            title: '任务结束天数',
            dataIndex: 'task_days',
            search: false,
          },
          {
            title: '定时结束',
            dataIndex: 'task_end_time',
            search: false,
          },
          MyColumns.UpdatedAt(),
          MyColumns.CreatedAt(),
          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={index}>
                {/* <Update item={item} reload={action?.reload} title={title} /> */}
                <MyButtons.Default
                  isConfirm
                  title="发送"
                  type="primary"
                  disabled={
                    item?.push_type === 'ScheduledPush' ||
                    item?.push_status === 'Pushed'
                  }
                  description="确定发送？"
                  onConfirm={() => {
                    Apis.Customer.CustomerMoments.Send({
                      id: item.id,
                    }).then(() => action?.reload());
                  }}
                />
                {/* <MyButtons.Delete
                  onConfirm={() =>
                    Apis.Customer.CustomerMoments.Delete({
                      id: item.id,
                    }).then(() => action?.reload())
                  }
                /> */}
              </Space>
            ),
          }),
        ]}
      />
    </MyPageContainer>
  );
}
