import { MyPageContainer } from '@/common';
import { Apis } from '@/gen/Apis';
import { useParams } from '@umijs/max';
import { Tabs } from 'antd';
import { useEffect, useState } from 'react';

import { ProCard } from '@ant-design/pro-components';
import AssetAccounts from '../table/AssetAccounts';
import MyAssetBuildings from '../table/AssetBuildings';
import AssetGrid from '../table/AssetGrid';
import AssetInfo from '../table/AssetInfo';
import AssetParkings from '../table/AssetParkings';
import ChargeStandard from '../table/ChargeStandard';
import MyManagers from '../table/Managers';

export default function Show({ title }: { title?: string } = {}) {
  const { id } = useParams<{ id: string }>();
  const [data, setShow] = useState<any>({});

  // 注册当前页面为标签页
  // const { addTab } = usePageTabs({
  //   tabKey: `asset-show-${id}`,
  //   tabLabel: '详情',
  //   autoAdd: false,
  // });

  const loadShow = () => {
    let paramsId: any = { id: id ?? 0 };
    Apis.Asset.AssetProjects.Show(paramsId).then((res) => {
      setShow(res?.data);
      // 更新标签页名称为API返回的name
      // if (res?.data?.name) {
      //   addTab({
      //     key: `asset-show-${id}`,
      //     label: res.data.name,
      //     path: `/asset/${id}`,
      //   });
      // }
    });
  };
  useEffect(() => {
    loadShow();
  }, [id]);

  let items = [
    {
      label: '基本信息',
      key: 'info',
      closable: false,
      children: <AssetInfo item={data} reload={() => loadShow()} />,
    },
    {
      label: '楼栋房屋',
      key: 'asset_buildings',
      closable: false,
      children: <MyAssetBuildings item={data} />,
    },
    {
      label: '楼栋管家',
      key: 'grid',
      closable: false,
      children: <AssetGrid item={data} />,
    },
    {
      label: '车场车位',
      key: 'parking_spaces',
      closable: false,
      children: <AssetParkings item={data} />,
    },
    {
      label: '项目收款账号',
      key: 'asset_accounts',
      closable: false,
      children: <AssetAccounts item={data} />,
    },
    {
      label: '项目收费标准',
      key: 'charge_standard',
      closable: false,
      children: <ChargeStandard item={data} />,
    },
    {
      label: '工单管理员',
      key: 'managers',
      closable: false,
      children: <MyManagers item={data} />,
    },
    // {
    //   label: '项目公告',
    //   key: 'announcement',
    //   closable: false,
    //   children: <Announcement item={data} />,
    // },
    // {
    //   label: '项目活动',
    //   key: 'activities',
    //   closable: false,
    //   children: <Activities item={data} />,
    // },
    // {
    //   label: '便民服务',
    //   key: 'convenience_services',
    //   closable: false,
    //   children: <ConvenienceServices item={data} />,
    // },
  ];
  return (
    <MyPageContainer
      title={data?.name || title || '项目详情'}
      enableTabs={false}
      tabKey="asset-show"
      tabLabel={data?.name || title || '项目详情'}
    >
      <ProCard>
        <Tabs type="card" items={data?.id ? items : []} />
      </ProCard>
    </MyPageContainer>
  );
}
