var m = Object.defineProperty;
var b = (e, t, r) => t in e ? m(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
var p = (e, t, r) => (b(e, typeof t != "symbol" ? t + "" : t, r), r);
import { iG as g, iH as x, a0 as i, iI as w, iw as v, f as C, V as o, b9 as d, e as I, P as l, iJ as L, bh as u, fE as V, iK as k, v as P, iL as q, iM as S, he as A, dr as E, iN as N, iO as F, gj as j, iP as O } from "./684d2f28.js";
import Q, { useContext as h, useState as f, useEffect as R, Fragment as _ } from "react";
class X {
  constructor(t, r) {
    p(this, "queryLibraryComp");
    p(this, "setQueryLibraryState");
    this.queryLibraryComp = t, this.setQueryLibraryState = r;
  }
  changeStateFn(t) {
    this.setQueryLibraryState((r) => {
      const n = t(r);
      return g(r, n);
    });
  }
  setComp(t) {
    this.changeStateFn((r) => ({ queryLibraryComp: t(r.queryLibraryComp) }));
  }
  getNameGenerator() {
    const t = new v(), r = this.nameAndExposingInfo();
    return t.init(Object.keys(r)), t;
  }
  nameAndExposingInfo() {
    return this.queryLibraryComp.nameAndExposingInfo();
  }
  checkRename(t, r) {
    const n = x(r);
    return n || (r !== t && this.nameAndExposingInfo().hasOwnProperty(r) ? i("query.nameExists", { name: r }) : "");
  }
  rename(t, r) {
    return this.checkRename(t, r) ? !1 : (r !== t && this.queryLibraryComp.dispatch(w(t, r)), !0);
  }
}
const y = Q.createContext(void 0), G = {
  name: k,
  description: P(""),
  value: q
}, M = (e) => {
  const [t, r] = f(e.showPopover), n = h(y), c = e.comp.children.name.getView();
  return /* @__PURE__ */ l("div", {
    style: {
      position: "relative",
      width: "100%"
    },
    children: [e.comp.children.value.propertyView({
      key: c,
      label: /* @__PURE__ */ o(S, {
        visible: t,
        setVisible: r,
        content: /* @__PURE__ */ l(u, {
          children: [e.comp.children.name.propertyView({
            label: i("queryLibrary.inputName"),
            onValidate: (a, s) => n.checkRename(a, s),
            onFinish: (a, s) => n.rename(a, s)
          }), /* @__PURE__ */ o(A, {
            label: i("queryLibrary.inputDesc"),
            children: /* @__PURE__ */ o(E, {
              value: e.comp.children.description.getView(),
              onChange: (a) => {
                e.comp.children.description.dispatchChangeValueAction(a.target.value);
              }
            })
          })]
        }),
        title: i("edit"),
        children: /* @__PURE__ */ o("div", {
          style: {
            cursor: "pointer"
          },
          children: c
        })
      }),
      layout: "vertical",
      tooltip: e.comp.children.description.getView()
    }), /* @__PURE__ */ o(N, {
      items: [{
        text: i("edit"),
        onClick: () => r(!0)
      }],
      del: e.onDelete,
      children: /* @__PURE__ */ o(W, {
        tabIndex: -1
      })
    })]
  });
}, B = class extends C(G) {
  propertyView(e) {
    return /* @__PURE__ */ o(M, {
      comp: this,
      ...e
    });
  }
}, D = O(B, {}, (e) => e.children.value.exposingNode()), T = d.div`
  padding: 0 16px;
`, W = d(F)`
  cursor: pointer;
  flex-shrink: 0;
  position: absolute;
  top: 0;
  right: 0;

  g {
    fill: #8b8fa3;
  }

  &:hover {
    background: #eef0f3;
    border-radius: 4px;
    cursor: pointer;

    g {
      fill: #3377ff;
    }
  }
`, J = d(j)`
  height: 28px;
  width: 70px;
  background-color: #fafbff;
  color: #4965f2;
  border-color: #c9d1fc;
  display: flex;
  align-items: center;
  box-shadow: none;

  &:hover {
    color: #315efb;
    background-color: #f5faff;
    border-color: #c2d6ff;
  }

  &:focus {
    color: #315efb;
    background-color: #f5faff;
    border-color: #c2d6ff;
  }

  &:disabled,
  &:disabled:hover {
    background: #f9fbff;
    border: 1px solid #dee9ff;
    border-radius: 4px;
  }
`, z = d.div`
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
`, H = I(V(D), (e) => {
  const t = h(y), [r, n] = f(void 0);
  R(() => {
    n(void 0);
  }, [e]);
  const c = () => {
    e.dispatch(e.pushAction({
      name: t.getNameGenerator().genItemName("queryInput")
    })), n(e.getView().length);
  };
  return /* @__PURE__ */ o(T, {
    children: e.getView().length > 0 ? /* @__PURE__ */ l(z, {
      children: [e.getView().map((a, s) => /* @__PURE__ */ o(_, {
        children: a.propertyView({
          onDelete: () => e.dispatch(e.deleteAction(s)),
          showPopover: s === r
        })
      }, s)), /* @__PURE__ */ o(J, {
        onClick: c,
        children: i("addItem")
      })]
    }) : /* @__PURE__ */ o(L, {
      text: /* @__PURE__ */ l(u, {
        children: [/* @__PURE__ */ o("div", {
          children: i("queryLibrary.emptyInputs")
        }), /* @__PURE__ */ o("span", {
          style: {
            color: "#4965f2",
            cursor: "pointer",
            margin: "0 4px"
          },
          onClick: c,
          children: i("queryLibrary.clickToAdd")
        })]
      })
    })
  });
}), Y = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  InputListComp: H
}, Symbol.toStringTag, { value: "Module" }));
export {
  H as I,
  y as Q,
  X as a,
  Y as i
};
