import { MyPageContainer, usePageTabs } from '@/common';
import { Apis } from '@/gen/Apis';
import { ProCard } from '@ant-design/pro-components';
import { useParams } from '@umijs/max';
import { Tabs } from 'antd';
import { useEffect, useState } from 'react';
import ChargeInfo from './components/ChargeInfo';
import HasHouse from './components/HasHouse';

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

  // 注册当前页面为标签页
  const { addTab } = usePageTabs({
    tabKey: `charge-standard-${id}`,
    tabLabel: data?.name || title || '收费标准详情',
  });

  const loadShow = () => {
    let paramsId: any = { id: id ?? 0 };
    Apis.HouseCharage.HouseChargeStandards.Show(paramsId).then((res) => {
      setShow(res?.data);
    });
  };

  useEffect(() => {
    loadShow();
  }, [id]);

  let items = [
    {
      label: '关联房屋',
      key: '1',
      closable: false,
      children: (
        <HasHouse
          item={{ ...data, house_charge_has_houses_id: id }}
          reload={() => loadShow()}
        />
      ),
    },
  ];
  return (
    <MyPageContainer title={title}>
      <ChargeInfo item={data} reload={loadShow} />
      <ProCard style={{ marginTop: 16 }}>
        <Tabs type="card" items={items} defaultActiveKey="1" size="small" />
      </ProCard>
    </MyPageContainer>
  );
}
