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/productSelect/ProductCard/SkuCard/components/CardCom/index.tsx
var CardCom_exports = {};
__export(CardCom_exports, {
  default: () => CardCom_default
});
module.exports = __toCommonJS(CardCom_exports);
var import_react = __toESM(require("react"));
var import_CardWrapper = __toESM(require("../CardWrapper"));
var import_Cover = __toESM(require("../Cover"));
var import_useDynamicComponents = require("../../hooks/useDynamicComponents");
var import_status = require("../../status");
var import_utils = require("@pisell/utils");
var import_locales = __toESM(require("../../locales"));
var import_useEngineContext = __toESM(require("../../../../../../hooks/useEngineContext"));
var import_Action = __toESM(require("../Action"));
var import_CardMoreText = __toESM(require("../CardMoreText"));
var import_WarningLists = __toESM(require("../WarningLists"));
var import_status2 = require("../../status");
var import_index = require("./index.less");
var CardCom = ({ props, className }) => {
  var _a, _b, _c, _d, _e, _f, _g, _h;
  const context = (0, import_useEngineContext.default)();
  const [isFold, setIsFold] = (0, import_react.useState)(false);
  import_utils.locales.init(
    import_locales.default,
    ((_b = (_a = context.appHelper.utils) == null ? void 0 : _a.storage) == null ? void 0 : _b.get("umi_locale")) || "en"
  );
  const {
    skuCardConfig,
    skuImageConfig,
    dataSource,
    skuActionConfig,
    skuTextConfig,
    style,
    rightStyle,
    onSelectCover,
    onSelectInfo
  } = props;
  const { renderComponents } = (0, import_useDynamicComponents.useDynamicComponents)();
  const { layoutDirection, displayMode, isFoldable } = skuCardConfig || ((_c = import_status2.productCardDefault) == null ? void 0 : _c.skuCardConfig) || {};
  const { isCover, height } = skuImageConfig || ((_d = import_status2.productCardDefault) == null ? void 0 : _d.skuImageConfig) || {};
  const { method } = skuActionConfig || ((_e = import_status2.productCardDefault) == null ? void 0 : _e.skuActionConfig) || {};
  const { paddingY, justifyContent, alignItems, slot } = (skuTextConfig == null ? void 0 : skuTextConfig.infoConfig) || ((_g = (_f = import_status2.productCardDefault) == null ? void 0 : _f.skuTextConfig) == null ? void 0 : _g.infoConfig) || {};
  const contentStyle = (0, import_react.useMemo)(() => {
    const isMinHeight = isCover && layoutDirection === "row" && displayMode !== "display_a1";
    return {
      minHeight: isMinHeight && !(rightStyle == null ? void 0 : rightStyle.minHeight) ? `${height}` : "auto",
      padding: `${paddingY}px 0`,
      alignItems: layoutDirection === "column" ? alignItems : "initial",
      justifyContent: (rightStyle == null ? void 0 : rightStyle.justifyContent) || justifyContent || "initial"
    };
  }, [
    paddingY,
    justifyContent,
    alignItems,
    isCover,
    height,
    layoutDirection,
    displayMode
  ]);
  const actionCom = (0, import_react.useCallback)(
    (key) => {
      if (displayMode === "display_a1") {
        return false;
      }
      if (key === "column") {
        if (layoutDirection === "column" && method === "button") {
          return /* @__PURE__ */ import_react.default.createElement(import_Action.default, { props, className: `${import_status.PREFIX}__card-action-custom` });
        }
        return false;
      }
      if (key === "row") {
        return (
          // 为了占位
          /* @__PURE__ */ import_react.default.createElement("div", { style: { opacity: layoutDirection === "column" ? 0 : 1 } }, /* @__PURE__ */ import_react.default.createElement(import_Action.default, { props }))
        );
      }
      return false;
    },
    [props]
  );
  const coverCom = (0, import_react.useMemo)(() => {
    if (isCover && displayMode !== "display_a1") {
      return /* @__PURE__ */ import_react.default.createElement(import_Cover.default, { props, onClick: (e) => {
        e.stopPropagation();
        onSelectCover == null ? void 0 : onSelectCover(dataSource);
      } });
    }
    return null;
  }, [isCover, displayMode, props]);
  const isShowMoreBtn = (0, import_react.useMemo)(() => {
    var _a2, _b2;
    if (((_a2 = dataSource == null ? void 0 : dataSource.sortKeys) == null ? void 0 : _a2.length) && ((_b2 = dataSource == null ? void 0 : dataSource.sortKeys) == null ? void 0 : _b2.length) < 4)
      return false;
    if (displayMode !== "display_a9" || !isFoldable) return false;
    return true;
  }, [(_h = dataSource == null ? void 0 : dataSource.sortKeys) == null ? void 0 : _h.length, displayMode, isFoldable]);
  const formatSortKeys = (0, import_react.useMemo)(() => {
    const sortKeys = (dataSource == null ? void 0 : dataSource.sortKeys) || [];
    if (displayMode === "display_a1") {
      const a1SortKeys = ["title", "price"];
      return sortKeys.filter((key) => a1SortKeys.includes(key));
    }
    if (displayMode === "display_a2") {
      return sortKeys.slice(0, 3);
    }
    if (displayMode === "display_a5") {
      return sortKeys.slice(0, 5);
    }
    if (isShowMoreBtn) {
      return isFold ? sortKeys.slice(0, 4) : sortKeys;
    }
    return sortKeys;
  }, [dataSource == null ? void 0 : dataSource.sortKeys, isShowMoreBtn, displayMode, isFold]);
  const contentCom = (0, import_react.useMemo)(() => {
    if (slot) {
      return slot;
    }
    return /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: `${import_status.PREFIX}__card-right-content ${className}-content `,
        style: contentStyle
      },
      renderComponents({ ...props, sortKeys: formatSortKeys }),
      /* @__PURE__ */ import_react.default.createElement(import_WarningLists.default, { lists: dataSource == null ? void 0 : dataSource.warning_lists }),
      isShowMoreBtn ? /* @__PURE__ */ import_react.default.createElement(import_CardMoreText.default, { ...props, onChange: setIsFold, isFold }) : null
    );
  }, [
    slot,
    contentStyle,
    className,
    props,
    formatSortKeys,
    isShowMoreBtn,
    isFold
  ]);
  const cardSlot = (0, import_react.useMemo)(() => {
    if (skuCardConfig == null ? void 0 : skuCardConfig.slot) {
      return skuCardConfig == null ? void 0 : skuCardConfig.slot;
    }
    if (displayMode === "display_custom") {
      return {
        type: "JSSlot",
        value: []
      };
    }
    return null;
  }, [skuCardConfig == null ? void 0 : skuCardConfig.slot, displayMode]);
  return /* @__PURE__ */ import_react.default.createElement(import_CardWrapper.default, { ...props }, /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: `${import_status.PREFIX}__card ${import_status.PREFIX}__card-${layoutDirection} ${className}`,
      style
    },
    cardSlot ? cardSlot : /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, coverCom, /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_status.PREFIX}__card-right`, style: rightStyle || {}, onClick: (e) => {
      e.stopPropagation();
      onSelectInfo == null ? void 0 : onSelectInfo(dataSource);
    } }, contentCom, actionCom("row")), actionCom("column"))
  ));
};
var CardCom_default = CardCom;
