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/components/Media/index.tsx
var Media_exports = {};
__export(Media_exports, {
  default: () => Media_default
});
module.exports = __toCommonJS(Media_exports);
var import_react = __toESM(require("react"));
var import_classnames = __toESM(require("classnames"));
var import_index = require("./index.less");
var clamp = (value, min, max) => {
  return Math.max(min, Math.min(value, max));
};
var stopPropagation = (e) => {
  e.stopPropagation();
};
var Media = ({
  cover,
  label,
  extra,
  indicator,
  showIndicator = true,
  coverType = "auto",
  shape,
  size = "large",
  selected = false,
  disabled = false,
  onClick,
  styles,
  className,
  style
}) => {
  const styleProps = {
    selected,
    disabled,
    shape,
    size
  };
  const fontSize = (0, import_react.useMemo)(() => {
    if (typeof size === "number") {
      return clamp(size * 0.2, 12, 48);
    }
    return void 0;
  }, [size]);
  const coverStyle = (0, import_react.useMemo)(() => {
    const baseStyle = {};
    if (typeof size === "number") {
      baseStyle.width = size;
      baseStyle.height = size;
      baseStyle.fontSize = fontSize;
    }
    if (!(styles == null ? void 0 : styles.cover)) return baseStyle;
    const customStyle = typeof styles.cover === "function" ? styles.cover(styleProps) : styles.cover;
    return { ...baseStyle, ...customStyle };
  }, [size, fontSize, styles == null ? void 0 : styles.cover, styleProps]);
  const containerStyle = (0, import_react.useMemo)(() => {
    if (!(styles == null ? void 0 : styles.container)) return style;
    const customStyle = typeof styles.container === "function" ? styles.container(styleProps) : styles.container;
    return { ...customStyle, ...style };
  }, [styles == null ? void 0 : styles.container, style, styleProps]);
  const labelStyle = (0, import_react.useMemo)(() => {
    const baseStyle = {};
    if (fontSize) {
      baseStyle.fontSize = fontSize;
    }
    if (!(styles == null ? void 0 : styles.label)) return baseStyle;
    const customStyle = typeof styles.label === "function" ? styles.label(styleProps) : styles.label;
    return { ...baseStyle, ...customStyle };
  }, [fontSize, styles == null ? void 0 : styles.label, styleProps]);
  const extraStyle = (0, import_react.useMemo)(() => {
    if (!(styles == null ? void 0 : styles.extra)) return void 0;
    return typeof styles.extra === "function" ? styles.extra(styleProps) : styles.extra;
  }, [styles == null ? void 0 : styles.extra, styleProps]);
  const indicatorSize = (0, import_react.useMemo)(() => {
    if (typeof size === "number") {
      return Math.round(size * 0.3);
    }
    return size === "large" ? "middle" : "small";
  }, [size]);
  const indicatorStyle = (0, import_react.useMemo)(() => {
    if (!(styles == null ? void 0 : styles.indicator)) return void 0;
    return typeof styles.indicator === "function" ? styles.indicator(styleProps) : styles.indicator;
  }, [styles == null ? void 0 : styles.indicator, styleProps]);
  const getTextContent = () => {
    if (typeof label === "string" && label) {
      return label[0].toUpperCase();
    }
    return "";
  };
  const renderPlaceholderLogo = () => {
    return /* @__PURE__ */ import_react.default.createElement(
      "svg",
      {
        className: "pisell-selector_media-placeholder",
        viewBox: "0 0 1024 1024",
        width: "60%",
        height: "60%"
      },
      /* @__PURE__ */ import_react.default.createElement(
        "path",
        {
          d: "M512 85.333333c235.648 0 426.666667 191.018667 426.666667 426.666667s-191.018667 426.666667-426.666667 426.666667S85.333333 747.648 85.333333 512 276.352 85.333333 512 85.333333z m0 85.333334C323.477333 170.666667 170.666667 323.477333 170.666667 512s152.810667 341.333333 341.333333 341.333333 341.333333-152.810667 341.333333-341.333333S700.522667 170.666667 512 170.666667z m0 128a85.333333 85.333333 0 1 1 0 170.666666 85.333333 85.333333 0 0 1 0-170.666666z m0 256c94.293333 0 170.666667 76.373333 170.666667 170.666666a42.666667 42.666667 0 0 1-85.333334 0 85.333333 85.333333 0 0 0-170.666666 0 42.666667 42.666667 0 0 1-85.333334 0c0-94.293333 76.373333-170.666667 170.666667-170.666666z",
          fill: "currentColor"
        }
      )
    );
  };
  const renderCover = () => {
    if (coverType === "image") {
      if (typeof cover === "string" && cover) {
        return /* @__PURE__ */ import_react.default.createElement("img", { src: cover, alt: typeof label === "string" ? label : "" });
      }
      if (import_react.default.isValidElement(cover)) {
        return cover;
      }
      return renderPlaceholderLogo();
    }
    if (coverType === "text") {
      const text2 = getTextContent();
      if (text2) {
        return /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-selector_media-text" }, text2);
      }
      return renderPlaceholderLogo();
    }
    if (typeof cover === "string" && cover) {
      return /* @__PURE__ */ import_react.default.createElement("img", { src: cover, alt: typeof label === "string" ? label : "" });
    }
    if (import_react.default.isValidElement(cover)) {
      return cover;
    }
    const text = getTextContent();
    if (text) {
      return /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-selector_media-text" }, text);
    }
    return renderPlaceholderLogo();
  };
  const renderIndicator = () => {
    if (!showIndicator || !indicator || !selected) return null;
    if (import_react.default.isValidElement(indicator)) {
      const clonedIndicator = import_react.default.cloneElement(
        indicator,
        {
          size: indicatorSize,
          variant: "filled"
        }
      );
      return /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          className: "pisell-selector_media-indicator-wrapper",
          style: indicatorStyle,
          onClick: stopPropagation
        },
        clonedIndicator
      );
    }
    return /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: "pisell-selector_media-indicator-wrapper",
        style: indicatorStyle,
        onClick: stopPropagation
      },
      indicator
    );
  };
  const handleClick = (e) => {
    if (disabled) return;
    onClick == null ? void 0 : onClick(e);
  };
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: (0, import_classnames.default)(
        "pisell-selector_media-item",
        {
          [`pisell-selector_media-item-${size}`]: [
            "small",
            "middle",
            "large"
          ].includes(size),
          "pisell-selector_media-item-disabled": disabled,
          "pisell-selector_media-item-selected": selected
        },
        className
      ),
      style: containerStyle,
      onClick: handleClick
    },
    /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: (0, import_classnames.default)(
          "pisell-selector_media-cover",
          `pisell-selector_media-cover-${shape}`
        ),
        style: coverStyle
      },
      renderCover(),
      renderIndicator()
    ),
    label && /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-selector_media-label", style: labelStyle }, label),
    extra && /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: "pisell-selector_media-extra",
        style: extraStyle,
        onClick: stopPropagation
      },
      extra
    )
  );
};
var Media_default = Media;
