import { getUniqueString as s, extractVueListeners as b, hasSlotContent as g } from "../../common/utils/index.js";
import C from "./collapsible-lazy-show.js";
import { DtIconChevronDown as x, DtIconChevronRight as S } from "@dialpad/dialtone-icons/vue3";
import { resolveComponent as a, openBlock as o, createBlock as i, resolveDynamicComponent as v, mergeProps as c, toHandlers as d, withCtx as r, createElementVNode as h, normalizeClass as L, renderSlot as p, createVNode as m, normalizeStyle as O, toDisplayString as T } from "vue";
import { _ as w } from "../../_plugin-vue_export-helper-CHgC5LLL.js";
import D from "../button/button.js";
import B from "../lazy-show/lazy-show.js";
const z = {
  compatConfig: { MODE: 3 },
  name: "DtCollapsible",
  components: {
    DtButton: D,
    DtCollapsibleLazyShow: C,
    DtLazyShow: B,
    DtIconChevronDown: x,
    DtIconChevronRight: S
  },
  props: {
    /**
     * Text that is displayed on the anchor if nothing is passed in the slot.
     * Ignored if the anchor slot is used.
     */
    anchorText: {
      type: String,
      default: null
    },
    /**
     * Controls whether the collapsible is shown. Leaving this null will have the collapsible start
     * expanded and trigger on click by default. If you set this value, the default trigger
     * behavior will be disabled, and you can control it as you need.
     * Supports .sync modifier
     * @values null, true, false
     */
    open: {
      type: Boolean,
      default: null
    },
    /**
     * The id of the content wrapper.
     */
    id: {
      type: String,
      default() {
        return s();
      }
    },
    /**
     * HTML element type (tag name) of the root element of the component.
     */
    elementType: {
      type: String,
      default: "div"
    },
    /**
     * HTML element type (tag name) of the content wrapper element.
     */
    contentElementType: {
      type: String,
      default: "div"
    },
    /**
     * Additional class name for the anchor wrapper element.
     */
    anchorClass: {
      type: [String, Array, Object],
      default: null
    },
    /**
     * Additional class name for the content wrapper element.
     */
    contentClass: {
      type: [String, Array, Object],
      default: null
    },
    /**
     * The maximum width of the anchor and collapsible element.
     * Possible units rem|px|%|em
     */
    maxWidth: {
      type: String,
      default: null
    },
    /**
     * The maximum height of the collapsible element.
     * Possible units rem|px|%|em
     */
    maxHeight: {
      type: String,
      default: null
    },
    /**
     * Label on the collapsible content. Should provide this or ariaLabelledBy but not both.
     */
    ariaLabel: {
      type: String,
      default: null
    },
    /**
     * Id of the element that labels the collapsible content. Defaults to the anchor element.
     * Should provide this or ariaLabel but not both.
     */
    ariaLabelledBy: {
      type: String,
      default: null
    }
  },
  emits: [
    /**
     * Event fired to sync the open prop with the parent component
     * @event update:open
     */
    "update:open",
    /**
     * Event fired when the content is shown or hidden
     *
     * @event opened
     * @type {Boolean}
     */
    "opened"
  ],
  data() {
    return {
      isOpen: !0
    };
  },
  computed: {
    labelledBy() {
      return this.ariaLabelledBy || !this.ariaLabel && s("DtCollapsible__anchor");
    },
    collapsibleListeners() {
      return b(this.$attrs);
    }
  },
  watch: {
    open: {
      handler: function(n) {
        n !== null && (this.isOpen = n);
      },
      immediate: !0
    }
  },
  created() {
    this.validateProperAnchor();
  },
  methods: {
    onLeaveTransitionComplete() {
      this.$emit("opened", !1), this.open !== null && this.$emit("update:open", !1);
    },
    onEnterTransitionComplete() {
      this.$emit("opened", !0, this.$refs.content), this.open !== null && this.$emit("update:open", !0);
    },
    defaultToggleOpen() {
      this.open === null && this.toggleOpen();
    },
    toggleOpen() {
      this.isOpen = !this.isOpen;
    },
    validateProperAnchor() {
      !this.anchorText && !g(this.$slots.anchor) && console.error("anchor text and anchor slot content cannot both be falsy");
    }
  }
}, A = ["id"], E = ["title"];
function k(n, W, e, H, l, t) {
  const u = a("dt-icon-chevron-down"), f = a("dt-icon-chevron-right"), y = a("dt-button"), _ = a("dt-collapsible-lazy-show");
  return o(), i(v(e.elementType), c({ ref: "collapsible" }, d(t.collapsibleListeners)), {
    default: r(() => [
      h("div", {
        id: !e.ariaLabelledBy && t.labelledBy,
        ref: "anchor",
        class: L(e.anchorClass)
      }, [
        p(n.$slots, "anchor", {
          attrs: {
            "aria-controls": e.id,
            "aria-expanded": l.isOpen.toString(),
            role: "button"
          }
        }, () => [
          m(y, {
            importance: "clear",
            kind: "muted",
            "aria-controls": e.id,
            "aria-expanded": `${l.isOpen}`,
            style: O({
              width: e.maxWidth
            }),
            onClick: t.defaultToggleOpen
          }, {
            default: r(() => [
              l.isOpen ? (o(), i(u, {
                key: 0,
                class: "d-collapsible__icon",
                size: "300"
              })) : (o(), i(f, {
                key: 1,
                class: "d-collapsible__icon",
                size: "300"
              })),
              h("span", {
                class: "d-collapsible__anchor-text",
                title: e.anchorText
              }, T(e.anchorText), 9, E)
            ]),
            _: 1
          }, 8, ["aria-controls", "aria-expanded", "style", "onClick"])
        ])
      ], 10, A),
      m(_, c({
        id: e.id,
        ref: "contentWrapper",
        "aria-hidden": `${!l.isOpen}`,
        "aria-labelledby": t.labelledBy,
        "aria-label": e.ariaLabel,
        show: l.isOpen,
        "element-type": e.contentElementType,
        class: e.contentClass,
        style: {
          "max-height": e.maxHeight,
          "max-width": e.maxWidth
        },
        "data-qa": "dt-collapsible--content",
        tabindex: "-1",
        appear: ""
      }, d(t.collapsibleListeners), {
        onAfterLeave: t.onLeaveTransitionComplete,
        onAfterEnter: t.onEnterTransitionComplete
      }), {
        default: r(() => [
          p(n.$slots, "content")
        ]),
        _: 3
      }, 16, ["id", "aria-hidden", "aria-labelledby", "aria-label", "show", "element-type", "class", "style", "onAfterLeave", "onAfterEnter"])
    ]),
    _: 3
  }, 16);
}
const R = /* @__PURE__ */ w(z, [["render", k]]);
export {
  R as default
};
//# sourceMappingURL=collapsible.js.map
