import * as vue from "vue";
import { defineComponent, mergeProps, unref, useSSRContext } from "vue";
import { ssrRenderAttrs, ssrRenderList, ssrRenderComponent } from "vue/server-renderer";
import { I as normalizeList } from "../mount.js";
import "js-cookie";
import "events";
import "http";
import { D as DraggableList } from "./index.2544f8a4.js";
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 "@medv/finder";
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 _sfc_main$1 } from "./InputElTab.f30b58ad.js";
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 "vue-router";
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: "InputRanking",
  __ssrInlineRender: true,
  props: {
    modelValue: { type: Array, default: () => [] },
    list: {
      type: Array,
      default: () => []
    }
  },
  emits: ["update:modelValue"],
  setup(__props, { emit }) {
    const props = __props;
    const rankingEl = vue.ref();
    const parsedList = vue.computed(() => {
      const li = props.list ? normalizeList(props.list) : [];
      return li.sort((a, b) => {
        const ap = a.value;
        const bp = b.value;
        const rankA = props.modelValue.indexOf(ap);
        const rankB = props.modelValue.indexOf(bp);
        let result = 0;
        if (rankA < rankB) {
          result = -1;
        } else if (rankA > rankB) {
          result = 1;
        }
        return result;
      });
    });
    vue.onMounted(async () => {
      const wrap = rankingEl.value;
      const update = () => {
        const rank = [];
        wrap == null ? void 0 : wrap.querySelectorAll("[data-value]").forEach((el) => {
          const element = el;
          const value = element.dataset.value;
          if (value) {
            rank.push(value);
          }
        });
        emit("update:modelValue", rank);
      };
      new DraggableList({
        wrapClass: "ranking",
        draggableClass: "ranking-item",
        ghostClasses: ["ring-4", "ring-theme-100", "ring-offset-2"],
        onUpdate: () => update()
      });
    });
    return (_ctx, _push, _parent, _attrs) => {
      _push(`<div${ssrRenderAttrs(mergeProps({
        ref_key: "rankingEl",
        ref: rankingEl,
        class: "ranking space-y-2"
      }, _attrs))}>`);
      if (unref(parsedList).length == 0) {
        _push(`<div class="border-theme-300 bg-theme-50 text-theme-400 rounded-lg border border-dashed py-2 px-4 text-sm"> No options </div>`);
      } else {
        _push(`<!--[-->`);
        ssrRenderList(unref(parsedList), (item, i) => {
          _push(ssrRenderComponent(_sfc_main$1, {
            key: item.value,
            class: "ranking-item cursor-move",
            prefix: i + 1,
            label: item.name,
            draggable: "true",
            "data-value": item.value,
            icon: "i-carbon-draggable"
          }, null, _parent));
        });
        _push(`<!--]-->`);
      }
      _push(`</div>`);
    };
  }
});
const _sfc_setup = _sfc_main.setup;
_sfc_main.setup = (props, ctx) => {
  const ssrContext = useSSRContext();
  (ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("../ui/InputRanking.vue");
  return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
export {
  _sfc_main as default
};
