import * as vue from "vue";
import { defineComponent, mergeProps, unref, useSSRContext } from "vue";
import { ssrRenderAttrs, ssrRenderClass, ssrRenderList, ssrInterpolate, ssrRenderAttr } from "vue/server-renderer";
import { I as normalizeList } from "../mount.js";
import "js-cookie";
import "events";
import { o as onResetUi, _ as _export_sfc } from "./index.b92a68c6.js";
import "http";
import "@medv/finder";
import "front-matter";
import "markdown-it";
import "markdown-it-anchor";
import "markdown-it-implicit-figures";
import "markdown-it-link-attributes";
import "markdown-it-video";
import "remove-markdown";
import "body-parser";
import "path-browserify";
import "dotenv";
import "compression";
import "serve-favicon";
import "serve-static";
import "html-minifier";
import "vite";
import "@vue/server-renderer";
import "fs";
import "enquirer";
import "semver";
import "glob";
import "minimist";
import "handlebars";
import "execa";
import "multer";
import "sharp";
import "@vitejs/plugin-vue";
import * as vueRouter from "vue-router";
import "express";
import "axios";
import "knex";
import "dompurify";
import "dayjs";
import "chalk";
import "dayjs/plugin/relativeTime.js";
import "dayjs/plugin/utc.js";
import "dayjs/plugin/timezone.js";
import "dayjs/plugin/updateLocale.js";
import "dayjs/plugin/weekOfYear.js";
import "deepmerge";
import "fast-safe-stringify";
import "spark-md5";
import "nanoid";
import "is-plain-object";
import "prettyoutput";
import "consola";
import "validator";
import "@vueuse/head";
import "node-fetch";
import "jsonwebtoken";
import "fs-extra";
import "bcrypt";
import "knex-stringcase";
import "@sinclair/typebox";
import "nodemailer";
import "nodemailer-html-to-text";
import "@tailwindcss/forms";
import "unocss/vite";
import "@unocss/preset-icons";
import "nodemon";
import "gravatar-url";
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "InputSelectMulti",
  __ssrInlineRender: true,
  props: {
    modelValue: {
      type: [Array, String],
      default: () => []
    },
    list: { type: Array, default: () => {
    } }
  },
  emits: ["update:modelValue"],
  setup(__props, { emit }) {
    const props = __props;
    vueRouter.useRouter();
    const active = vue.ref(false);
    const hovered = vue.ref(-1);
    const li = vue.computed(() => {
      var _a;
      return normalizeList((_a = props.list) != null ? _a : ["no items"]).filter(
        (_) => _.value || _.format
      );
    });
    const val = vue.computed(() => {
      return typeof props.modelValue == "string" ? props.modelValue.split(",").map((_) => _.trim()) : props.modelValue;
    });
    const selected = vue.computed({
      get: () => {
        var _a;
        return (_a = val.value) != null ? _a : [];
      },
      set: (v) => {
        emit("update:modelValue", v);
      }
    });
    const getItemName = (val2) => {
      var _a;
      return ((_a = li.value.find((_) => _.value == val2)) == null ? void 0 : _a.name) || val2;
    };
    const isSelected = (value) => {
      return value ? selected.value.includes(value) : false;
    };
    const listItemClass = (item, i) => {
      var _a;
      let out = [];
      const val2 = (_a = item.value) != null ? _a : "";
      if (item.disabled) {
        out.push("text-theme-300");
      } else {
        if (hovered.value === i) {
          out.push("bg-theme-100 text-theme-800");
        } else if (isSelected(val2)) {
          out.push("bg-theme-0 text-theme-500");
        } else {
          out.push("text-theme-900");
        }
        out.push("cursor-pointer hover:text-theme-800 hover:bg-theme-50");
      }
      return out.join(" ");
    };
    onResetUi(() => active.value = false);
    const buttonClasses = [
      "group",
      "relative",
      "w-full",
      "cursor-pointer",
      "rounded-input",
      "border",
      "border-theme-300",
      "py-input-y",
      "pl-input-x",
      "pr-10",
      "text-left",
      "text-input-size",
      "bg-theme-50",
      "text-theme-700",
      "hover:border-theme-300",
      "focus:border-theme-400",
      "focus:outline-none",
      "focus:ring-4",
      "focus:ring-theme-50",
      "focus:ring-offset-2"
    ];
    return (_ctx, _push, _parent, _attrs) => {
      _push(`<label${ssrRenderAttrs(mergeProps({ class: "block" }, _attrs))} data-v-27d79748><div class="text-theme-800 relative" data-v-27d79748><div class="${ssrRenderClass(buttonClasses)}" data-v-27d79748><span class="flex w-full flex-wrap items-center" data-v-27d79748>`);
      if (unref(selected).length === 0) {
        _push(`<span class="truncate" data-v-27d79748>Select</span>`);
      } else {
        _push(`<!--[-->`);
        ssrRenderList(unref(selected), (v, i) => {
          _push(`<div class="border-theme-300 bg-theme-100 text-theme-600 my-1 mr-2 inline-flex select-none justify-center overflow-hidden rounded-md border text-xs" data-v-27d79748><div class="px-input-x py-input-y max-w-full flex-initial font-medium leading-none" data-v-27d79748>${ssrInterpolate(getItemName(v))}</div><div class="text-theme-400 border-theme-200 hover:bg-theme-100 flex cursor-pointer flex-col justify-center border-l px-1" data-v-27d79748><svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" data-v-27d79748><line x1="18" y1="6" x2="6" y2="18" data-v-27d79748></line><line x1="6" y1="6" x2="18" y2="18" data-v-27d79748></line></svg></div></div>`);
        });
        _push(`<!--]-->`);
      }
      _push(`<span class="${ssrRenderClass([unref(active) ? "text-theme-300" : "text-theme-500", "group-hover:text-theme-300 pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2"])}" data-v-27d79748><svg class="h-5 w-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" data-v-27d79748><path fill-rule="evenodd" d="M10 3a1 1 0 01.707.293l3 3a1 1 0 01-1.414 1.414L10 5.414 7.707 7.707a1 1 0 01-1.414-1.414l3-3A1 1 0 0110 3zm-3.707 9.293a1 1 0 011.414 0L10 14.586l2.293-2.293a1 1 0 011.414 1.414l-3 3a1 1 0 01-1.414 0l-3-3a1 1 0 010-1.414z" clip-rule="evenodd" data-v-27d79748></path></svg></span></span></div>`);
      if (unref(active)) {
        _push(`<div class="absolute top-full z-50 mt-1 w-full rounded-md bg-white shadow-lg ring-1 ring-black/10" data-v-27d79748><ul role="listbox" aria-labelledby="listbox-label" class="max-h-60 overflow-auto rounded-md shadow focus:outline-none" data-v-27d79748><!--[-->`);
        ssrRenderList(unref(li), (item, i) => {
          _push(`<!--[-->`);
          if (item.format == "divider") {
            _push(`<li data-v-27d79748><div class="border-theme-300 w-full border-t" data-v-27d79748></div></li>`);
          } else if (item.format == "title") {
            _push(`<li class="text-theme-300 mt-4 mb-2" data-v-27d79748><div class="px-4 text-xs font-semibold uppercase" data-v-27d79748>${ssrInterpolate(item.name)}</div></li>`);
          } else {
            _push(`<li${ssrRenderAttr("id", `listbox-item-${i}`)} role="option" class="${ssrRenderClass([listItemClass(item, i), "group py-input-y px-input-x text-input-size relative select-none"])}" data-v-27d79748><div class="flex items-center" data-v-27d79748><span class="truncate" data-v-27d79748>${ssrInterpolate(item.name)}</span>`);
            if (item.desc) {
              _push(`<span class="ml-2 truncate opacity-60" data-v-27d79748>${ssrInterpolate(item.desc)}</span>`);
            } else {
              _push(`<!---->`);
            }
            if (isSelected(item.value)) {
              _push(`<span class="${ssrRenderClass([
                unref(hovered) > -1 && unref(hovered) !== i ? "text-primary group-hover:text-primary-500" : "",
                "absolute inset-y-0 right-0 flex items-center pr-2"
              ])}" data-v-27d79748><!-- Heroicon name: check --><div class="text-primary rounded-full p-0.5" data-v-27d79748><svg class="h-4 w-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" data-v-27d79748><path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd" data-v-27d79748></path></svg></div></span>`);
            } else {
              _push(`<!---->`);
            }
            _push(`</div></li>`);
          }
          _push(`<!--]-->`);
        });
        _push(`<!--]--></ul></div>`);
      } else {
        _push(`<!---->`);
      }
      _push(`</div></label>`);
    };
  }
});
const InputSelectMulti_vue_vue_type_style_index_0_scoped_27d79748_lang = "";
const _sfc_setup = _sfc_main.setup;
_sfc_main.setup = (props, ctx) => {
  const ssrContext = useSSRContext();
  (ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("../ui/InputSelectMulti.vue");
  return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
const InputSelectMulti = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-27d79748"]]);
export {
  InputSelectMulti as default
};
