import React from 'react'
import GrentReducer from './grent'
import Upload from '../../components/Upload'
import styles from './index.module.css'
import { useRouteMatch } from 'react-router-dom'


export default function ModelList({ className }: any) {
  const match = useRouteMatch()
  const sid = (match?.params as any).sid
  
  const { referData, Element, models } = GrentReducer({
    delUrl: '/cesium/model/remove/',
    getUrl: '/cesium/model/list',
    zipUrl: '/cesium/model/unzip/',
    sectionUrl: '/cesium/model/slice/',
    transferUrl: '/cesium/model/publish'
  })

  for (let i = 0; i < models.length; i++) {
    let model = models[i] as Model
    if (model.status !== 6) continue
    setTimeout(() => referData(), 1000)
    break;
  }

  return (
    <div className={className}>
      <div className={styles.uplayer} >
        <Upload api='/cesium/model/upload' 
          // check='/fdModel/check/' 
          body={{sceneId: sid}} upHandle={referData} className={styles.inputitem} />
      </div>
      {Element}
    </div>
  )
}