import { MyPageContainer } from '@/common';
import { useSearchParams } from '@umijs/max';
import type { TabsProps } from 'antd';
import { Tabs } from 'antd';
import { useEffect, useState } from 'react';
import Expense from './Expense';
import Income from './Income';

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

  const items: TabsProps['items'] = [
    {
      key: 'Expense',
      label: '合同支出',
      children: <Expense />,
    },
    {
      key: 'Income',
      label: '合同收入',
      children: <Income />,
    },
  ];

  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"
        // tabBarExtraContent={{
        //   right: (
        //     <Button
        //       type="primary"
        //       onClick={() => navigate('/contract/contracts_bi')}
        //     >
        //       返回合同BI
        //     </Button>
        //   ),
        // }}
      />
    </MyPageContainer>
  );
}
