import { MyPageContainer } from '@/common';
import { useSearchParams } from '@umijs/max';
import { Tabs } from 'antd';
import { useEffect, useState } from 'react';
import CommonMeter from './common_meter';
import HouseMeter from './house_meter';

export default function Index({ title = '仪表管理' }) {
  const [searchParams] = useSearchParams();
  const [activeKey, setActiveKey] = useState('MyResources');

  const items = [
    {
      key: 'HouseMeter',
      label: '房屋表',
      children: <HouseMeter />,
    },
    {
      key: 'CommonMeter',
      label: '公摊表',
      children: <CommonMeter />,
    },
  ];
  useEffect(() => {
    if (searchParams?.get('key')) {
      setActiveKey(searchParams?.get('key') || '1');
    }
  }, []);

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