import { InputNumber, Modal, Tag } from 'antd'
import React, { useEffect, useState } from 'react'
import { useModel } from 'umi'


interface Props {
    isAll?: boolean
}
function SortModal(props: Props) {
    const { isAll } = props
    const { state, offEditFile, configSort, listImg, listVideo, set } = useModel(isAll ? 'useLaunchAdq.useBdMedia' : 'useLaunchAdq.useBdMediaPup')
    const { sortVisible, actionItem } = state
    const [sort, setSort] = useState<number>(0)

    useEffect(() => {
        setSort(actionItem?.sort || 0)
    }, [actionItem?.sort])

    const sortHandle = () => {
        configSort.run({ sysMediaId: actionItem?.id, sort: sort, mediaType: state?.mediaType }).then(res => {
            if (res) {
                if (state?.mediaType === 'IMG') {
                    listImg.refresh()
                } else if (state?.mediaType === 'VIDEO') {
                    listVideo.refresh()
                }
                set({ sortVisible: false, actionItem: null })
            }
        })
    }

    return <Modal
        open={sortVisible}
        width={400}
        title={'编辑排序'}
        closable={false}
        onOk={sortHandle}
        onCancel={() => { offEditFile() }}
    >
        <Tag color='warning'>数值越大越靠前</Tag>
        <InputNumber
            style={{ width: '100%', marginTop: 10 }}
            value={sort}
            placeholder='请输入序号, 数值越大越靠前'
            onChange={(e) => {
                setSort(e || 0)
            }}
        />
    </Modal>
}
export default SortModal