import React, { useEffect, useState } from 'react'
import styles from './index.module.scss'
import { rowArrTemp } from '@/pages/Zother/data'
import { InfoProvider } from '@/pages/Zother/InfoContext'
import EditTop from '@/pages/Zother/EditTop'
import { G1_APIgetClueList, G1API_obj } from '@/store/action/Gmaintain/G1accident'
import EditBtn from '@/pages/Zother/EditBtn'
import { G1moreList, getPanDianListFu } from '../data'
import FileArchive from '@/pages/Zother/FileArchive'

const rowArr = [
  {
    name: `事故登记`,
    type: 'txt'
  },
  ...rowArrTemp('事故', undefined, '事故登记').slice(1)
]

function G1edit() {
  const [info, setInfo] = useState<any>({ list: [], loding: false })

  useEffect(() => {
    getPanDianListFu(
      list => {
        setInfo({ list, loding: true })
      },
      list => G1moreList(list)
    )
  }, [])

  return (
    <>
      {info.loding ? (
        <InfoProvider>
          <div className={styles.B3edit} id='editBox'>
            <div className='editMain'>
              {/* 顶部 */}
              <EditTop
                pageTxt='事故登记'
                rowArr={rowArr}
                APIobj={G1API_obj}
                fileUpInfo={{ myUrl: 'cms/orderAccident/upload', dirCode: 'accident' }}
                // 第二个模块
                moreDom={{
                  txt: '事故报告',
                  API: G1_APIgetClueList,
                  domList: info.list,
                  myUrl: 'cms/orderAccident/son/upload',
                  dirCode: 'accidentSon'
                }}
              />

              {/* 附件归档 */}
              <FileArchive />

              {/* 底部按钮 */}
              <EditBtn
                path='/accident'
                APIobj={G1API_obj}
                checkListTxt='请选择关联藏品'
                isTow={true}
              />
            </div>
          </div>
        </InfoProvider>
      ) : null}
    </>
  )
}

const MemoG1edit = React.memo(G1edit)

export default MemoG1edit
