import React from 'react'
import { PostFrom, usePostFromArgs } from './component'
import { useDispatch } from '../../store'
import { updateScene, Scene } from '../../store/scene'
import { Modal } from 'antd'


export const EditScene = ({onClose, ...scene}: {onClose: () => void} & Scene) => {
  console.log(scene)
  const dispatch = useDispatch()
  const postFromArgs = usePostFromArgs(async nscene => {
    const action = updateScene({
      ...scene,
      ...nscene
    })
    await dispatch(action).unwrap()
    onClose()
    return false
  }, scene)

  return (
    <Modal 
      title="更新场景" 
      okText='修改'
      cancelText='取消'
      visible={true} 
      onOk={postFromArgs.onSubmit} 
      onCancel={onClose}>
      <PostFrom {...postFromArgs} />
    </Modal>
  )
}