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 { jc as g, jd as x, a4 as i, je as w, hW as v, f as C, H as n, a3 as d, e as I, fJ as L, jf as k, v as V, jg as j, ad as l, jh as q, I as u, gx as P, f3 as S, ji as A, hn as E, jj as F, ii as N, jk as Q } from "./56c67d3b.js";
import R, { useState as h, useContext as f, useEffect as _, Fragment as O } 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 o = t(r);
      return g(r, o);
    });
  }
  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 o = x(r);
    return o || (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 = R.createContext(void 0), G = {
  name: k,
  description: V(""),
  value: j
}, W = (e) => {
  const [t, r] = h(e.showPopover), o = f(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__ */ n(q, {
        visible: t,
        setVisible: r,
        content: /* @__PURE__ */ l(u, {
          children: [e.comp.children.name.propertyView({
            label: i("queryLibrary.inputName"),
            onValidate: (a, s) => o.checkRename(a, s),
            onFinish: (a, s) => o.rename(a, s)
          }), /* @__PURE__ */ n(P, {
            label: i("queryLibrary.inputDesc"),
            children: /* @__PURE__ */ n(S, {
              value: e.comp.children.description.getView(),
              onChange: (a) => {
                e.comp.children.description.dispatchChangeValueAction(a.target.value);
              }
            })
          })]
        }),
        title: i("edit"),
        children: /* @__PURE__ */ n("div", {
          style: {
            cursor: "pointer"
          },
          children: c
        })
      }),
      layout: "vertical",
      tooltip: e.comp.children.description.getView()
    }), /* @__PURE__ */ n(A, {
      items: [{
        text: i("edit"),
        onClick: () => r(!0)
      }],
      del: e.onDelete,
      children: /* @__PURE__ */ n(T, {
        tabIndex: -1
      })
    })]
  });
}, B = class extends C(G) {
  propertyView(e) {
    return /* @__PURE__ */ n(W, {
      comp: this,
      ...e
    });
  }
}, D = Q(B, {}, (e) => e.children.value.exposingNode()), M = d.div`
  padding: 0 16px;
`, T = 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(N)`
  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(L(D), (e) => {
  const t = f(y), [r, o] = h(void 0);
  _(() => {
    o(void 0);
  }, [e]);
  const c = () => {
    e.dispatch(e.pushAction({
      name: t.getNameGenerator().genItemName("queryInput")
    })), o(e.getView().length);
  };
  return /* @__PURE__ */ n(M, {
    children: e.getView().length > 0 ? /* @__PURE__ */ l(z, {
      children: [e.getView().map((a, s) => /* @__PURE__ */ n(O, {
        children: a.propertyView({
          onDelete: () => e.dispatch(e.deleteAction(s)),
          showPopover: s === r
        })
      }, s)), /* @__PURE__ */ n(J, {
        onClick: c,
        children: i("addItem")
      })]
    }) : /* @__PURE__ */ n(E, {
      text: /* @__PURE__ */ l(u, {
        children: [/* @__PURE__ */ n("div", {
          children: i("queryLibrary.emptyInputs")
        }), /* @__PURE__ */ n("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
};
