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

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

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

  const loadShow = () => {
    let paramsId: any = { id: id ?? 0 };
    Apis.Renovation.RenovationApplies.Show(paramsId).then((res) => {
      setShow(res?.data);
      // if (res?.data?.asset_house?.full_name) {
      //   addTab({
      //     key: `renovation_applies_config_${id}`,
      //     label: `${res?.data?.asset_house?.full_name}_装修配置_${id}`,
      //     path: `/renovation/show/${id}`,
      //   });
      // }
    });
  };

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

  let items = [
    {
      label: '装修工人',
      key: '1',
      closable: false,
      children: <MyRenovationWorkers item={{ id: id }} />,
    },
  ];
  return (
    <MyPageContainer title={title}>
      <Tabs type="card" items={items} size="small" />
    </MyPageContainer>
  );
}
