import { ManagedDialogDefine, ManagedDialogDict } from "./types"


export default function ManagedDialogsLayer({ dialogDefine, dialogs,closeDialog }:{
  dialogDefine:ManagedDialogDefine,
  dialogs:ManagedDialogDict
  closeDialog:(type:string)=>void
}) {

  const list: JSX.Element[] = []

  for (const [k, d] of Object.entries(dialogDefine)) {
    const dialogType = k 
    const Dialog = d
    const props = dialogs[dialogType]
    if (props) {
      list.push(
        <Dialog key={dialogType} onCancel={() => closeDialog(dialogType)} {...props} />,
      )
    }
  }

  return <>{list}</>
}
