import { MyPageContainer } from '@/common';
import { Apis } from '@/gen/Apis';

import { useNavigate, useParams, useSearchParams } from '@umijs/max';
import { Space, Tabs, TabsProps } from 'antd';
import { useEffect, useState } from 'react';
import MyArchivingLogs from './components/ArchivingLogs';
import MyContractBillObjects from './components/ContractBillObjects';
import MyContractBills from './components/ContractBills';
import ContractDisputeRecords from './components/ContractDisputeRecords';
import ContractsAdd from './components/ContractsAdd';
import MyContractsInfo from './components/ContractsInfo';
import MyUsedLogs from './components/UsedLogs';

export default function Index({ title = '合同详情' }) {
  const navigate = useNavigate();
  const { id } = useParams<{ id: string }>();
  const [showData, setDataShow] = useState<any>({});
  const [searchParams] = useSearchParams();
  const activeKey = searchParams?.get('key') || '1';

  const items: TabsProps['items'] = [
    {
      key: '1',
      label: '基本信息',
      children: <MyContractsInfo item={showData} />,
    },
    {
      key: '2',
      label: '用印记录',
      children: <MyUsedLogs item={showData} />,
    },
    {
      key: '4',
      label: '合同账单',
      children: <MyContractBills item={{ ...showData, id: Number(id) }} />,
    },
    {
      key: '3',
      label: '合同标的',
      children: <MyContractBillObjects item={showData} />,
    },
    {
      key: '5',
      label: '归档记录',
      children: <MyArchivingLogs item={showData} />,
    },
    {
      key: '6',
      label: '争议处理记录',
      children: <ContractDisputeRecords item={{ id: Number(id) }} />,
    },
    {
      key: '7',
      label: '补充协议',
      children: <ContractsAdd item={{ id: Number(id) }} />,
    },
  ];
  const loadShow = () => {
    Apis.Contract.Contracts.Show({ id: Number(id) }).then((res) => {
      setDataShow(res?.data);
    });
  };

  useEffect(() => {
    loadShow();
  }, [id]);
  return (
    <MyPageContainer
      title={
        <Space
          style={{ cursor: 'pointer' }}
          onClick={() => {
            navigate(-1);
          }}
        >
          {/* <LeftCircleOutlined size={34} /> */}
          {title}
        </Space>
      }
      enableTabs={false}
      tabKey="charge-standards-create"
      tabLabel={title}
    >
      <Space direction="vertical" style={{ width: '100%' }}>
        <Tabs type="card" items={items} defaultActiveKey={activeKey} />
      </Space>
    </MyPageContainer>
  );
}
