const require_runtime = require("../../../../../_virtual/_rolldown/runtime.js");
const require_asyncToGenerator = require("../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_useEngineContext = require("../../../../../hooks/useEngineContext.js");
const require_locales = require("./locales.js");
const require_index = require("../PageSettingItem/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
require("./PageSetting.less");
//#region src/components/authentication/admin/ChannelAuthSetting/PageSetting/index.tsx
const { Title, Paragraph } = antd.Typography;
const PageSetting = (0, react.forwardRef)(({ className, style, value, onChange, showRegisterPage = true, showImageUpload = true }, ref) => {
	var _context$engine;
	const context = require_useEngineContext.default();
	_pisell_utils.locales.init(require_locales.default, (context === null || context === void 0 || (_context$engine = context.engine) === null || _context$engine === void 0 || (_context$engine = _context$engine.props) === null || _context$engine === void 0 ? void 0 : _context$engine.locale) || "en");
	const registerPageRef = (0, react.useRef)(null);
	const loginPageRef = (0, react.useRef)(null);
	(0, react.useImperativeHandle)(ref, () => ({ validateFields: function() {
		var _ref = require_asyncToGenerator._asyncToGenerator(function* () {
			const promises = [];
			if (showRegisterPage && registerPageRef.current) promises.push(registerPageRef.current.validateFields());
			if ((!sameAsRegister || !showRegisterPage) && loginPageRef.current) promises.push(loginPageRef.current.validateFields());
			return Promise.all(promises);
		});
		return function validateFields() {
			return _ref.apply(this, arguments);
		};
	}() }));
	const [registerPageValue, setRegisterPageValue] = (0, react.useState)({
		backgroundImage: void 0,
		termsConditions: []
	});
	const [sameAsRegister, setSameAsRegister] = (0, react.useState)(true);
	const [loginPageValue, setLoginPageValue] = (0, react.useState)({
		backgroundImage: void 0,
		termsConditions: []
	});
	(0, react.useEffect)(() => {
		if (value) {
			var _value$loginPage$same, _value$loginPage;
			setRegisterPageValue(value.registerPage || {
				backgroundImage: void 0,
				termsConditions: []
			});
			setSameAsRegister((_value$loginPage$same = (_value$loginPage = value.loginPage) === null || _value$loginPage === void 0 ? void 0 : _value$loginPage.sameAsRegister) !== null && _value$loginPage$same !== void 0 ? _value$loginPage$same : true);
			setTimeout(() => {
				var _value$loginPage2;
				setLoginPageValue(((_value$loginPage2 = value.loginPage) === null || _value$loginPage2 === void 0 ? void 0 : _value$loginPage2.settings) || {
					backgroundImage: void 0,
					termsConditions: []
				});
			}, 0);
		}
	}, [value]);
	const handleRegisterPageChange = (val) => {
		onChange === null || onChange === void 0 || onChange({
			registerPage: val,
			loginPage: {
				sameAsRegister,
				settings: loginPageValue
			}
		});
	};
	const handleLoginPageChange = (val) => {
		onChange === null || onChange === void 0 || onChange({
			registerPage: registerPageValue,
			loginPage: {
				sameAsRegister,
				settings: val
			}
		});
	};
	const handleSameAsRegisterChange = (checked) => {
		onChange === null || onChange === void 0 || onChange({
			registerPage: registerPageValue,
			loginPage: {
				sameAsRegister: checked,
				settings: loginPageValue
			}
		});
	};
	return /* @__PURE__ */ react.default.createElement("div", {
		className: (0, classnames.default)("page-setting", className),
		style
	}, showRegisterPage && /* @__PURE__ */ react.default.createElement("div", { className: "page-setting-group" }, /* @__PURE__ */ react.default.createElement("div", { className: "page-setting-group-header" }, /* @__PURE__ */ react.default.createElement(Title, {
		level: 2,
		className: "page-setting-group-title"
	}, _pisell_utils.locales.getText("page.setting.register.title")), /* @__PURE__ */ react.default.createElement(Paragraph, { className: "page-setting-group-description" }, _pisell_utils.locales.getText("page.setting.register.description"))), /* @__PURE__ */ react.default.createElement("div", { className: "page-setting-group-content" }, /* @__PURE__ */ react.default.createElement(require_index.default, {
		ref: registerPageRef,
		value: registerPageValue,
		onChange: handleRegisterPageChange,
		showImageUpload
	}))), /* @__PURE__ */ react.default.createElement("div", { className: "page-setting-group" }, /* @__PURE__ */ react.default.createElement("div", { className: "page-setting-group-header" }, /* @__PURE__ */ react.default.createElement(Title, {
		level: 2,
		className: "page-setting-group-title"
	}, _pisell_utils.locales.getText("page.setting.login.title")), /* @__PURE__ */ react.default.createElement(Paragraph, { className: "page-setting-group-description" }, _pisell_utils.locales.getText("page.setting.login.description"))), /* @__PURE__ */ react.default.createElement("div", { className: "page-setting-group-content" }, showRegisterPage && /* @__PURE__ */ react.default.createElement("div", { className: "page-setting-checkbox" }, /* @__PURE__ */ react.default.createElement(antd.Checkbox, {
		checked: sameAsRegister,
		onChange: (e) => handleSameAsRegisterChange(e.target.checked)
	}, /* @__PURE__ */ react.default.createElement("div", { className: "page-setting-checkbox-label" }, /* @__PURE__ */ react.default.createElement("span", { className: "page-setting-checkbox-label-text" }, _pisell_utils.locales.getText("page.setting.login.sameAsRegister")), /* @__PURE__ */ react.default.createElement("span", { className: "page-setting-checkbox-label-description" }, _pisell_utils.locales.getText("page.setting.login.sameAsRegister.description"))))), (!sameAsRegister || !showRegisterPage) && /* @__PURE__ */ react.default.createElement(require_index.default, {
		ref: loginPageRef,
		value: loginPageValue,
		onChange: handleLoginPageChange,
		showImageUpload
	}))));
});
PageSetting.displayName = "PageSetting";
//#endregion
exports.default = PageSetting;
