{"version":3,"sources":["../components/widgets/dialog-manager/provider.tsx"],"sourcesContent":["\"use client\";\nimport * as React from 'react';\nimport { useState, useCallback } from 'react';\nimport { DialogContext } from './context';\nimport { TypedDialogComponent } from './types';\n\ntype DialogEntry = {\n  id: number;\n  Component: TypedDialogComponent<any, any>;\n  args: any;\n  resolve: (value: any) => void;\n};\n\nlet dialogId = 0;\n\nexport function DialogProvider({ children }: { children: React.ReactNode }) {\n  const [dialogs, setDialogs] = useState<DialogEntry[]>([]);\n\n  const openDialog = useCallback(<A, R>(Component: TypedDialogComponent<A, R>, args: A): Promise<R> => {\n    return new Promise<R>((resolve) => {\n      const id = ++dialogId;\n      setDialogs((prev) => [...prev, { id, Component, args, resolve }]);\n    });\n  }, []);\n\n  const handleClose = useCallback((id: number, result: any) => {\n    setDialogs((prev) => {\n      const entry = prev.find((d) => d.id === id);\n      if (entry) entry.resolve(result);\n      return prev.filter((d) => d.id !== id);\n    });\n  }, []);\n\n  return (\n    <DialogContext.Provider value={{ openDialog }}>\n      {children}\n\n      {dialogs.map(({ id, Component, args }) => (\n        <Component key={id} open={true} args={args} onClose={(result: any) => handleClose(id, result)} />\n      ))}\n    </DialogContext.Provider>\n  );\n}\n"],"mappings":";;;;;AACA,YAAY,WAAW;AACvB,SAAS,UAAU,mBAAmB;AAWtC,IAAI,WAAW;AAER,SAAS,eAAe,EAAE,SAAS,GAAkC;AAC1E,QAAM,CAAC,SAAS,UAAU,IAAI,SAAwB,CAAC,CAAC;AAExD,QAAM,aAAa,YAAY,CAAO,WAAuC,SAAwB;AACnG,WAAO,IAAI,QAAW,CAAC,YAAY;AACjC,YAAM,KAAK,EAAE;AACb,iBAAW,CAAC,SAAS,CAAC,GAAG,MAAM,EAAE,IAAI,WAAW,MAAM,QAAQ,CAAC,CAAC;AAAA,IAClE,CAAC;AAAA,EACH,GAAG,CAAC,CAAC;AAEL,QAAM,cAAc,YAAY,CAAC,IAAY,WAAgB;AAC3D,eAAW,CAAC,SAAS;AACnB,YAAM,QAAQ,KAAK,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE;AAC1C,UAAI,MAAO,OAAM,QAAQ,MAAM;AAC/B,aAAO,KAAK,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE;AAAA,IACvC,CAAC;AAAA,EACH,GAAG,CAAC,CAAC;AAEL,SACE,oCAAC,cAAc,UAAd,EAAuB,OAAO,EAAE,WAAW,KACzC,UAEA,QAAQ,IAAI,CAAC,EAAE,IAAI,WAAW,KAAK,MAClC,oCAAC,aAAU,KAAK,IAAI,MAAM,MAAM,MAAY,SAAS,CAAC,WAAgB,YAAY,IAAI,MAAM,GAAG,CAChG,CACH;AAEJ;","names":[]}