import {
    inject,
    observer
} from 'mobx-react'
import {
    WeaTableNew
} from 'comsMobx'
const WeaTable = WeaTableNew.WeaTable;

@inject('hrmRecruitLibrary') //todo
@observer
export default class MainTable extends React.Component {
    constructor(props) {
        super(props);
    }

    componentDidMount() {
        this.props.hrmRecruitLibrary.getTableInfo();
    }

    componentDidUpdate(prevProps, prevState) {
        const {
            setSelectedRowKeys,
            hrmRecruitLibrary
        } = this.props, {
            mainTab
        } = hrmRecruitLibrary, {
            needTab
        } = mainTab;

        !needTab && setSelectedRowKeys([]);
    }

    reRenderColumns = (columns) => {
        const {
            hrmRecruitLibrary
        } = this.props, {
            openDialog,
            mainTable,
        } = hrmRecruitLibrary, {
            isEdit
        } = mainTable;

        isEdit && columns.map(c => {
            if (c.dataIndex == 'lastname') {
                c.render = (t, r) => {
                    return <a onClick={() => openDialog('1',r.randomFieldId)}>{r.lastnamespan}</a>
                }
            }
        })
    }

    render() {
        const {
            hrmRecruitLibrary,
            setSelectedRowKeys,
        } = this.props, {
            mainTable,
            onOperatesClick,
            mainTab,
        } = hrmRecruitLibrary, {
            tableStore
        } = mainTable, {
            needTab,
        } = mainTab;

        return (
            <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@3cqitp`} 
                comsWeaTableStore={tableStore}
                hasOrder={true}
                needScroll={true}
                rowSelection={!needTab && {
                    onChange: selectedRowKeys => setSelectedRowKeys(selectedRowKeys)
                }}
                getColumns={columns => this.reRenderColumns(columns)}
                onOperatesClick={(record, rowIndex, operate) => onOperatesClick(record, rowIndex, operate)}
            />
        )

    }
}