var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
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_icon = __toESM(require("../icon"));
var import_loading = __toESM(require("../loading"));
var import_popup = __toESM(require("../popup"));
var import_Popup = require("../popup/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 ActionSheet = (props) => {
  const {
    prefixCls,
    createNamespace
  } = (0, import_react.useContext)(import_ConfigProviderContext.default);
  const [bem] = createNamespace("action-sheet", prefixCls);
  const onCancel = () => {
    var _a, _b;
    (_a = props.onClose) == null ? void 0 : _a.call(props);
    (_b = props.onCancel) == null ? void 0 : _b.call(props);
  };
  const renderHeader = () => {
    if (!props.title)
      return null;
    return /* @__PURE__ */ import_react.default.createElement("div", {
      className: (0, import_classnames.default)(bem("header"))
    }, props.title, props.closeable && (typeof props.closeIcon === "string" ? /* @__PURE__ */ import_react.default.createElement(import_icon.default, {
      name: props.closeIcon,
      className: (0, import_classnames.default)(bem("close")),
      onClick: onCancel
    }) : /* @__PURE__ */ import_react.default.createElement("div", {
      className: (0, import_classnames.default)(bem("close")),
      onClick: onCancel
    }, props.closeIcon)));
  };
  const renderCancel = () => {
    if (!props.cancelText)
      return null;
    return [/* @__PURE__ */ import_react.default.createElement("div", {
      key: "cancel-gap",
      className: (0, import_classnames.default)(bem("gap"))
    }), /* @__PURE__ */ import_react.default.createElement("button", {
      key: "cancel-btn",
      type: "button",
      className: (0, import_classnames.default)(bem("cancel")),
      onClick: onCancel
    }, props.cancelText)];
  };
  const renderOption = (item, index) => {
    const {
      name,
      color,
      subname,
      loading,
      callback,
      disabled,
      className,
      style
    } = item;
    const Content = loading ? /* @__PURE__ */ import_react.default.createElement(import_loading.default, {
      className: (0, import_classnames.default)(bem("loading-icon"))
    }) : [/* @__PURE__ */ import_react.default.createElement("span", {
      key: `${index}-1`,
      className: (0, import_classnames.default)(bem("name"))
    }, name), subname && /* @__PURE__ */ import_react.default.createElement("div", {
      key: `${index}-2`,
      className: (0, import_classnames.default)(bem("subname"))
    }, subname)];
    const onClick = () => {
      if (disabled || loading) {
        return;
      }
      if (callback) {
        callback(item);
      }
      if (props.closeOnClickAction) {
        onCancel();
      }
      setTimeout(() => {
        var _a;
        (_a = props.onSelect) == null ? void 0 : _a.call(props, item, index);
      }, 0);
    };
    return /* @__PURE__ */ import_react.default.createElement("button", {
      key: index,
      type: "button",
      style: __spreadValues({
        color
      }, style),
      className: (0, import_classnames.default)(bem("item", {
        loading,
        disabled
      }), className),
      onClick
    }, Content);
  };
  const renderDescription = () => {
    if (props.description) {
      return /* @__PURE__ */ import_react.default.createElement("div", {
        className: (0, import_classnames.default)(bem("description"))
      }, props.description);
    }
    return null;
  };
  const renderOptions = () => {
    if (props.actions) {
      return props.actions.map(renderOption);
    }
    return null;
  };
  return /* @__PURE__ */ import_react.default.createElement(import_popup.default, _extends({
    visible: props.visible,
    className: (0, import_classnames.default)(bem()),
    position: "bottom"
  }, (0, import_utils.pick)(props, import_Popup.sharedPopupProps), {
    onClose: onCancel,
    closeable: false
  }), renderHeader(), renderDescription(), /* @__PURE__ */ import_react.default.createElement("div", {
    className: (0, import_classnames.default)(bem("content"))
  }, renderOptions(), props.children), renderCancel());
};
ActionSheet.defaultProps = {
  closeIcon: "cross",
  closeable: true,
  safeAreaInsetBottom: true,
  round: true,
  lockScroll: true,
  overlay: true,
  closeOnClickOverlay: true
};
var stdin_default = ActionSheet;
