import { DtIconChevronUp as n } from "@dialpad/dialtone-icons/vue2";
import r, { warnIfUnmounted as l } from "../../common/utils/index.js";
import { DialtoneLocalization as a } from "../../localization/index.js";
import { n as i } from "../../_plugin-vue2_normalizer-DSLOjnn3.js";
import { CALLBAR_BUTTON_VALID_WIDTH_SIZE as s } from "../callbar-button/callbar-button-constants.js";
import p from "../button/button.js";
import c from "../popover/popover.js";
import u from "../callbar-button/callbar-button.js";
const d = {
  name: "DtRecipeCallbarButtonWithPopover",
  components: { DtRecipeCallbarButton: u, DtPopover: c, DtButton: p, DtIconChevronUp: n },
  /* inheritAttrs: false is generally an option we want to set on library
    components. This allows any attributes passed in that are not recognized
    as props to be passed down to another element or component using v-bind:$attrs
    more info: https://vuejs.org/v2/api/#inheritAttrs */
  inheritAttrs: !1,
  props: {
    /**
     * Id for the item.
     */
    id: {
      type: String,
      default() {
        return r.getUniqueString();
      }
    },
    /**
     * Aria label for the button. If empty, it takes its value from the default slot.
     */
    ariaLabel: {
      type: String,
      default: null,
      validator: (e) => e || (void 0).$slots.default
    },
    /**
     * The direction the popover displays relative to the anchor.
     * @values 'bottom', 'bottom-start', 'bottom-end',
     *         'right', 'right-start', 'right-end',
     *         'left', 'left-start', 'left-end',
     *         'top', 'top-start', 'top-end'
     * @default 'top'
     */
    placement: {
      type: String,
      default: "top"
    },
    /**
     *  Displaces the content box from its anchor element
     *  by the specified number of pixels.
     *  <a
     *    class="d-link"
     *    href="https://atomiks.github.io/tippyjs/v6/all-props/#offset"
     *    target="_blank"
     *  >
     *    Tippy.js docs
     *  </a>
     */
    offset: {
      type: Array,
      default: () => [0, 16]
    },
    /**
     * The element that is focused when the popover is opened. This can be an
     * HTMLElement within the popover, a string starting with '#' which will
     * find the element by ID. 'first' which will automatically focus
     * the first element, or 'dialog' which will focus the dialog window itself.
     * If the dialog is modal this prop cannot be 'none'.
     */
    initialFocusElement: {
      type: String,
      default: "first"
    },
    /**
     * Determines visibility for close button
     */
    showCloseButton: {
      type: Boolean,
      default: !0
    },
    /**
     * Determines whether the button should be disabled
     * default is false.
     * @values true, false
     */
    disabled: {
      type: Boolean,
      default: !1
    },
    /**
     * Forces showing the arrow, even if the button is disabled.
     * default is false
     * @values true, false
     */
    forceShowArrow: {
      type: Boolean,
      default: !1
    },
    /**
     * Determines whether the button should have active styling
     * default is false.
     * @values true, false
     * @see https://dialtone.dialpad.com/components/button/
     */
    active: {
      type: Boolean,
      default: !1
    },
    /**
     * Determines whether the button should have danger styling
     * default is false.
     * @values true, false
     * @see https://dialtone.dialpad.com/components/button/
     */
    danger: {
      type: Boolean,
      default: !1
    },
    /**
     * Additional class name for the button wrapper element.
     */
    buttonClass: {
      type: [String, Array, Object],
      default: ""
    },
    /**
     * Additional class name for the button text.
     */
    textClass: {
      type: [String, Array, Object],
      default: ""
    },
    /*
     * Width size. Valid values are: 'xl', 'lg', 'md' and 'sm'.
     */
    buttonWidthSize: {
      type: String,
      default: "xl",
      validator: (e) => s.includes(e)
    },
    /**
     * Additional class name for the popover content wrapper element.
     */
    contentClass: {
      type: [String, Array, Object],
      default: ""
    },
    /**
     * To auto open the modal popover.
     */
    openPopover: {
      type: Boolean,
      default: !1
    },
    /**
     * Whether the tooltip has an inverted background color.
     * @values true, false
     */
    invertedTooltip: {
      type: Boolean,
      default: !1
    },
    /**
     * Use this if you would like to manually override the logic for when the tooltip shows.
     * Otherwise it will just show on hover/focus.
     * @values null, true, false
     */
    showTooltip: {
      type: Boolean,
      default: null
    },
    /**
     * The message that displays in the tooltip. This will be overridden by the tooltip slot.
     */
    tooltipText: {
      type: String,
      default: void 0
    },
    /**
     * Whether there is a delay before the tooltip shows on hover/focus.
     * @values true, false
     */
    tooltipDelay: {
      type: Boolean,
      default: void 0
    }
  },
  emits: [
    /**
     * Emitted when the arrow is clicked
     */
    "arrow-click",
    /**
     * Native click event
     *
     * @event click
     * @type {PointerEvent | KeyboardEvent}
     */
    "click",
    /**
     * Emitted when modal popover is opened or closed.
     */
    "opened"
  ],
  data() {
    return {
      open: !1,
      i18n: new a()
    };
  },
  computed: {
    showArrowButton() {
      return this.forceShowArrow || !this.disabled;
    },
    isCompactMode() {
      return this.buttonWidthSize === "sm" || this.buttonWidthSize === "md";
    },
    showPopover() {
      return !this.openPopover || this.open ? (this.syncOpenState(), !1) : this.toggleOpen();
    },
    arrowButtonLabel() {
      return this.i18n.$t("DIALTONE_CALLBAR_BUTTON_WITH_POPOVER_ARROW_BUTTON_ARIA_LABEL");
    }
  },
  mounted() {
    l(this.$el, this.$options.name);
  },
  methods: {
    arrowClick(e) {
      return this.$emit("arrow-click", e), this.toggleOpen();
    },
    toggleOpen() {
      return this.open = !this.open;
    },
    syncOpenState() {
      this.open = this.openPopover;
    },
    buttonClick(e) {
      this.$listeners.click ? this.$emit("click", e) : this.arrowClick(e);
    },
    onModalIsOpened(e) {
      this.open = e, this.$emit("opened", e);
    }
  }
};
var f = function() {
  var t = this, o = t._self._c;
  return o("div", { staticClass: "d-recipe-callbar-button-with-popover" }, [o("dt-recipe-callbar-button", { staticClass: "d-recipe-callbar-button-with-popover--main-button", attrs: { "aria-label": t.ariaLabel, disabled: t.disabled, active: t.active, danger: t.danger, "button-class": t.buttonClass, "button-width-size": t.buttonWidthSize, "text-class": t.textClass, "inverted-tooltip": t.invertedTooltip, "show-tooltip": t.showTooltip, "tooltip-text": t.tooltipText, "tooltip-delay": t.tooltipDelay }, on: { click: t.buttonClick } }, [t._t("icon", null, { slot: "icon" }), t._t("tooltip", null, { slot: "tooltip" }), t._t("default")], 2), t.showArrowButton ? o("dt-popover", t._b({ staticClass: "d-recipe-callbar-button-with-popover__popover-wrapper", attrs: { id: t.id, modal: !1, open: t.open, placement: t.placement, "initial-focus-element": t.initialFocusElement, "show-close-button": t.showCloseButton, offset: t.offset, padding: "none", "dialog-class": ["d-recipe-callbar-button-with-popover__popover", t.contentClass], "open-popover": t.showPopover }, on: { opened: t.onModalIsOpened }, scopedSlots: t._u([{ key: "anchor", fn: function() {
    return [o("dt-button", { class: [
      "d-recipe-callbar-button-with-popover__arrow",
      { "d-recipe-callbar-button-with-popover__arrow--large": !t.isCompactMode }
    ], attrs: { active: t.open, circle: !0, importance: "clear", size: "lg", "aria-label": t.arrowButtonLabel, title: t.arrowButtonLabel, width: "2rem" }, on: { click: t.arrowClick }, scopedSlots: t._u([{ key: "icon", fn: function() {
      return [o("dt-icon-chevron-up", { staticClass: "d-recipe-callbar-button-with-popover__arrow-icon", attrs: { size: "200" } })];
    }, proxy: !0 }], null, !1, 778999832) })];
  }, proxy: !0 }], null, !1, 2571181550) }, "dt-popover", t.$attrs, !1), [t._t("content", null, { slot: "content" }), t._t("headerContent", null, { slot: "headerContent" }), t._t("footerContent", null, { slot: "footerContent" })], 2) : t._e()], 1);
}, h = [], _ = /* @__PURE__ */ i(
  d,
  f,
  h
);
const S = _.exports;
export {
  S as default
};
//# sourceMappingURL=callbar-button-with-popover.js.map
