import { defineComponent, ref, computed, unref, withCtx, createTextVNode, toDisplayString, createVNode, createBlock, createCommentVNode, openBlock, Fragment, renderList, useSSRContext } from "vue";
import { ssrRenderComponent, ssrInterpolate, ssrRenderList } from "vue/server-renderer";
import { Head, Link } from "@inertiajs/vue3";
import { _ as _sfc_main$1 } from "./AppLayout-DXKl-uoF.js";
import { _ as _export_sfc } from "./_plugin-vue_export-helper-1tPrXgE0.js";
import "class-variance-authority";
import "./AppLogoIcon-DhmQfNIw.js";
import "clsx";
import "tailwind-merge";
import "reka-ui";
import "@vueuse/core";
import "lucide-vue-next";
import "./Input-CFG4Vy8n.js";
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "Stats",
  __ssrInlineRender: true,
  props: ["installers"],
  setup(__props) {
    const breadcrumbs = [
      {
        title: "Статистика монтажников",
        href: "/installers/stats"
      }
    ];
    const props = __props;
    const sortKey = ref("name");
    const sortAsc = ref(true);
    const sortedInstallers = computed(() => {
      return [...props.installers].sort((a, b) => {
        let valA = a[sortKey.value];
        let valB = b[sortKey.value];
        if (valA == null) valA = sortKey.value === "name" ? "" : -Infinity;
        if (valB == null) valB = sortKey.value === "name" ? "" : -Infinity;
        if (typeof valA === "string" && typeof valB === "string") {
          valA = valA.toLowerCase();
          valB = valB.toLowerCase();
          if (valA < valB) return sortAsc.value ? -1 : 1;
          if (valA > valB) return sortAsc.value ? 1 : -1;
          return 0;
        }
        if (typeof valA === "number" && typeof valB === "number") {
          return sortAsc.value ? valA - valB : valB - valA;
        }
        valA = String(valA);
        valB = String(valB);
        if (valA < valB) return sortAsc.value ? -1 : 1;
        if (valA > valB) return sortAsc.value ? 1 : -1;
        return 0;
      });
    });
    function sortBy(key) {
      if (sortKey.value === key) {
        sortAsc.value = !sortAsc.value;
      } else {
        sortKey.value = key;
        sortAsc.value = true;
      }
    }
    function formatHours(hours) {
      if (hours == null || isNaN(hours)) return "—";
      const h = Math.floor(hours);
      const m = Math.round((hours - h) * 60);
      return `${h}ч ${m}м`;
    }
    return (_ctx, _push, _parent, _attrs) => {
      _push(`<!--[-->`);
      _push(ssrRenderComponent(unref(Head), { title: "Статистика монтажников" }, null, _parent));
      _push(ssrRenderComponent(_sfc_main$1, { breadcrumbs }, {
        default: withCtx((_, _push2, _parent2, _scopeId) => {
          if (_push2) {
            _push2(`<div class="flex h-full flex-1 flex-col gap-4 rounded-xl p-4" data-v-e4455394${_scopeId}><h1 class="text-2xl font-bold mb-4" data-v-e4455394${_scopeId}>Статистика по монтажникам</h1><table class="w-full text-sm text-left text-gray-700" data-v-e4455394${_scopeId}><thead class="text-xs text-gray-500 uppercase bg-gray-50 border-b border-gray-200" data-v-e4455394${_scopeId}><tr data-v-e4455394${_scopeId}><th class="px-4 py-3 cursor-pointer select-none" data-v-e4455394${_scopeId}><div class="flex items-center gap-1" data-v-e4455394${_scopeId}> Имя `);
            if (sortKey.value === "name") {
              _push2(`<span data-v-e4455394${_scopeId}>${ssrInterpolate(sortAsc.value ? "▲" : "▼")}</span>`);
            } else {
              _push2(`<!---->`);
            }
            _push2(`</div></th><th class="px-4 py-3 cursor-pointer select-none" data-v-e4455394${_scopeId}><div class="flex items-center gap-1" data-v-e4455394${_scopeId}> Рейтинг `);
            if (sortKey.value === "ratings_received_avg") {
              _push2(`<span data-v-e4455394${_scopeId}>${ssrInterpolate(sortAsc.value ? "▲" : "▼")}</span>`);
            } else {
              _push2(`<!---->`);
            }
            _push2(`</div></th><th class="px-4 py-3 cursor-pointer select-none" data-v-e4455394${_scopeId}><div class="flex items-center gap-1" data-v-e4455394${_scopeId}> Завершено `);
            if (sortKey.value === "completed_count") {
              _push2(`<span data-v-e4455394${_scopeId}>${ssrInterpolate(sortAsc.value ? "▲" : "▼")}</span>`);
            } else {
              _push2(`<!---->`);
            }
            _push2(`</div></th><th class="px-4 py-3 cursor-pointer select-none" data-v-e4455394${_scopeId}><div class="flex items-center gap-1" data-v-e4455394${_scopeId}> Отказов `);
            if (sortKey.value === "rejected_count") {
              _push2(`<span data-v-e4455394${_scopeId}>${ssrInterpolate(sortAsc.value ? "▲" : "▼")}</span>`);
            } else {
              _push2(`<!---->`);
            }
            _push2(`</div></th><th class="px-4 py-3 cursor-pointer select-none" data-v-e4455394${_scopeId}><div class="flex items-center gap-1" data-v-e4455394${_scopeId}> Ср. время `);
            if (sortKey.value === "avg_hours") {
              _push2(`<span data-v-e4455394${_scopeId}>${ssrInterpolate(sortAsc.value ? "▲" : "▼")}</span>`);
            } else {
              _push2(`<!---->`);
            }
            _push2(`</div></th></tr></thead><tbody class="divide-y divide-gray-100" data-v-e4455394${_scopeId}><!--[-->`);
            ssrRenderList(sortedInstallers.value, (installer) => {
              var _a;
              _push2(`<tr class="hover:bg-gray-50 transition-colors" data-v-e4455394${_scopeId}><td class="px-4 py-3 font-medium text-gray-800 whitespace-nowrap" data-v-e4455394${_scopeId}>`);
              _push2(ssrRenderComponent(unref(Link), {
                href: `/installers/${installer.id}`,
                class: "text-blue-600 hover:underline"
              }, {
                default: withCtx((_2, _push3, _parent3, _scopeId2) => {
                  if (_push3) {
                    _push3(`${ssrInterpolate(installer.name)}`);
                  } else {
                    return [
                      createTextVNode(toDisplayString(installer.name), 1)
                    ];
                  }
                }),
                _: 2
              }, _parent2, _scopeId));
              _push2(`</td><td class="px-4 py-3" data-v-e4455394${_scopeId}>${ssrInterpolate(((_a = installer.ratings_received_avg) == null ? void 0 : _a.toFixed(1)) ?? "—")}</td><td class="px-4 py-3" data-v-e4455394${_scopeId}>${ssrInterpolate(installer.completed_count)}</td><td class="px-4 py-3" data-v-e4455394${_scopeId}>${ssrInterpolate(installer.rejected_count)}</td><td class="px-4 py-3" data-v-e4455394${_scopeId}>${ssrInterpolate(formatHours(installer.avg_hours))}</td></tr>`);
            });
            _push2(`<!--]--></tbody></table></div>`);
          } else {
            return [
              createVNode("div", { class: "flex h-full flex-1 flex-col gap-4 rounded-xl p-4" }, [
                createVNode("h1", { class: "text-2xl font-bold mb-4" }, "Статистика по монтажникам"),
                createVNode("table", { class: "w-full text-sm text-left text-gray-700" }, [
                  createVNode("thead", { class: "text-xs text-gray-500 uppercase bg-gray-50 border-b border-gray-200" }, [
                    createVNode("tr", null, [
                      createVNode("th", {
                        onClick: ($event) => sortBy("name"),
                        class: "px-4 py-3 cursor-pointer select-none"
                      }, [
                        createVNode("div", { class: "flex items-center gap-1" }, [
                          createTextVNode(" Имя "),
                          sortKey.value === "name" ? (openBlock(), createBlock("span", { key: 0 }, toDisplayString(sortAsc.value ? "▲" : "▼"), 1)) : createCommentVNode("", true)
                        ])
                      ], 8, ["onClick"]),
                      createVNode("th", {
                        onClick: ($event) => sortBy("ratings_received_avg"),
                        class: "px-4 py-3 cursor-pointer select-none"
                      }, [
                        createVNode("div", { class: "flex items-center gap-1" }, [
                          createTextVNode(" Рейтинг "),
                          sortKey.value === "ratings_received_avg" ? (openBlock(), createBlock("span", { key: 0 }, toDisplayString(sortAsc.value ? "▲" : "▼"), 1)) : createCommentVNode("", true)
                        ])
                      ], 8, ["onClick"]),
                      createVNode("th", {
                        onClick: ($event) => sortBy("completed_count"),
                        class: "px-4 py-3 cursor-pointer select-none"
                      }, [
                        createVNode("div", { class: "flex items-center gap-1" }, [
                          createTextVNode(" Завершено "),
                          sortKey.value === "completed_count" ? (openBlock(), createBlock("span", { key: 0 }, toDisplayString(sortAsc.value ? "▲" : "▼"), 1)) : createCommentVNode("", true)
                        ])
                      ], 8, ["onClick"]),
                      createVNode("th", {
                        onClick: ($event) => sortBy("rejected_count"),
                        class: "px-4 py-3 cursor-pointer select-none"
                      }, [
                        createVNode("div", { class: "flex items-center gap-1" }, [
                          createTextVNode(" Отказов "),
                          sortKey.value === "rejected_count" ? (openBlock(), createBlock("span", { key: 0 }, toDisplayString(sortAsc.value ? "▲" : "▼"), 1)) : createCommentVNode("", true)
                        ])
                      ], 8, ["onClick"]),
                      createVNode("th", {
                        onClick: ($event) => sortBy("avg_hours"),
                        class: "px-4 py-3 cursor-pointer select-none"
                      }, [
                        createVNode("div", { class: "flex items-center gap-1" }, [
                          createTextVNode(" Ср. время "),
                          sortKey.value === "avg_hours" ? (openBlock(), createBlock("span", { key: 0 }, toDisplayString(sortAsc.value ? "▲" : "▼"), 1)) : createCommentVNode("", true)
                        ])
                      ], 8, ["onClick"])
                    ])
                  ]),
                  createVNode("tbody", { class: "divide-y divide-gray-100" }, [
                    (openBlock(true), createBlock(Fragment, null, renderList(sortedInstallers.value, (installer) => {
                      var _a;
                      return openBlock(), createBlock("tr", {
                        key: installer.id,
                        class: "hover:bg-gray-50 transition-colors"
                      }, [
                        createVNode("td", { class: "px-4 py-3 font-medium text-gray-800 whitespace-nowrap" }, [
                          createVNode(unref(Link), {
                            href: `/installers/${installer.id}`,
                            class: "text-blue-600 hover:underline"
                          }, {
                            default: withCtx(() => [
                              createTextVNode(toDisplayString(installer.name), 1)
                            ]),
                            _: 2
                          }, 1032, ["href"])
                        ]),
                        createVNode("td", { class: "px-4 py-3" }, toDisplayString(((_a = installer.ratings_received_avg) == null ? void 0 : _a.toFixed(1)) ?? "—"), 1),
                        createVNode("td", { class: "px-4 py-3" }, toDisplayString(installer.completed_count), 1),
                        createVNode("td", { class: "px-4 py-3" }, toDisplayString(installer.rejected_count), 1),
                        createVNode("td", { class: "px-4 py-3" }, toDisplayString(formatHours(installer.avg_hours)), 1)
                      ]);
                    }), 128))
                  ])
                ])
              ])
            ];
          }
        }),
        _: 1
      }, _parent));
      _push(`<!--]-->`);
    };
  }
});
const _sfc_setup = _sfc_main.setup;
_sfc_main.setup = (props, ctx) => {
  const ssrContext = useSSRContext();
  (ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("resources/js/pages/installers/Stats.vue");
  return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
const Stats = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-e4455394"]]);
export {
  Stats as default
};
