import HocError from '@/Hoc/HocError'
import React, { useMemo } from 'react'
import { useModel } from 'umi'
import TableData from '../../components/TableData'
import { columns } from './tableConfig'


/**投手投放号 */
function Page() {
    const { state: { dataSource }, getPitcherChannel } = useModel('useData.useTableData')

    
    //加工数据
    const data = useMemo(() => {
        if (dataSource) {
            return dataSource?.map((item: any, index: number) => {
                item['id'] = index
                return item
            })
        }
        return []
    }, [dataSource])


    const sortArr = useMemo(() => {
        let arr: any[] = []
        columns().map((item: any) => {
            if (typeof item.title === 'string') {
                arr.push({ title: item.title, value: item.dataIndex ,key:item.dataIndex })
            }
            if(typeof item.title === 'object' && typeof  item.title.props.children[0] === 'string' ){
                arr.push({ title: item.title, value: item.dataIndex ,key:item.dataIndex })
            }
        })
        return arr
    }, [columns])

  
    return <>
        <TableData
            ajax={getPitcherChannel}
            isTableId
            isLocation
            isZj
            isAdmin
            isUserId
            isDownload
            isDataSelectPitcher
            isSelctAcc
            isTableDateArr
            columns={columns}
            isGroupTab={false}
            sortArr={sortArr}
            dataSource={data}
            title='投手投放号'
            scroll={{ x: 1000, y: 600 }}
        />
    </>
}

export default HocError(Page)