import { MyPageContainer } from '@/common';
import MyPatrolWork from '@/pages/work_order/patrol_work';
import { useSearchParams } from '@umijs/max';
import { Tabs } from 'antd';
import { useEffect, useState } from 'react';
import MyPatrolLocations from './patrol_locations';
import MyPatrolRoutes from './patrol_routes';
import MyPatrolTasks from './patrol_tasks';

export default function Index({ title = '安防巡更' }) {
  const [searchParams] = useSearchParams();
  const [activeKey, setActiveKey] = useState('MyPatrolTasks');

  const items = [
    {
      key: '1',
      label: '巡更任务',
      children: <MyPatrolTasks />,
    },
    {
      key: '2',
      label: '路线配置',
      children: <MyPatrolRoutes />,
    },
    {
      key: '3',
      label: '点位配置',
      children: <MyPatrolLocations />,
    },
    {
      key: '4',
      label: '巡更工单',
      children: <MyPatrolWork />,
    },
  ];

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

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