'use client';

import { Button, ButtonColor, ButtonVariant } from "../Button/Button.mjs";
import { LocaleSwitcherContentProvider } from "../LocaleSwitcherContentDropDown/LocaleSwitcherContentContext.mjs";
import { Tab } from "../Tab/Tab.mjs";
import { ContentEditor } from "./ContentEditor.mjs";
import { DictionaryDetailsForm } from "./DictionaryDetails/DictionaryDetailsForm.mjs";
import { JSONEditor } from "./JSONEditor.mjs";
import { SaveForm } from "./SaveForm/SaveForm.mjs";
import { StructureEditor } from "./StructureEditor.mjs";
import { ArrowLeft } from "lucide-react";
import { useEffect } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
import { useIntlayer } from "react-intlayer";
import { useConfiguration, useDictionariesRecordActions, useFocusUnmergedDictionary } from "@intlayer/editor-react";

//#region src/components/DictionaryFieldEditor/DictionaryFieldEditor.tsx
const DictionaryFieldEditor = ({ dictionary, onClickDictionaryList, isDarkMode, mode, onDelete, onSave, showReturnButton = true }) => {
	const config = useConfiguration();
	const { returnToDictionaryList } = useIntlayer("dictionary-field-editor");
	const { setFocusedContent } = useFocusUnmergedDictionary();
	const { setLocaleDictionaries } = useDictionariesRecordActions();
	useEffect(() => {
		setFocusedContent((prev) => ({
			...prev ?? {},
			dictionaryKey: dictionary.key,
			dictionaryLocalId: dictionary.localId
		}));
		setLocaleDictionaries((prev) => ({
			...prev,
			[dictionary.localId]: dictionary
		}));
	}, []);
	return /* @__PURE__ */ jsx(LocaleSwitcherContentProvider, {
		availableLocales: config?.internationalization.locales ?? [],
		children: /* @__PURE__ */ jsxs("div", {
			className: "relative flex h-full min-h-0 w-full flex-1 flex-col overflow-hidden",
			children: [
				showReturnButton && /* @__PURE__ */ jsx(Button, {
					onClick: onClickDictionaryList,
					variant: ButtonVariant.HOVERABLE,
					className: "z-10 mr-auto ml-5 shrink-0",
					color: ButtonColor.TEXT,
					Icon: ArrowLeft,
					label: returnToDictionaryList.label.value,
					children: returnToDictionaryList.text
				}),
				/* @__PURE__ */ jsx("div", {
					className: "min-h-0 flex-1",
					children: /* @__PURE__ */ jsxs(Tab, {
						defaultTab: "content",
						variant: "ghost",
						fullHeight: true,
						headerClassName: "sticky top-0 z-10 rounded-xl bg-background/20 pb-4",
						children: [
							mode.includes("remote") && /* @__PURE__ */ jsx(Tab.Item, {
								label: "Details",
								value: "details",
								children: /* @__PURE__ */ jsx(DictionaryDetailsForm, {
									dictionary,
									mode
								})
							}),
							/* @__PURE__ */ jsx(Tab.Item, {
								label: "Structure",
								value: "structure",
								children: /* @__PURE__ */ jsx(StructureEditor, { dictionary })
							}),
							/* @__PURE__ */ jsx(Tab.Item, {
								label: "Content",
								value: "content",
								children: /* @__PURE__ */ jsx(ContentEditor, {
									dictionary,
									isDarkMode
								})
							}),
							/* @__PURE__ */ jsx(Tab.Item, {
								label: "JSON",
								value: "json",
								children: /* @__PURE__ */ jsx(JSONEditor, {
									dictionary,
									isDarkMode
								})
							})
						]
					})
				}),
				/* @__PURE__ */ jsx("div", {
					className: "shrink-0 border-card border-t p-4",
					children: /* @__PURE__ */ jsx(SaveForm, {
						dictionary,
						mode,
						onDelete: () => {
							setFocusedContent(null);
							onDelete?.();
						},
						onSave
					})
				})
			]
		})
	});
};

//#endregion
export { DictionaryFieldEditor };
//# sourceMappingURL=DictionaryFieldEditor.mjs.map