/* Copyright 2025 New Vector Ltd. SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial Please see LICENSE files in the repository root for full details. */ import React, { type ComponentType, type JSX, useCallback } from "react"; import { type DialogProps, type DialogOptions, type DialogHandle } from "@element-hq/element-web-module-api"; import Modal from "../Modal"; import BaseDialog from "../components/views/dialogs/BaseDialog.tsx"; const OuterDialog = ({ title, Dialog, props, onFinished, }: { title: string; Dialog: ComponentType & P>; props: P; onFinished(this: void, ok: boolean, model: M | null): void; }): JSX.Element => { const close = useCallback(() => onFinished(false, null), [onFinished]); const submit = useCallback((model: M) => onFinished(true, model), [onFinished]); return ( ); }; export function openDialog( initialOptions: DialogOptions, Dialog: ComponentType

>, props: P, ): DialogHandle { const { close, finished } = Modal.createDialog(OuterDialog, { title: initialOptions.title, Dialog, props, }); return { finished: finished.then(([ok, model]) => ({ ok: ok ?? false, model: model ?? null, })), close: () => close(false, null), }; }