{"version":3,"file":"useEditor.cjs","names":["IntlayerClientContext","isEnabled"],"sources":["../../../src/editor/useEditor.tsx"],"sourcesContent":["'use client';\n\nimport type { EditorStateManager } from '@intlayer/editor';\nimport { isEnabled } from '@intlayer/editor/isEnabled';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { useContext, useEffect, useRef } from 'react';\nimport { IntlayerClientContext } from '../client/IntlayerProvider';\n\n/**\n * Initializes the Intlayer editor client singleton when the editor is enabled.\n * Syncs the current locale from the Intlayer context into the editor manager so\n * the editor always knows which locale the app is displaying.\n */\nexport const useEditor = () => {\n  const { locale } = useContext(IntlayerClientContext) ?? {};\n  const managerRef = useRef<EditorStateManager | null>(null);\n\n  useEffect(() => {\n    if (process.env['INTLAYER_EDITOR_ENABLED'] === 'false' || !isEnabled)\n      return;\n\n    import('@intlayer/editor').then(({ initEditorClient }) => {\n      const manager = initEditorClient();\n      managerRef.current = manager;\n\n      if (locale) manager.currentLocale.set(locale as Locale);\n    });\n\n    return () => {\n      managerRef.current = null;\n      import('@intlayer/editor').then(({ stopEditorClient }) => {\n        stopEditorClient();\n      });\n    };\n  }, []);\n\n  useEffect(() => {\n    if (!locale || !managerRef.current) return;\n\n    managerRef.current.currentLocale.set(locale as Locale);\n  }, [locale]);\n};\n"],"mappings":";;;;;;;;;;;;;;AAaA,MAAa,kBAAkB;CAC7B,MAAM,EAAE,iCAAsBA,sDAAsB,IAAI,EAAE;CAC1D,MAAM,+BAA+C,KAAK;AAE1D,4BAAgB;AACd,MAAI,QAAQ,IAAI,+BAA+B,WAAW,CAACC,qCACzD;AAEF,SAAO,oBAAoB,MAAM,EAAE,uBAAuB;GACxD,MAAM,UAAU,kBAAkB;AAClC,cAAW,UAAU;AAErB,OAAI,OAAQ,SAAQ,cAAc,IAAI,OAAiB;IACvD;AAEF,eAAa;AACX,cAAW,UAAU;AACrB,UAAO,oBAAoB,MAAM,EAAE,uBAAuB;AACxD,sBAAkB;KAClB;;IAEH,EAAE,CAAC;AAEN,4BAAgB;AACd,MAAI,CAAC,UAAU,CAAC,WAAW,QAAS;AAEpC,aAAW,QAAQ,cAAc,IAAI,OAAiB;IACrD,CAAC,OAAO,CAAC"}