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(
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var stdin_exports = {};
__export(stdin_exports, {
  default: () => stdin_default
});
module.exports = __toCommonJS(stdin_exports);
var import_react = __toESM(require("react"));
var import_classnames = __toESM(require("classnames"));
var import_utils = require("../utils");
var import_popup = __toESM(require("../popup"));
var import_ConfigProviderContext = __toESM(require("../config-provider/ConfigProviderContext"));
function _extends() {
  _extends = Object.assign ? Object.assign.bind() : function(target) {
    for (var i = 1; i < arguments.length; i++) {
      var source = arguments[i];
      for (var key in source) {
        if (Object.prototype.hasOwnProperty.call(source, key)) {
          target[key] = source[key];
        }
      }
    }
    return target;
  };
  return _extends.apply(this, arguments);
}
const PRESET_ICONS = ["qq", "link", "weibo", "wechat", "poster", "qrcode", "weapp-qrcode", "wechat-moments"];
function getIconURL(icon) {
  if (PRESET_ICONS.includes(icon)) {
    return `https://img.yzcdn.cn/vant/share-sheet-${icon}.png`;
  }
  return icon;
}
const ShareSheet = (props) => {
  const {
    prefixCls,
    createNamespace
  } = (0, import_react.useContext)(import_ConfigProviderContext.default);
  const [bem] = createNamespace("share-sheet", prefixCls);
  const onCancel = () => {
    var _a;
    (_a = props.onCancel) == null ? void 0 : _a.call(props);
  };
  const onSelect = (option, index) => {
    var _a;
    (_a = props.onSelect) == null ? void 0 : _a.call(props, option, index);
  };
  const renderHeader = () => {
    const {
      title,
      description
    } = props;
    if (title || description) {
      return /* @__PURE__ */ import_react.default.createElement("div", {
        className: (0, import_classnames.default)(bem("header"))
      }, title && /* @__PURE__ */ import_react.default.createElement("div", {
        className: (0, import_classnames.default)(bem("title"))
      }, title), description && /* @__PURE__ */ import_react.default.createElement("div", {
        className: (0, import_classnames.default)(bem("description"))
      }, description));
    }
    return null;
  };
  const renderOption = (option, index) => {
    const {
      name,
      icon,
      className,
      description
    } = option;
    return /* @__PURE__ */ import_react.default.createElement("div", {
      key: index,
      role: "button",
      tabIndex: 0,
      className: (0, import_classnames.default)([bem("option"), className]),
      onClick: () => onSelect(option, index)
    }, /* @__PURE__ */ import_react.default.createElement("img", {
      alt: "share sheet icon",
      src: getIconURL(icon),
      className: (0, import_classnames.default)(bem("icon"))
    }), name && /* @__PURE__ */ import_react.default.createElement("span", {
      className: (0, import_classnames.default)(bem("name"))
    }, name), description && /* @__PURE__ */ import_react.default.createElement("span", {
      className: (0, import_classnames.default)(bem("option-description"))
    }, description));
  };
  const renderOptions = (options, border, key) => /* @__PURE__ */ import_react.default.createElement("div", {
    key,
    className: (0, import_classnames.default)(bem("options", {
      border
    }))
  }, options.map(renderOption));
  const renderRows = () => {
    const {
      options
    } = props;
    if (Array.isArray(options[0])) {
      return options.map((item, index) => renderOptions(item, index !== 0, index));
    }
    return renderOptions(options);
  };
  const renderCancelButton = () => {
    const {
      cancelText
    } = props;
    if (cancelText) {
      return /* @__PURE__ */ import_react.default.createElement("button", {
        type: "button",
        className: (0, import_classnames.default)(bem("cancel")),
        onClick: onCancel
      }, cancelText);
    }
    return null;
  };
  return /* @__PURE__ */ import_react.default.createElement(import_popup.default, _extends({
    round: true,
    className: (0, import_classnames.default)(bem()),
    position: "bottom",
    onClose: onCancel
  }, (0, import_utils.pick)(props, ["closeOnPopstate", "safeAreaInsetBottom", "visible", "overlay", "duration", "lockScroll", "overlayStyle", "overlayClass", "closeOnClickOverlay"])), renderHeader(), renderRows(), renderCancelButton());
};
ShareSheet.defaultProps = {
  cancelText: "\u53D6\u6D88",
  options: [],
  closeOnPopstate: true,
  safeAreaInsetBottom: true,
  closeOnClickOverlay: true
};
var stdin_default = ShareSheet;
