import { MyPageContainer } 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 ContractBill from '../components/ContractBill';
import Credit from '../components/Credit';
import GradeList from '../components/GradeList';
import Info from '../components/Info';
import RelatedPartyContract from '../components/RelatedPartyContract';
import Survey from '../components/Survey';

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

  const loadShow = () => {
    let paramsId: any = { id: id ?? 0 };
    Apis.CompanySupplier.CompanySuppliers.Show(paramsId).then((res) => {
      setShow(res?.data);
      // 更新标签页标题
      // if (res?.data?.full_name) {
      //   addTab({
      //     key: `supplier-outside-detail-${id}`,
      //     label: title,
      //     path: `/supplier/outside/show/${id}`,
      //   });
      // }
    });
  };

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

  let items = [
    {
      label: '基本信息',
      key: 'info',
      closable: false,
      children: <Info item={data} reload={() => loadShow()} />,
    },
    {
      label: '评级记录',
      key: 'grade',
      closable: false,
      children: (
        <GradeList
          item={{ ...data, company_suppliers_id: id }}
          reload={() => {
            loadShow();
          }}
        />
      ),
    },
    {
      label: '关联合同',
      key: 'contract',
      closable: false,
      children: (
        <RelatedPartyContract item={{ ...data, company_suppliers_id: id }} />
      ),
    },
    {
      label: '关联账单',
      key: 'bill',
      closable: false,
      children: <ContractBill item={{ ...data, company_suppliers_id: id }} />,
    },
    {
      label: '实地调查',
      key: 'survey',
      closable: false,
      children: <Survey item={{ ...data, company_suppliers_id: id }} />,
    },
    {
      label: '资信调查',
      key: 'credit',
      closable: false,
      children: <Credit item={{ ...data, company_suppliers_id: id }} />,
    },
  ];

  return (
    <MyPageContainer
      title={`${data?.name || title}详情`}
      enableTabs={true}
      tabKey={`supplier-outside-detail-${id}`}
      tabLabel={`${data?.name || title}详情`}
    >
      {/* <Info item={data} reload={loadShow} /> */}
      <ProCard style={{ marginTop: 16 }}>
        <Tabs type="card" items={items} defaultActiveKey="1" />
      </ProCard>
    </MyPageContainer>
  );
}
