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/pro/Selector/Item.tsx
var Item_exports = {};
__export(Item_exports, {
  default: () => Item_default
});
module.exports = __toCommonJS(Item_exports);
var import_react = __toESM(require("react"));
var import_components = require("./components");
var import_usePresetItemProps = __toESM(require("./hooks/usePresetItemProps"));
var import_Selector = require("./Selector");
var Item = (props) => {
  const {
    actions,
    dataSource,
    indicator,
    numberSelector,
    optionItemValue,
    quantityInfo,
    values,
    children
  } = props;
  const { disabled, mode, variant, itemProps, preset, itemLayout } = (0, import_react.useContext)(import_Selector.SelectorContext);
  const { mediaProps, cardProps } = (0, import_usePresetItemProps.default)({
    variant,
    itemLayout,
    preset,
    itemProps,
    indicator,
    numberSelector,
    mode,
    disabled: disabled || dataSource.disabled,
    selected: dataSource.selected
  });
  const handleClick = () => {
    if (disabled || dataSource.disabled) return;
    if (dataSource.selected) {
      actions.update(dataSource._key, { quantity: 0 });
    } else {
      const quantity = dataSource.effectiveMin || 1;
      actions.update(dataSource._key, { quantity });
    }
  };
  if (variant === "media") {
    return /* @__PURE__ */ import_react.default.createElement(
      import_components.MediaItem,
      {
        ...mediaProps,
        cover: dataSource.cover,
        label: dataSource._label,
        extra: numberSelector,
        indicator,
        selected: dataSource.selected,
        disabled: disabled || dataSource.disabled,
        onClick: handleClick
      }
    );
  }
  const renderChildren = () => {
    var _a;
    if (typeof (cardProps == null ? void 0 : cardProps.renderContent) === "function") {
      return (_a = cardProps == null ? void 0 : cardProps.renderContent) == null ? void 0 : _a.call(cardProps, { dataSource });
    }
    if ("design" === props.__designMode) {
      if (children == null || Array.isArray(children) && !children.length) {
        return /* @__PURE__ */ import_react.default.createElement("div", { className: "lc-container-placeholder" }, "拖拽组件或模板到这里");
      }
    }
    return children ? children : /* @__PURE__ */ import_react.default.createElement("span", null, dataSource._label);
  };
  return /* @__PURE__ */ import_react.default.createElement(
    import_components.CardItem,
    {
      ...cardProps,
      selected: dataSource.selected,
      disabled: disabled || dataSource.disabled,
      onClick: handleClick
    },
    renderChildren()
  );
};
var Item_default = Item;
