import { MyPageContainer, usePageTabs } from '@/common';
import { Apis } from '@/gen/Apis';
import { ProCard } from '@ant-design/pro-components';
import { useParams } from '@umijs/max';
import { Tabs } from 'antd';
import { useEffect, useState } from 'react';
import CollectionList from './components/CollectionList';
import CollectionTaskInfo from './components/CollectionTaskInfo';

export default function Show({ title }: { title?: string } = {}) {
  const { id } = useParams<{ id: string }>();
  const [data, setShow] = useState<any>({});

  // 注册当前页面为标签页
  const { addTab } = usePageTabs({
    tabKey: `collection-task-${id}`,
    tabLabel: `${data?.task_name} ${data?.id}` || title || '任务详情',
  });

  const loadShow = () => {
    let paramsId: any = { id: id ?? 0 };
    Apis.Collcetion.HouseCollectionTasks.Show(paramsId).then((res) => {
      setShow(res?.data);
    });
  };

  useEffect(() => {
    loadShow();
  }, [id]);

  let items = [
    {
      label: '通知记录',
      key: '1',
      closable: false,
      children: (
        <CollectionList
          item={{ ...data, collection_tasks_id: id }}
          reload={() => loadShow()}
        />
      ),
    },
  ];
  return (
    <MyPageContainer title={title}>
      <CollectionTaskInfo item={data} reload={loadShow} />
      <ProCard style={{ marginTop: 16 }}>
        <Tabs type="card" items={items} defaultActiveKey="1" size="small" />
      </ProCard>
    </MyPageContainer>
  );
}
