"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const Vue = require("vue");
const index$1 = require("../icon/index.js");
const index = require("../popup/index.js");
const index$2 = require("../loading/index.js");
const shared = require("../popup/shared.js");
const basic = require("../utils/basic.js");
const props = require("../utils/props.js");
const create = require("../utils/create.js");
const constant = require("../utils/constant.js");
const [name, bem] = create.createNamespace("action-sheet");
const actionSheetProps = basic.extend({}, shared.popupSharedProps, {
  title: String,
  round: props.truthProp,
  actions: props.makeArrayProp(),
  closeIcon: props.makeStringProp("cross"),
  closeable: props.truthProp,
  cancelText: String,
  description: String,
  closeOnPopstate: props.truthProp,
  closeOnClickAction: Boolean,
  safeAreaInsetBottom: props.truthProp
});
const popupInheritKeys = [...shared.popupSharedPropKeys, "round", "closeOnPopstate", "safeAreaInsetBottom"];
var stdin_default = Vue.defineComponent({
  name,
  props: actionSheetProps,
  emits: ["select", "cancel", "update:show"],
  setup(props2, {
    slots,
    emit
  }) {
    const updateShow = (show) => emit("update:show", show);
    const onCancel = () => {
      updateShow(false);
      emit("cancel");
    };
    const renderHeader = () => {
      if (props2.title) {
        return Vue.createVNode("div", {
          "class": bem("header")
        }, [props2.title, props2.closeable && Vue.createVNode(index$1.Icon, {
          "name": props2.closeIcon,
          "class": [bem("close"), constant.HAPTICS_FEEDBACK],
          "onClick": onCancel
        }, null)]);
      }
    };
    const renderCancel = () => {
      if (slots.cancel || props2.cancelText) {
        return [Vue.createVNode("div", {
          "class": bem("gap")
        }, null), Vue.createVNode("button", {
          "type": "button",
          "class": bem("cancel"),
          "onClick": onCancel
        }, [slots.cancel ? slots.cancel() : props2.cancelText])];
      }
    };
    const renderIcon = (action) => {
      if (action.icon) {
        return Vue.createVNode(index$1.Icon, {
          "class": bem("item-icon"),
          "name": action.icon
        }, null);
      }
    };
    const renderActionContent = (action, index2) => {
      if (action.loading) {
        return Vue.createVNode(index$2.Loading, {
          "class": bem("loading-icon")
        }, null);
      }
      if (slots.action) {
        return slots.action({
          action,
          index: index2
        });
      }
      return [Vue.createVNode("span", {
        "class": bem("name")
      }, [action.name]), action.subname && Vue.createVNode("div", {
        "class": bem("subname")
      }, [action.subname])];
    };
    const renderAction = (action, index2) => {
      const {
        color,
        loading,
        callback,
        disabled,
        className
      } = action;
      const onClick = () => {
        if (disabled || loading) {
          return;
        }
        if (callback) {
          callback(action);
        }
        if (props2.closeOnClickAction) {
          updateShow(false);
        }
        Vue.nextTick(() => emit("select", action, index2));
      };
      return Vue.createVNode("button", {
        "type": "button",
        "style": {
          color
        },
        "class": [bem("item", {
          loading,
          disabled
        }), className],
        "onClick": onClick
      }, [renderIcon(action), renderActionContent(action, index2)]);
    };
    const renderDescription = () => {
      if (props2.description || slots.description) {
        const content = slots.description ? slots.description() : props2.description;
        return Vue.createVNode("div", {
          "class": bem("description")
        }, [content]);
      }
    };
    return () => Vue.createVNode(index.Popup, Vue.mergeProps({
      "class": bem(),
      "position": "bottom",
      "onUpdate:show": updateShow
    }, basic.pick(props2, popupInheritKeys)), {
      default: () => {
        var _a;
        return [renderHeader(), renderDescription(), Vue.createVNode("div", {
          "class": bem("content")
        }, [props2.actions.map(renderAction), (_a = slots.default) == null ? void 0 : _a.call(slots)]), renderCancel()];
      }
    });
  }
});
exports.actionSheetProps = actionSheetProps;
exports.default = stdin_default;
