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 BannerList from './components/BannerList';
import BannerSpaceInfo from './components/BannerSpaceInfo';

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

  // 注册当前页面为标签页
  const { addTab } = usePageTabs({
    tabKey: `banner-space-${id}`,
    tabLabel: data?.name || title || '广告位详情',
  });

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

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

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