{
  "version": 3,
  "sources": ["../../../src/components/widget-settings/use-widget-settings-toggle.ts"],
  "sourcesContent": ["import { useCallback } from '@wordpress/element';\nimport { useDashboardInternalContext } from '../../context/dashboard-context';\nimport { useDashboardUIContext } from '../../context/ui-context';\nimport type { DashboardWidget } from '../../types';\n\ninterface WidgetSettingsToggle {\n\t/**\n\t * Whether this instance's settings surface is the open one.\n\t */\n\tisOpen: boolean;\n\n\t/**\n\t * Opens the settings surface for this instance.\n\t */\n\topen: () => void;\n\n\t/**\n\t * Closes the surface when this instance already owns it (discarding\n\t * staged edits), opens it otherwise.\n\t */\n\ttoggle: () => void;\n}\n\n/**\n * Shared open/close logic for an instance's settings surface. The surface is\n * mounted once at the dashboard root and reacts to the `uuid` written into\n * the UI context; controls drive it through this hook.\n *\n * @param {DashboardWidget< unknown >} widget The instance whose settings surface the control drives.\n */\nexport function useWidgetSettingsToggle(\n\twidget: DashboardWidget< unknown >\n): WidgetSettingsToggle {\n\tconst { settingsWidgetUuid, setSettingsWidgetUuid } =\n\t\tuseDashboardUIContext();\n\tconst { cancel, flushAutoSave } = useDashboardInternalContext();\n\n\tconst isOpen = settingsWidgetUuid === widget.uuid;\n\n\tconst open = useCallback( () => {\n\t\t// Persist any pending prominent-surface edit before opening, so the\n\t\t// settings surface's edits stay isolated and its Cancel discards only\n\t\t// its own changes.\n\t\tflushAutoSave();\n\t\tsetSettingsWidgetUuid( widget.uuid );\n\t}, [ flushAutoSave, setSettingsWidgetUuid, widget.uuid ] );\n\n\tconst toggle = useCallback( () => {\n\t\t// Re-clicking the open instance's control closes the settings surface,\n\t\t// discarding staged edits like any other non-Save exit.\n\t\tif ( isOpen ) {\n\t\t\tcancel();\n\t\t\tsetSettingsWidgetUuid( null );\n\t\t\treturn;\n\t\t}\n\t\topen();\n\t}, [ isOpen, cancel, setSettingsWidgetUuid, open ] );\n\n\treturn { isOpen, open, toggle };\n}\n"],
  "mappings": ";AAAA,SAAS,mBAAmB;AAC5B,SAAS,mCAAmC;AAC5C,SAAS,6BAA6B;AA4B/B,SAAS,wBACf,QACuB;AACvB,QAAM,EAAE,oBAAoB,sBAAsB,IACjD,sBAAsB;AACvB,QAAM,EAAE,QAAQ,cAAc,IAAI,4BAA4B;AAE9D,QAAM,SAAS,uBAAuB,OAAO;AAE7C,QAAM,OAAO,YAAa,MAAM;AAI/B,kBAAc;AACd,0BAAuB,OAAO,IAAK;AAAA,EACpC,GAAG,CAAE,eAAe,uBAAuB,OAAO,IAAK,CAAE;AAEzD,QAAM,SAAS,YAAa,MAAM;AAGjC,QAAK,QAAS;AACb,aAAO;AACP,4BAAuB,IAAK;AAC5B;AAAA,IACD;AACA,SAAK;AAAA,EACN,GAAG,CAAE,QAAQ,QAAQ,uBAAuB,IAAK,CAAE;AAEnD,SAAO,EAAE,QAAQ,MAAM,OAAO;AAC/B;",
  "names": []
}
