import { MyPageContainer } from '@/common';
import { useSearchParams } from '@umijs/max';
import type { TabsProps } from 'antd';
import { Tabs } from 'antd';
import { useEffect, useState } from 'react';
import Borrows from './borrows';
import Read from './read';

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

  const items: TabsProps['items'] = [
    {
      key: 'Borrows',
      label: '合同借用',
      children: <Borrows />,
    },
    {
      key: 'Read',
      label: '合同借阅',
      children: <Read />,
    },
  ];

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

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