import { DtIconClose as C } from "@dialpad/dialtone-icons/vue3";
import { CHIP_CLOSE_BUTTON_SIZE_MODIFIERS as p, CHIP_SIZE_MODIFIERS as c, CHIP_ICON_SIZES as f } from "./chip-constants.js";
import { hasSlotContent as y, getUniqueString as S } from "../../common/utils/index.js";
import { DialtoneLocalization as k } from "../../localization/index.js";
import { resolveComponent as r, createElementBlock as l, openBlock as a, createBlock as u, createCommentVNode as o, resolveDynamicComponent as B, mergeProps as I, toHandlers as O, withCtx as h, renderSlot as d, normalizeClass as b, createVNode as v } from "vue";
import { _ as g } from "../../_plugin-vue_export-helper-CHgC5LLL.js";
import z from "../button/button.js";
const D = {
  compatConfig: { MODE: 3 },
  name: "DtChip",
  components: {
    DtButton: z,
    DtIconClose: C
  },
  props: {
    /**
     * Whether the chip is disabled
     * @values true, false
     */
    disabled: {
      type: Boolean,
      default: !1
    },
    /**
     * Hides the close button on the chip
     * @values true, false
     */
    hideClose: {
      type: Boolean,
      default: !1
    },
    /**
     * The size of the chip.
     * @values xs, sm, md
     */
    size: {
      type: String,
      default: "md",
      validator: (e) => Object.keys(c).includes(e)
    },
    /**
     * The interactivity of the chip.
     * Makes chip clickable, apply hover/focus/active style, emit keyboard events etc.
     * @values true, false
     */
    interactive: {
      type: Boolean,
      default: !0
    },
    /**
     * Id to use for the dialog's aria-labelledby.
     */
    id: {
      type: String,
      default: function() {
        return S();
      }
    },
    /**
     * Descriptive label for the chip content.
     * If this prop is unset the content in the default slot will be used as an aria-label.
     */
    ariaLabel: {
      type: String,
      default: ""
    },
    /**
     * Additional class name for the chip element.
     */
    contentClass: {
      type: [String, Array, Object],
      default: ""
    },
    /**
     * Additional class name for the span element.
     */
    labelClass: {
      type: [String, Array, Object],
      default: ""
    }
  },
  emits: [
    /**
     * Native chip click event
     *
     * @event click
     * @type {PointerEvent | KeyboardEvent}
     */
    "click",
    /**
     * Close button click event
     *
     * @event close
     */
    "close",
    /**
     * Native chip key up event
     *
     * @event keyup
     * @type {KeyboardEvent}
     */
    "keyup",
    /**
     * Native chip key down event
     *
     * @event keydown
     * @type {KeyboardEvent}
     */
    "keydown"
  ],
  data() {
    return {
      isActive: !1,
      hasSlotContent: y,
      i18n: new k()
    };
  },
  computed: {
    chipListeners() {
      return {
        click: (e) => {
          this.interactive && this.$emit("click", e);
        },
        keydown: (e) => {
          var s;
          ((s = e.code) == null ? void 0 : s.toLowerCase()) === "delete" ? this.onClose() : this.$emit("keydown", e);
        },
        keyup: (e) => {
          this.$emit("keyup", e);
        }
      };
    },
    closeButtonIconSize() {
      return f[this.size];
    },
    closeButtonTitle() {
      return this.i18n.$t("DIALTONE_CLOSE_BUTTON");
    }
  },
  methods: {
    chipClasses() {
      return [
        this.$attrs["grouped-chip"] ? "d-chip" : "d-chip__label",
        c[this.size],
        this.labelClass,
        this.disabled && "d-chip--disabled"
      ];
    },
    chipCloseButtonClasses() {
      return [
        "d-chip__close",
        p[this.size],
        this.disabled && "d-chip__close--disabled"
      ];
    },
    onClose() {
      this.hideClose || this.$emit("close");
    }
  }
}, E = { class: "d-chip" }, L = {
  key: 0,
  class: "d-chip__icon",
  "data-qa": "dt-chip-icon"
}, T = {
  key: 1,
  "data-qa": "dt-chip-avatar"
}, q = ["id"];
function w(e, s, t, N, n, i) {
  const m = r("dt-icon-close"), _ = r("dt-button");
  return a(), l("span", E, [
    (a(), u(B(t.interactive ? "button" : "span"), I({
      id: t.id,
      "aria-label": t.ariaLabel,
      "aria-labelledby": t.ariaLabel ? void 0 : `${t.id}-content`,
      "aria-disabled": t.disabled,
      class: i.chipClasses(),
      type: t.interactive && "button",
      "data-qa": "dt-chip",
      tabindex: t.disabled ? -1 : null
    }, O(i.chipListeners)), {
      default: h(() => [
        n.hasSlotContent(e.$slots.icon) ? (a(), l("span", L, [
          d(e.$slots, "icon")
        ])) : n.hasSlotContent(e.$slots.avatar) ? (a(), l("span", T, [
          d(e.$slots, "avatar")
        ])) : o("", !0),
        n.hasSlotContent(e.$slots.default) ? (a(), l("span", {
          key: 2,
          id: `${t.id}-content`,
          class: b(["d-chip__text", t.contentClass]),
          "data-qa": "dt-chip-label"
        }, [
          d(e.$slots, "default")
        ], 10, q)) : o("", !0)
      ]),
      _: 3
    }, 16, ["id", "aria-label", "aria-labelledby", "aria-disabled", "class", "type", "tabindex"])),
    t.hideClose ? o("", !0) : (a(), u(_, {
      key: 0,
      class: b(i.chipCloseButtonClasses()),
      "data-qa": "dt-chip-close",
      "aria-label": i.closeButtonTitle,
      "aria-disabled": t.disabled,
      title: i.closeButtonTitle,
      tabindex: t.disabled ? -1 : null,
      onClick: s[0] || (s[0] = (A) => e.$emit("close"))
    }, {
      icon: h(() => [
        v(m, { size: i.closeButtonIconSize }, null, 8, ["size"])
      ]),
      _: 1
    }, 8, ["class", "aria-label", "aria-disabled", "title", "tabindex"]))
  ]);
}
const F = /* @__PURE__ */ g(D, [["render", w]]);
export {
  F as default
};
//# sourceMappingURL=chip.js.map
