import { ref as I, computed as u, watch as b } from "vue";
import { getSidebarValidationReport as V, validateSidebarItems as S } from "./sidebarValidator.js";
function T(a, f = {}) {
  const { autoValidate: h = !0, debounce: r = 0 } = f, l = I(null), p = u(() => {
    var e;
    return ((e = l.value) == null ? void 0 : e.isValid) ?? !0;
  }), s = u(() => {
    var e;
    return ((e = l.value) == null ? void 0 : e.errors) ?? [];
  }), g = u(() => {
    var e;
    return ((e = l.value) == null ? void 0 : e.warnings) ?? [];
  }), m = u(() => s.value.length), $ = u(() => g.value.length), v = u(() => l.value ? V(l.value) : "Валидация не выполнена");
  function i() {
    const e = S(a.value);
    return l.value = e, e;
  }
  function w() {
    l.value = null;
  }
  function E() {
    if (!l.value) {
      console.log("Валидация не выполнена");
      return;
    }
    if (console.group("📋 Детальный отчет валидации sidebar items"), console.log(v.value), s.value.length > 0) {
      console.log(`
📊 Детали ошибок:`);
      const e = /* @__PURE__ */ new Map();
      s.value.forEach((o) => {
        const n = o.path.match(/sidebarItems\[(\d+)\]/);
        if (n) {
          const t = parseInt(n[1]);
          e.has(t) || e.set(t, []), e.get(t).push(o);
        }
      });
      let d = 1;
      e.forEach((o, n) => {
        console.group(`
🔴 Sidebar Item [${n}] - ошибок: ${o.length}`), o.forEach((t) => {
          console.log(`
${d}. ${t.path}`), console.log(`   Сообщение: ${t.message}`), t.value !== void 0 && console.log("   Значение поля:", t.value), d++;
        }), a.value && a.value[n] && (console.log(`
📦 Полный объект sidebar item:`), console.log(a.value[n])), console.groupEnd();
      });
      const c = s.value.filter((o) => !o.path.match(/sidebarItems\[(\d+)\]/));
      c.length > 0 && (console.group(`
⚠️ Общие ошибки - ${c.length}`), c.forEach((o, n) => {
        console.log(`
${n + 1}. ${o.path}`), console.log(`   Сообщение: ${o.message}`), o.value !== void 0 && console.log("   Значение:", o.value);
      }), console.groupEnd());
    }
    console.groupEnd();
  }
  if (h) {
    let e = null;
    b(
      a,
      () => {
        r > 0 ? (e !== null && clearTimeout(e), e = window.setTimeout(() => {
          i(), e = null;
        }, r)) : i();
      },
      { deep: !0, immediate: !0 }
    );
  }
  return {
    validationResult: l,
    isValid: p,
    errors: s,
    warnings: g,
    errorCount: m,
    warningCount: $,
    report: v,
    validate: i,
    reset: w,
    showReport: E
  };
}
export {
  T as useSidebarValidator
};
