var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/plus/skuOptionsSelection/index.tsx
var skuOptionsSelection_exports = {};
__export(skuOptionsSelection_exports, {
  default: () => skuOptionsSelection_default
});
module.exports = __toCommonJS(skuOptionsSelection_exports);
var import_react = __toESM(require("react"));
var import_utils = require("@pisell/utils");
var import_locales = __toESM(require("./locales"));
var import_stock = __toESM(require("../../shared/locales/stock"));
var import_hooks = require("./hooks");
var import_Selector = __toESM(require("../../pro/Selector"));
var import_utils2 = require("./utils");
var import_store = require("./store");
var import_index = require("./index.less");
var SelectorGroup = import_Selector.default.Group;
var SKUOptionsSelection = (0, import_react.forwardRef)((props, ref) => {
  const language = (0, import_hooks.useLanguage)();
  const symbol = (0, import_hooks.useSymbol)();
  import_utils.locales.init(import_locales.default, language);
  import_utils.locales.init(import_stock.default, language);
  const selectorGroupRef = (0, import_react.useRef)(null);
  const selectorDataSource = (0, import_hooks.useStore)((s) => s.selectorDataSource);
  const selectorValue = (0, import_hooks.useStore)((s) => s.selectorValue);
  (0, import_react.useImperativeHandle)(ref, () => {
    return {
      validate: () => {
        var _a;
        return (_a = selectorGroupRef.current) == null ? void 0 : _a.validate();
      },
      getValues: () => {
        var _a;
        return (_a = selectorGroupRef.current) == null ? void 0 : _a.getValues();
      },
      getTransformValues: () => {
        const _values = import_store.store.getState().selectorValue;
        return (0, import_utils2.transformSelectorValueToValue)(_values);
      }
    };
  });
  (0, import_react.useEffect)(() => {
    import_store.actions.updateSymbol(symbol);
  }, [symbol]);
  (0, import_react.useEffect)(() => {
    import_store.actions.updateConfig((props == null ? void 0 : props.config) || {});
  }, [props == null ? void 0 : props.config]);
  (0, import_react.useEffect)(() => {
    if (props == null ? void 0 : props.skuCardConfig) {
      import_store.actions.updateSkuCardConfig(props.skuCardConfig);
    }
  }, [props == null ? void 0 : props.skuCardConfig]);
  (0, import_react.useEffect)(() => {
    import_store.actions.updateCustomConfig((props == null ? void 0 : props.customConfig) || {});
  }, [props == null ? void 0 : props.customConfig]);
  (0, import_react.useEffect)(() => {
    import_store.actions.updateDataSource((props == null ? void 0 : props.dataSource) || {});
  }, [props == null ? void 0 : props.dataSource]);
  (0, import_react.useEffect)(() => {
    import_store.actions.updateValue((props == null ? void 0 : props.value) || {});
  }, [props == null ? void 0 : props.value]);
  (0, import_react.useEffect)(() => {
    const _transformValues = (0, import_utils2.transformValueToSelectorValue)(
      (props == null ? void 0 : props.value) || null,
      (props == null ? void 0 : props.dataSource) || null
    );
    import_store.actions.updateSelectorValue(_transformValues);
  }, [props == null ? void 0 : props.value, props == null ? void 0 : props.dataSource]);
  (0, import_react.useEffect)(() => {
    var _a, _b, _c, _d, _e, _f;
    const _groupDataSource = [];
    if ((_a = props == null ? void 0 : props.dataSource) == null ? void 0 : _a.variant_group) {
      const renderVariantGroup = (0, import_utils2.transformVariantGroup)(
        (_b = props == null ? void 0 : props.dataSource) == null ? void 0 : _b.variant_group
      );
      _groupDataSource.push(...renderVariantGroup);
    }
    if ((_c = props == null ? void 0 : props.dataSource) == null ? void 0 : _c.option_group) {
      const renderOptionGroup = (0, import_utils2.transformOptionGroup)(
        (_d = props == null ? void 0 : props.dataSource) == null ? void 0 : _d.option_group
      );
      _groupDataSource.push(...renderOptionGroup);
    }
    if ((_e = props == null ? void 0 : props.dataSource) == null ? void 0 : _e.bundle_group) {
      const renderBundleGroup = (0, import_utils2.transformBundleGroup)(
        (_f = props == null ? void 0 : props.dataSource) == null ? void 0 : _f.bundle_group
      );
      _groupDataSource.push(...renderBundleGroup);
    }
    import_store.actions.updateSelectorDataSource(_groupDataSource);
  }, [props == null ? void 0 : props.dataSource]);
  (0, import_react.useEffect)(() => {
    return () => {
      var _a, _b;
      (_b = (_a = selectorGroupRef.current) == null ? void 0 : _a.clear) == null ? void 0 : _b.call(_a);
      import_store.actions.clearStore();
    };
  }, []);
  return /* @__PURE__ */ import_react.default.createElement(
    SelectorGroup,
    {
      ref: selectorGroupRef,
      dataSource: selectorDataSource,
      value: selectorValue,
      onChange: (values) => {
        var _a;
        console.log("selector_onChange_values>>>>>>>", values);
        import_store.actions.updateSelectorValue(values);
        const transformValue = (0, import_utils2.transformSelectorValueToValue)(values);
        console.log("selector_onChange_transformValue>>>>>>>", transformValue);
        (_a = props == null ? void 0 : props.onChange) == null ? void 0 : _a.call(props, transformValue);
      },
      style: props == null ? void 0 : props.style,
      customScrollParent: props == null ? void 0 : props.customScrollParent
    }
  );
});
var skuOptionsSelection_default = SKUOptionsSelection;
