import { MyPageContainer } from '@/common';
import { useSearchParams } from '@umijs/max';
import type { TabsProps } from 'antd';
import { Tabs } from 'antd';
import { useEffect, useState } from 'react';
import Finished from './finished';
import Transfers from './transfers';
import Unfinished from './unfinished';

export default function Index({ title = '合同归档' }) {
  const [searchParams] = useSearchParams();
  const [activeKey, setActiveKey] = useState('Unfinished');

  const items: TabsProps['items'] = [
    {
      key: 'Unfinished',
      label: '未归档合同',
      children: <Unfinished />,
    },
    {
      key: 'Finished',
      label: '归档记录',
      children: <Finished />,
    },
    {
      key: 'Transfers',
      label: '转移记录',
      children: <Transfers />,
    },
  ];

  useEffect(() => {
    if (searchParams?.get('key')) {
      setActiveKey(searchParams?.get('key') || 'Unfinished');
    }
  }, []);

  return (
    <MyPageContainer
      title={title}
      enableTabs={true}
      tabKey="archives"
      tabLabel={title}
    >
      <Tabs
        activeKey={activeKey}
        items={items}
        onChange={(key) => {
          setActiveKey(key);
        }}
        type="card"
      />
    </MyPageContainer>
  );
}
