import { MyPageContainer } from '@/common';
import { useSearchParams } from '@umijs/max';
import type { TabsProps } from 'antd';
import { Tabs } from 'antd';
import { useEffect, useState } from 'react';
import Seals from './seals';
import UnusedSeal from './unused';
import UsedSeal from './used';

export default function Index({ title = '合同用印' }) {
  const [searchParams] = useSearchParams();
  const [activeKey, setActiveKey] = useState('1');

  const items: TabsProps['items'] = [
    {
      key: 'UnusedSeal',
      label: '未用印合同',
      children: <UnusedSeal />,
    },
    {
      key: 'UsedSeal',
      label: '已用印合同',
      children: <UsedSeal />,
    },
    {
      key: 'Seals',
      label: '印章管理',
      children: <Seals />,
    },
  ];

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

  return (
    <MyPageContainer
      title={title}
      enableTabs={true}
      tabKey="visited"
      tabLabel={title}
    >
      <Tabs defaultActiveKey={activeKey} items={items} type="card" />
    </MyPageContainer>
  );
}
