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

export default function Index({ title = '工单回访' }) {
  const [searchParams] = useSearchParams();
  const [activeKey, setActiveKey] = useState('1');

  const items: TabsProps['items'] = [
    {
      key: 'NoVisited',
      label: '未回访工单',
      children: <NoVisited />,
    },
    {
      key: 'IsVisited',
      label: '已回访工单',
      children: <IsVisited />,
    },
  ];

  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>
  );
}
