import { defineComponent as y, ref as p, createElementBlock as v, openBlock as c, Fragment as u, createElementVNode as T, createVNode as i, renderList as x, createBlock as b, unref as r, withCtx as g, createTextVNode as h } from "vue";
import { useModal as d, ScalarButton as k } from "@scalar/components";
import { ScalarIconPlus as M } from "@scalar/icons";
import S from "./components/EnvironmentCreateModal.vue.js";
import N from "./components/EnvironmentDeleteModal.vue.js";
import w from "./components/Environment.vue.js";
const A = { class: "text-c-3 flex h-full items-center justify-center rounded-lg border p-4" }, z = /* @__PURE__ */ y({
  __name: "EnvironmentsList",
  props: {
    environments: {},
    eventBus: {},
    activeEnvironment: {},
    collectionType: {}
  },
  setup(e) {
    const s = d(), m = d(), t = p(null), f = (o) => {
      t.value = o, m.show();
    }, E = () => {
      t.value && e.eventBus.emit("environment:delete:environment", {
        environmentName: t.value,
        collectionType: e.collectionType
      });
    }, a = (o) => {
      t.value = o ?? null, s.show();
    };
    return (o, l) => (c(), v(u, null, [
      (c(!0), v(u, null, x(Object.entries(e.environments), ([n, B]) => (c(), b(w, {
        key: n,
        collectionType: e.collectionType,
        environment: B,
        environmentName: n,
        eventBus: e.eventBus,
        isActive: e.activeEnvironment === n,
        onDelete: () => f(n),
        onEdit: () => a(n)
      }, null, 8, ["collectionType", "environment", "environmentName", "eventBus", "isActive", "onDelete", "onEdit"]))), 128)),
      T("div", A, [
        i(r(k), {
          class: "hover:bg-b-2 hover:text-c-1 flex items-center gap-2",
          size: "xs",
          variant: "ghost",
          onClick: l[0] || (l[0] = () => a())
        }, {
          default: g(() => [
            i(r(M)),
            l[1] || (l[1] = h(" Add Environment ", -1))
          ]),
          _: 1
        })
      ]),
      i(S, {
        collectionType: e.collectionType,
        environments: e.environments,
        eventBus: e.eventBus,
        selectedEnvironmentName: t.value,
        state: r(s)
      }, null, 8, ["collectionType", "environments", "eventBus", "selectedEnvironmentName", "state"]),
      i(N, {
        name: t.value,
        state: r(m),
        onSubmit: E
      }, null, 8, ["name", "state"])
    ], 64));
  }
});
export {
  z as default
};
