import { defineComponent as I, ref as f, provide as O, watch as $, openBlock as a, createElementBlock as m, Fragment as K, renderSlot as q, createBlock as k, Teleport as J, createElementVNode as x, normalizeStyle as A, unref as l, normalizeClass as b, createVNode as D, TransitionGroup as Q, withCtx as U, renderList as W, createCommentVNode as g, toDisplayString as C } from "vue";
import { injectNotificationKey as Y } from "../../composables/keys.js";
import { useColors as H } from "../../composables/useColors.js";
import { useCSS as Z } from "../../composables/useCSS.js";
import { useTheme as ee } from "../../composables/useTheme.js";
import { closeIcon as oe } from "../../common/icons.js";
import E from "../icon/Icon.vue.js";
import te from "../spacer/Spacer.js";
const se = { class: "flex items-center flex-wrap" }, re = {
  key: 0,
  class: "font-medium mr-2"
}, ae = ["onClick"], le = {
  ...H.props("primary"),
  align: {
    type: String,
    default: "right",
    validator: (n) => _.align.includes(n)
  },
  position: {
    type: String,
    default: "bottom",
    validator: (n) => _.position.includes(n)
  },
  timeout: {
    type: Number,
    default: 3500
  },
  removable: {
    type: Boolean,
    default: !0
  },
  injectKey: {
    type: [Symbol, String],
    default: Y
  }
}, _ = {
  align: ["left", "right"],
  position: ["bottom", "top"]
}, ne = {
  name: "XNotifications",
  validators: _
}, ge = /* @__PURE__ */ I({
  ...ne,
  props: le,
  setup(n, { expose: L }) {
    const s = n, i = f(s.align), r = f(s.position), p = f([]), z = f(null), R = Z("notification"), M = H();
    O(s.injectKey, {
      log: w,
      info: S,
      warn: d,
      error: P,
      warning: d,
      success: N
    }), $(() => s.align, (o) => {
      i.value = o;
    }), $(() => s.position, (o) => {
      r.value = o;
    });
    function w(o) {
      const t = typeof o == "string", e = {
        message: t ? o : void 0
      };
      c(t ? e : {
        ...e,
        ...o
      });
    }
    function S(o) {
      const t = typeof o == "string", e = {
        icon: '<path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd" />',
        iconColor: "sky",
        message: t ? o : void 0
      };
      c(t ? e : {
        ...e,
        ...o
      });
    }
    function N(o) {
      const t = typeof o == "string", e = {
        icon: '<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd" />',
        iconColor: "success",
        message: t ? o : void 0
      };
      c(t ? e : {
        ...e,
        ...o
      });
    }
    function d(o) {
      const t = typeof o == "string", e = {
        icon: '<path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd" />',
        iconColor: "warning",
        message: t ? o : void 0
      };
      c(t ? e : {
        ...e,
        ...o
      });
    }
    function P(o) {
      const t = typeof o == "string", e = {
        icon: '<path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z" clip-rule="evenodd" />',
        iconColor: "error",
        message: t ? o : void 0
      };
      c(t ? e : {
        ...e,
        ...o
      });
    }
    function c(o) {
      var V, j;
      const e = {
        ...{
          id: Date.now(),
          iconColor: s.color,
          timeout: s.timeout,
          align: i.value,
          position: r.value,
          removable: s.removable
        },
        ...o
      };
      i.value = e.align, r.value = e.position;
      const u = M.getPalette(e.iconColor), v = M.getPalette(((V = e.action) == null ? void 0 : V.color) || "primary"), T = R.variables({
        icon: u[400],
        action: v[400],
        hover: {
          action: v[500]
        },
        dark: {
          icon: u[500],
          action: v[500],
          hover: {
            action: v[600]
          }
        }
      });
      e.style = Object.keys(T).map((B) => `${B}: ${T[B]}`).join(";"), p.value.push(e), (j = z.value) == null || j.scrollTo({ top: 0, behavior: "smooth" }), e.timeout && X(e, e.timeout);
    }
    function y(o) {
      p.value = p.value.filter((t) => t.id !== o.id);
    }
    function X(o, t) {
      setTimeout(() => {
        y(o);
      }, t);
    }
    const { styles: F, classes: h, className: G } = ee("Notifications", {}, s);
    return L({ log: w, info: S, success: N, warn: d, warning: d, error: P }), (o, t) => (a(), m(K, null, [
      q(o.$slots, "default"),
      (a(), k(J, { to: "body" }, [
        x("div", {
          ref_key: "listRef",
          ref: z,
          style: A(l(F)),
          class: b([
            l(G),
            l(h).wrapper,
            {
              // align
              "left-0": i.value === "left",
              "right-0": i.value === "right",
              // position
              "top-0": r.value === "top",
              "bottom-0": r.value === "bottom"
            }
          ])
        }, [
          D(Q, {
            tag: "ul",
            class: b([
              l(h).list,
              { "flex-col-reverse": r.value }
            ]),
            "enter-active-class": "transition ease-out duration-200",
            "leave-active-class": "transition ease-out duration-100",
            "enter-from-class": "transform translate-y-2 opacity-0",
            "enter-to-class": "transform translate-y-0 opacity-100",
            "leave-from-class": "transform translate-y-0 opacity-100",
            "leave-to-class": "transform translate-y-2 opacity-0",
            "move-class": "ease-in-out duration-200"
          }, {
            default: U(() => [
              (a(!0), m(K, null, W(p.value, (e) => (a(), m("li", {
                key: e.id,
                class: b([
                  l(h).item,
                  {
                    "mb-2": r.value === "bottom",
                    "mt-2": r.value === "top"
                  }
                ]),
                style: A(e.style)
              }, [
                e.icon ? (a(), k(E, {
                  key: 0,
                  filled: "",
                  icon: e.icon,
                  class: "mr-4 text-[color:var(--x-notification-icon)] dark:text-[color:var(--x-notification-dark-icon)]",
                  viewBox: "0 0 20 20"
                }, null, 8, ["icon"])) : g("", !0),
                x("div", se, [
                  e.title ? (a(), m("span", re, C(e.title), 1)) : g("", !0),
                  x("span", null, C(e.message), 1)
                ]),
                D(l(te)),
                e.action ? (a(), m("button", {
                  key: 1,
                  type: "button",
                  class: "ml-3 font-medium cursor-pointer text-[color:var(--x-notification-action)] hover:text-[color:var(--x-notification-action-hover)] dark:text-[color:var(--x-notification-dark-action)] dark:hover:text-[color:var(--x-notification-dark-action-hover)]",
                  onClick: () => {
                    var u;
                    (u = e.action) == null || u.onClick(), y(e);
                  }
                }, C(e.action.label), 9, ae)) : g("", !0),
                e.removable ? (a(), k(E, {
                  key: 2,
                  icon: l(oe),
                  class: "text-secondary-400 hover:text-secondary-500 ml-3 cursor-pointer",
                  onClick: () => {
                    y(e);
                  }
                }, null, 8, ["icon", "onClick"])) : g("", !0)
              ], 6))), 128))
            ]),
            _: 1
          }, 8, ["class"])
        ], 6)
      ]))
    ], 64));
  }
});
export {
  ge as default
};
