var __defProp = Object.defineProperty;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
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;
};
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);
}
import React, { useContext } from "react";
import classnames from "classnames";
import { pick } from "../utils";
import Icon from "../icon";
import Loading from "../loading";
import Popup from "../popup";
import { sharedPopupProps } from "../popup/Popup";
import ConfigProviderContext from "../config-provider/ConfigProviderContext";
const ActionSheet = (props) => {
  const {
    prefixCls,
    createNamespace
  } = useContext(ConfigProviderContext);
  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__ */ React.createElement("div", {
      className: classnames(bem("header"))
    }, props.title, props.closeable && (typeof props.closeIcon === "string" ? /* @__PURE__ */ React.createElement(Icon, {
      name: props.closeIcon,
      className: classnames(bem("close")),
      onClick: onCancel
    }) : /* @__PURE__ */ React.createElement("div", {
      className: classnames(bem("close")),
      onClick: onCancel
    }, props.closeIcon)));
  };
  const renderCancel = () => {
    if (!props.cancelText)
      return null;
    return [/* @__PURE__ */ React.createElement("div", {
      key: "cancel-gap",
      className: classnames(bem("gap"))
    }), /* @__PURE__ */ React.createElement("button", {
      key: "cancel-btn",
      type: "button",
      className: classnames(bem("cancel")),
      onClick: onCancel
    }, props.cancelText)];
  };
  const renderOption = (item, index) => {
    const {
      name,
      color,
      subname,
      loading,
      callback,
      disabled,
      className,
      style
    } = item;
    const Content = loading ? /* @__PURE__ */ React.createElement(Loading, {
      className: classnames(bem("loading-icon"))
    }) : [/* @__PURE__ */ React.createElement("span", {
      key: `${index}-1`,
      className: classnames(bem("name"))
    }, name), subname && /* @__PURE__ */ React.createElement("div", {
      key: `${index}-2`,
      className: classnames(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__ */ React.createElement("button", {
      key: index,
      type: "button",
      style: __spreadValues({
        color
      }, style),
      className: classnames(bem("item", {
        loading,
        disabled
      }), className),
      onClick
    }, Content);
  };
  const renderDescription = () => {
    if (props.description) {
      return /* @__PURE__ */ React.createElement("div", {
        className: classnames(bem("description"))
      }, props.description);
    }
    return null;
  };
  const renderOptions = () => {
    if (props.actions) {
      return props.actions.map(renderOption);
    }
    return null;
  };
  return /* @__PURE__ */ React.createElement(Popup, _extends({
    visible: props.visible,
    className: classnames(bem()),
    position: "bottom"
  }, pick(props, sharedPopupProps), {
    onClose: onCancel,
    closeable: false
  }), renderHeader(), renderDescription(), /* @__PURE__ */ React.createElement("div", {
    className: classnames(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;
export {
  stdin_default as default
};
