const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_locales = require("./locales.js");
const require_useLanguage = require("./hooks/useLanguage.js");
const require_store = require("./store/store.js");
const require_useStore = require("./hooks/useStore.js");
const require_useSymbol = require("./hooks/useSymbol.js");
const require_index = require("../../pro/Selector/index.js");
const require_transformBundleGroup = require("./utils/transformBundleGroup.js");
const require_transformOptionGroup = require("./utils/transformOptionGroup.js");
const require_transformVariantGroup = require("./utils/transformVariantGroup.js");
const require_transformValueToSelectorValue = require("./utils/transformValueToSelectorValue.js");
const require_transformSelectorValueToValue = require("./utils/transformSelectorValueToValue.js");
const require_actions = require("./store/actions.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
require("./index.less");
//#region src/plus/skuOptionsSelection/index.tsx
const SelectorGroup = require_index.default.Group;
const SKUOptionsSelection = (0, react.forwardRef)((props, ref) => {
	const language = require_useLanguage.default();
	const symbol = require_useSymbol.default();
	_pisell_utils.locales.init(require_locales.default, language);
	const selectorGroupRef = (0, react.useRef)(null);
	const selectorDataSource = require_useStore.default((s) => s.selectorDataSource);
	const selectorValue = require_useStore.default((s) => s.selectorValue);
	(0, react.useImperativeHandle)(ref, () => {
		return {
			validate: () => {
				var _selectorGroupRef$cur;
				return (_selectorGroupRef$cur = selectorGroupRef.current) === null || _selectorGroupRef$cur === void 0 ? void 0 : _selectorGroupRef$cur.validate();
			},
			getValues: () => {
				var _selectorGroupRef$cur2;
				return (_selectorGroupRef$cur2 = selectorGroupRef.current) === null || _selectorGroupRef$cur2 === void 0 ? void 0 : _selectorGroupRef$cur2.getValues();
			},
			getTransformValues: () => {
				const _values = require_store.default.getState().selectorValue;
				return require_transformSelectorValueToValue.transformSelectorValueToValue(_values);
			}
		};
	});
	(0, react.useEffect)(() => {
		require_actions.default.updateSymbol(symbol);
	}, [symbol]);
	(0, react.useEffect)(() => {
		require_actions.default.updateConfig((props === null || props === void 0 ? void 0 : props.config) || {});
	}, [props === null || props === void 0 ? void 0 : props.config]);
	(0, react.useEffect)(() => {
		if (props === null || props === void 0 ? void 0 : props.skuCardConfig) require_actions.default.updateSkuCardConfig(props.skuCardConfig);
	}, [props === null || props === void 0 ? void 0 : props.skuCardConfig]);
	(0, react.useEffect)(() => {
		require_actions.default.updateCustomConfig((props === null || props === void 0 ? void 0 : props.customConfig) || {});
	}, [props === null || props === void 0 ? void 0 : props.customConfig]);
	(0, react.useEffect)(() => {
		require_actions.default.updateDataSource((props === null || props === void 0 ? void 0 : props.dataSource) || {});
	}, [props === null || props === void 0 ? void 0 : props.dataSource]);
	(0, react.useEffect)(() => {
		require_actions.default.updateValue((props === null || props === void 0 ? void 0 : props.value) || {});
	}, [props === null || props === void 0 ? void 0 : props.value]);
	(0, react.useEffect)(() => {
		const _transformValues = require_transformValueToSelectorValue.transformValueToSelectorValue((props === null || props === void 0 ? void 0 : props.value) || null, (props === null || props === void 0 ? void 0 : props.dataSource) || null);
		require_actions.default.updateSelectorValue(_transformValues);
	}, [props === null || props === void 0 ? void 0 : props.value, props === null || props === void 0 ? void 0 : props.dataSource]);
	(0, react.useEffect)(() => {
		var _props$dataSource, _props$dataSource3, _props$dataSource5;
		const _groupDataSource = [];
		if (props === null || props === void 0 || (_props$dataSource = props.dataSource) === null || _props$dataSource === void 0 ? void 0 : _props$dataSource.variant_group) {
			var _props$dataSource2;
			const renderVariantGroup = require_transformVariantGroup.transformVariantGroup(props === null || props === void 0 || (_props$dataSource2 = props.dataSource) === null || _props$dataSource2 === void 0 ? void 0 : _props$dataSource2.variant_group);
			_groupDataSource.push(...renderVariantGroup);
		}
		if (props === null || props === void 0 || (_props$dataSource3 = props.dataSource) === null || _props$dataSource3 === void 0 ? void 0 : _props$dataSource3.option_group) {
			var _props$dataSource4;
			const renderOptionGroup = require_transformOptionGroup.transformOptionGroup(props === null || props === void 0 || (_props$dataSource4 = props.dataSource) === null || _props$dataSource4 === void 0 ? void 0 : _props$dataSource4.option_group);
			_groupDataSource.push(...renderOptionGroup);
		}
		if (props === null || props === void 0 || (_props$dataSource5 = props.dataSource) === null || _props$dataSource5 === void 0 ? void 0 : _props$dataSource5.bundle_group) {
			var _props$dataSource6;
			const renderBundleGroup = require_transformBundleGroup.transformBundleGroup(props === null || props === void 0 || (_props$dataSource6 = props.dataSource) === null || _props$dataSource6 === void 0 ? void 0 : _props$dataSource6.bundle_group);
			_groupDataSource.push(...renderBundleGroup);
		}
		require_actions.default.updateSelectorDataSource(_groupDataSource);
	}, [props === null || props === void 0 ? void 0 : props.dataSource]);
	(0, react.useEffect)(() => {
		return () => {
			var _selectorGroupRef$cur3, _selectorGroupRef$cur4;
			(_selectorGroupRef$cur3 = selectorGroupRef.current) === null || _selectorGroupRef$cur3 === void 0 || (_selectorGroupRef$cur4 = _selectorGroupRef$cur3.clear) === null || _selectorGroupRef$cur4 === void 0 || _selectorGroupRef$cur4.call(_selectorGroupRef$cur3);
			require_actions.default.clearStore();
		};
	}, []);
	return /* @__PURE__ */ react.default.createElement(SelectorGroup, {
		ref: selectorGroupRef,
		dataSource: selectorDataSource,
		value: selectorValue,
		onChange: (values) => {
			var _props$onChange;
			console.log("selector_onChange_values>>>>>>>", values);
			require_actions.default.updateSelectorValue(values);
			const transformValue = require_transformSelectorValueToValue.transformSelectorValueToValue(values);
			console.log("selector_onChange_transformValue>>>>>>>", transformValue);
			props === null || props === void 0 || (_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, transformValue);
		},
		style: props === null || props === void 0 ? void 0 : props.style,
		customScrollParent: props === null || props === void 0 ? void 0 : props.customScrollParent,
		theme: props === null || props === void 0 ? void 0 : props.theme
	});
});
//#endregion
exports.default = SKUOptionsSelection;
