import * as vue from "vue";
import { defineComponent, unref, mergeProps, useSSRContext } from "vue";
import { ssrRenderAttrs, ssrRenderClass, ssrInterpolate, ssrRenderAttr, ssrRenderList } 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.2544f8a4.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";
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "InputSelectCustom",
  __ssrInlineRender: true,
  props: {
    modelValue: { type: [Number, String, Boolean], default: "" },
    list: {
      type: Array,
      default: () => []
    },
    defaultValue: { type: [Number, String, Boolean], default: "" },
    defaultText: { type: String, default: "" },
    listSuffix: { type: String, default: "" },
    classButton: { type: String, default: "" },
    classOption: { type: String, default: "" },
    disabled: { type: Boolean, default: false }
  },
  emits: ["update:modelValue"],
  setup(__props, { emit }) {
    const props = __props;
    vueRouter.useRouter();
    const active = vue.ref(false);
    const hovered = vue.ref(-1);
    if (!props.modelValue && props.defaultValue) {
      emit("update:modelValue", props.defaultValue);
    }
    const li = vue.computed(() => {
      var _a;
      return normalizeList((_a = props.list) != null ? _a : []);
    });
    const selectedItem = vue.computed(() => {
      let f = li.value.find((l) => l.value == props.modelValue);
      if (!f && props.defaultValue) {
        f = li.value.find((l) => l.value == props.defaultValue);
      }
      return f;
    });
    const selectedIndex = vue.computed(() => {
      return li.value.findIndex((_) => _.value == props.modelValue);
    });
    onResetUi(() => active.value = false);
    const isSelected = (value) => {
      return value && props.modelValue == value ? true : false;
    };
    const listItemClass = (item, i) => {
      let out = [];
      if (item.disabled) {
        out.push("opacity-60");
      } else {
        if (isSelected(item.value) && hovered.value === -1 || hovered.value === i) {
          out.push("bg-theme-500 text-theme-0 font-medium");
        } else if (isSelected(item.value)) {
          out.push("bg-theme-0 font-medium");
        } else {
          out.push("font-normal");
        }
        out.push(
          "cursor-pointer focus:text-white focus:bg-theme hover:text-theme-0 hover:bg-theme-500"
        );
      }
      return out.join(" ");
    };
    const buttonClasses = [
      "select-none",
      "group",
      "relative",
      "w-full",
      "cursor-pointer",
      "rounded-input",
      "border",
      "border-theme-300",
      "bg-theme-50",
      "py-input-y",
      "pl-3",
      "pr-8",
      "text-left",
      "text-input-size",
      "text-theme-700",
      "focus:outline-none"
    ];
    return (_ctx, _push, _parent, _attrs) => {
      var _a, _b;
      _push(`<div${ssrRenderAttrs(_attrs)} data-v-860c3fae><div class="text-theme-700 relative" data-v-860c3fae><div class="${ssrRenderClass([
        buttonClasses,
        unref(active) || __props.disabled ? "opacity-50" : "hover:border-input-edge",
        __props.classButton,
        __props.disabled ? "cursor-not-allowed" : "focus:ring-1 focus:ring-input-primary focus:border-input-primary"
      ])}" data-v-860c3fae><span class="flex w-full items-baseline truncate" data-v-860c3fae><span class="truncate" data-v-860c3fae>${ssrInterpolate(((_a = unref(selectedItem)) == null ? void 0 : _a.name) || __props.defaultValue || __props.defaultText || "Select")}</span><span class="select-description text-input-body-light ml-2 truncate text-xs" data-v-860c3fae>${ssrInterpolate((_b = unref(selectedItem)) == null ? void 0 : _b.desc)}</span></span><span class="${ssrRenderClass([unref(active) ? "text-theme-500" : "", "text-theme-500 group-hover:text-theme-400 pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2"])}" data-v-860c3fae><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-860c3fae><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-860c3fae></path></svg></span></div><!-- For validation --><input${ssrRenderAttrs(mergeProps({ class: "absolute float-left block h-0 w-0 p-0 opacity-0" }, _ctx.$attrs, {
        type: "text",
        value: __props.modelValue
      }))} data-v-860c3fae>`);
      if (unref(active)) {
        _push(`<div class="absolute z-50 mt-1 w-full rounded-md bg-white shadow-xl" data-v-860c3fae><ul role="listbox" aria-labelledby="listbox-label"${ssrRenderAttr("aria-activedescendant", `listbox-item-${unref(selectedIndex)}`)} class="max-h-60 overflow-auto rounded-md shadow focus:outline-none" data-v-860c3fae><!--[-->`);
        ssrRenderList(unref(li), (item, i) => {
          _push(`<!--[-->`);
          if (item.format == "divider") {
            _push(`<li class="" data-v-860c3fae><div class="border-input-edge w-full border-t" data-v-860c3fae></div></li>`);
          } else if (item.format == "title") {
            _push(`<li class="text-input-body-light mt-4 mb-2" data-v-860c3fae><div class="px-4 text-xs font-semibold uppercase" data-v-860c3fae>${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-860c3fae><div class="${ssrRenderClass([__props.classOption, "flex items-baseline truncate"])}" data-v-860c3fae><span class="${ssrRenderClass([item.desc ? "" : "w-full", "shrink-0 truncate"])}" data-v-860c3fae>${ssrInterpolate(item.name)}</span>`);
            if (item.desc) {
              _push(`<span class="ml-2 truncate opacity-50" data-v-860c3fae>${ssrInterpolate(item.desc)}</span>`);
            } else {
              _push(`<!---->`);
            }
            if (isSelected(item.value)) {
              _push(`<span class="${ssrRenderClass([
                unref(hovered) !== i ? "text-input-primary group-hover:text-white" : "",
                "absolute inset-y-0 right-0 flex items-center pr-3"
              ])}" data-v-860c3fae><!-- Heroicon name: check --><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-860c3fae><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-860c3fae></path></svg></span>`);
            } else {
              _push(`<!---->`);
            }
            _push(`</div></li>`);
          }
          _push(`<!--]-->`);
        });
        _push(`<!--]--></ul></div>`);
      } else {
        _push(`<!---->`);
      }
      _push(`</div></div>`);
    };
  }
});
const InputSelectCustom_vue_vue_type_style_index_0_scoped_860c3fae_lang = "";
const _sfc_setup = _sfc_main.setup;
_sfc_main.setup = (props, ctx) => {
  const ssrContext = useSSRContext();
  (ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("../ui/InputSelectCustom.vue");
  return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
const InputSelect = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-860c3fae"]]);
export {
  InputSelect as default
};
