"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const vue = require("vue");
const comp = require("../../ui/src/comp.js");
require("../../ui/index.js");
const XEUtils = require("xe-utils");
const button = require("./button.js");
const config = require("../../../../@vxe-ui/core/es/src/config.js");
const useFns = require("../../../../@vxe-ui/core/es/src/useFns.js");
const event = require("../../../../@vxe-ui/core/es/src/event.js");
const index_esm = require("../../../../@vxe-ui/core/es/index.esm.js");
const VxeButtonGroupComponent = comp.defineVxeComponent({
  name: "VxeButtonGroup",
  props: {
    options: Array,
    mode: String,
    status: String,
    round: Boolean,
    vertical: Boolean,
    circle: Boolean,
    align: String,
    className: [String, Function],
    disabled: Boolean,
    permissionCode: [String, Number],
    size: {
      type: String,
      default: () => config.getConfig().buttonGroup.size || config.getConfig().size
    }
  },
  emits: [
    "click",
    "contextmenu"
  ],
  setup(props, context) {
    const { slots, emit } = context;
    const xID = XEUtils.uniqueId();
    const reactData = vue.reactive({});
    const computeMaps = {};
    const $xeButtonGroup = {
      xID,
      props,
      context,
      reactData,
      getComputeMaps: () => computeMaps
    };
    useFns.useSize(props);
    const { computePermissionInfo } = useFns.usePermission(props);
    const dispatchEvent = (type, params, evnt) => {
      emit(type, event.createEvent(evnt, { $buttonGroup: $xeButtonGroup }, params));
    };
    const buttonGroupMethods = {
      dispatchEvent
    };
    const buttonGroupPrivateMethods = {
      handleClick(params, evnt) {
        const { options } = props;
        const { name } = params;
        const option = options ? options.find((item) => item.name === name) : null;
        buttonGroupMethods.dispatchEvent("click", Object.assign(Object.assign({}, params), { option }), evnt);
      }
    };
    const contextmenuEvent = (evnt) => {
      dispatchEvent("contextmenu", {}, evnt);
    };
    Object.assign($xeButtonGroup, buttonGroupMethods, buttonGroupPrivateMethods);
    const renderVN = () => {
      const { className, options, vertical } = props;
      const permissionInfo = computePermissionInfo.value;
      const defaultSlot = slots.default;
      if (!permissionInfo.visible) {
        return index_esm.renderEmptyElement();
      }
      return vue.h("div", {
        class: ["vxe-button-group", className ? XEUtils.isFunction(className) ? className({ $buttonGroup: $xeButtonGroup }) : className : "", {
          "is--vertical": vertical
        }],
        onContextmenu: contextmenuEvent
      }, defaultSlot ? defaultSlot({}) : options ? options.map((item, index) => {
        return vue.h(button.default, Object.assign({ key: index }, item));
      }) : []);
    };
    $xeButtonGroup.renderVN = renderVN;
    vue.provide("$xeButtonGroup", $xeButtonGroup);
    return $xeButtonGroup;
  },
  render() {
    return this.renderVN();
  }
});
exports.default = VxeButtonGroupComponent;
