import { AuthMethodType } from "./types.js";
import locales_default from "./locales.js";
import EmailSettingsContent from "./components/EmailSettingsContent.js";
import PhoneSettingsContent from "./components/PhoneSettingsContent.js";
import DefaultSettingsContent from "./components/DefaultSettingsContent.js";
import PasswordRulesSettingsContent from "./components/PasswordRulesSettingsContent.js";
import React from "react";
import { Button, Drawer } from "antd";
import { locales } from "@pisell/utils";
import "./SettingsDrawer.less";
//#region src/components/authentication/admin/AuthMethods/SettingsDrawer.tsx
locales.init(locales_default, localStorage.getItem("umi_locale") || "en");
const SettingsDrawer = ({ open, method, onClose, onSave, mode = "auth-methods", initialSettings }) => {
	const [currentSettings, setCurrentSettings] = React.useState(null);
	const handleSave = () => {
		if (currentSettings) onSave === null || onSave === void 0 || onSave(currentSettings);
		onClose();
	};
	const handleCancel = () => {
		onClose();
	};
	const getDrawerTitle = () => {
		if (!method) return locales.getText("auth.email.settings");
		if (method.type === AuthMethodType.EMAIL) return locales.getText("auth.email.settings");
		if (method.type === AuthMethodType.PHONE) return locales.getText("auth.phone.settings");
		if (method.type === AuthMethodType.PASSWORD_RULES) return locales.getText("auth.password.settings");
		return `${method.title} Settings`;
	};
	const handleSettingsChange = (settings) => {
		setCurrentSettings(settings);
		console.log("Settings changed:", settings);
	};
	const renderContent = () => {
		if (!method) return null;
		switch (method.type) {
			case AuthMethodType.EMAIL: return /* @__PURE__ */ React.createElement(EmailSettingsContent, {
				initialSettings,
				onSettingsChange: handleSettingsChange
			});
			case AuthMethodType.PHONE: return /* @__PURE__ */ React.createElement(PhoneSettingsContent, {
				initialSettings,
				onSettingsChange: handleSettingsChange
			});
			case AuthMethodType.PASSWORD_RULES: return /* @__PURE__ */ React.createElement(PasswordRulesSettingsContent, {
				initialSettings,
				onSettingsChange: handleSettingsChange
			});
			default:
				if (mode === "setting-list") return /* @__PURE__ */ React.createElement("div", { className: "settings-section" }, /* @__PURE__ */ React.createElement("div", {
					className: "settings-section-description",
					style: {
						padding: "20px 0",
						color: "#8c8c8c"
					}
				}, locales.getText("auth.settings.no.additional")));
				return /* @__PURE__ */ React.createElement(DefaultSettingsContent, {
					method,
					onSettingsChange: handleSettingsChange
				});
		}
	};
	return /* @__PURE__ */ React.createElement(Drawer, {
		title: getDrawerTitle(),
		placement: "right",
		width: 640,
		open,
		onClose: handleCancel,
		maskClosable: true,
		keyboard: true,
		footer: /* @__PURE__ */ React.createElement("div", { className: "drawer-footer" }, /* @__PURE__ */ React.createElement(Button, { onClick: handleCancel }, locales.getText("auth.button.cancel")), /* @__PURE__ */ React.createElement(Button, {
			type: "primary",
			onClick: handleSave,
			style: { marginLeft: 8 }
		}, locales.getText("auth.button.save")))
	}, /* @__PURE__ */ React.createElement("div", {
		className: "settings-drawer-content",
		onClick: (e) => e.stopPropagation()
	}, renderContent()));
};
//#endregion
export { SettingsDrawer as default };
