import { DtIconClose as _ } from "@dialpad/dialtone-icons/vue3";
import { CHIP_CLOSE_BUTTON_SIZE_MODIFIERS as f, CHIP_SIZE_MODIFIERS as r, CHIP_ICON_SIZES as y } from "./chip-constants.js";
import { hasSlotContent as b, getUniqueString as S } from "../../common/utils/index.js";
import { DialtoneLocalization as k } from "../../localization/index.js";
import { resolveComponent as d, createElementBlock as a, openBlock as s, createBlock as u, createCommentVNode as n, resolveDynamicComponent as B, mergeProps as I, toHandlers as O, withCtx as h, renderSlot as c, normalizeClass as p, 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: _
  },
  props: {
    /**
     * 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(r).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: b,
      i18n: new k()
    };
  },
  computed: {
    chipListeners() {
      return {
        click: (e) => {
          this.interactive && this.$emit("click", e);
        },
        keydown: (e) => {
          var o;
          ((o = e.code) == null ? void 0 : o.toLowerCase()) === "delete" ? this.onClose() : this.$emit("keydown", e);
        },
        keyup: (e) => {
          this.$emit("keyup", e);
        }
      };
    },
    closeButtonIconSize() {
      return y[this.size];
    },
    closeButtonTitle() {
      return this.i18n.$t("DIALTONE_CLOSE_BUTTON");
    }
  },
  methods: {
    chipClasses() {
      return [
        this.$attrs["grouped-chip"] ? "d-chip" : "d-chip__label",
        r[this.size],
        this.labelClass
      ];
    },
    chipCloseButtonClasses() {
      return [
        "d-chip__close",
        f[this.size]
      ];
    },
    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, o, t, N, l, i) {
  const m = d("dt-icon-close"), C = d("dt-button");
  return s(), a("span", E, [
    (s(), u(B(t.interactive ? "button" : "span"), I({
      id: t.id,
      "aria-label": t.ariaLabel,
      "aria-labelledby": t.ariaLabel ? void 0 : `${t.id}-content`,
      class: i.chipClasses(),
      type: t.interactive && "button",
      "data-qa": "dt-chip"
    }, O(i.chipListeners)), {
      default: h(() => [
        l.hasSlotContent(e.$slots.icon) ? (s(), a("span", L, [
          c(e.$slots, "icon")
        ])) : l.hasSlotContent(e.$slots.avatar) ? (s(), a("span", T, [
          c(e.$slots, "avatar")
        ])) : n("", !0),
        l.hasSlotContent(e.$slots.default) ? (s(), a("span", {
          key: 2,
          id: `${t.id}-content`,
          class: p(["d-chip__text", t.contentClass]),
          "data-qa": "dt-chip-label"
        }, [
          c(e.$slots, "default")
        ], 10, q)) : n("", !0)
      ]),
      _: 3
    }, 16, ["id", "aria-label", "aria-labelledby", "class", "type"])),
    t.hideClose ? n("", !0) : (s(), u(C, {
      key: 0,
      class: p(i.chipCloseButtonClasses()),
      "data-qa": "dt-chip-close",
      "aria-label": i.closeButtonTitle,
      title: i.closeButtonTitle,
      onClick: o[0] || (o[0] = (A) => e.$emit("close"))
    }, {
      icon: h(() => [
        v(m, { size: i.closeButtonIconSize }, null, 8, ["size"])
      ]),
      _: 1
    }, 8, ["class", "aria-label", "title"]))
  ]);
}
const R = /* @__PURE__ */ g(D, [["render", w]]);
export {
  R as default
};
//# sourceMappingURL=chip.js.map
