import { b9 as i, i9 as V, jO as R, V as t, P as o, jP as C, gq as P, jK as Q, f as S, bh as x, hL as w, a0 as a, jQ as j, jB as I, jR as B, jS as H, jT as T, hh as k, jU as z, jV as E, iI as D, iN as F, eB as M, jW as A, d6 as W, e as J, jX as K, jY as N, Q as O, bJ as $, iO as G, jZ as U, gj as X } from "./684d2f28.js";
import { useState as g, useEffect as f } from "react";
import { Q as Y, a as Z, I as _ } from "./f65ac842.js";
import { u as ee, H as te } from "./63cfd7ef.js";
import "react-dom";
const re = i.div`
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  min-width: min-content;
`, ie = i.div`
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  height: 95px;
  flex-shrink: 0;
  padding: 32px 36px 0 16px;
  border-bottom: 1px solid #e1e3eb;
`, oe = i.div`
  display: flex;
  flex-direction: column;

  .taco-edit-text-wrapper {
    width: 252px;
    color: #222222;
    font-size: 18px;
    font-weight: 500;
    margin-left: -8px;

    &:hover {
      background-color: #f5f5f6;
    }
  }

  .taco-edit-text-input {
    width: 252px;
    color: #222222;
    font-weight: 500;
    font-size: 18px;
    background-color: #f5f5f6;
    border: 1px solid #3377ff;
    margin-left: -8px;

    &:focus {
      border-color: #3377ff;
      box-shadow: 0 0 0 2px #d6e4ff;
    }
  }
`, ne = i.div`
  display: flex;
  align-items: center;
  gap: 20px;
  font-size: 13px;
  color: #b8b9bf;
`, ae = i.div`
  display: flex;
  align-items: center;
  gap: 12px;
`, se = i.div`
  position: relative;
  display: flex;
  height: calc(100% - 95px);
  width: 100%;
`, de = i.div`
  position: relative;
  padding: 16px 16px 80px;
  flex-grow: 1;
  width: calc(100% - 297px);
`, le = i.div`
  height: 100%;
  width: 297px;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-left: 1px solid #e1e3eb;
`, ce = (r) => {
  var b;
  const {
    comp: e,
    title: c,
    subTitle: p,
    headerRight: u,
    bodyLeft: h,
    bodyRight: s
  } = r, y = e.children.query, l = V(R), [n, d] = g();
  return f(() => {
    const L = new Z(e, (q) => {
      d((m) => m ? q(m) : void 0);
    });
    d(L);
  }, []), f(() => {
    n != null && n.setComp(() => e);
  }, [e]), n ? /* @__PURE__ */ t(Y.Provider, {
    value: n,
    children: /* @__PURE__ */ o(re, {
      children: [/* @__PURE__ */ o(ie, {
        children: [/* @__PURE__ */ o(oe, {
          children: [c, /* @__PURE__ */ o(ne, {
            children: [C((b = l[y.children.id.getView()]) == null ? void 0 : b.createTime, 30 * 24 * 60 * 60 * 1e3), p]
          })]
        }), /* @__PURE__ */ t(ae, {
          children: u
        })]
      }), /* @__PURE__ */ o(se, {
        children: [/* @__PURE__ */ t(de, {
          children: h
        }), /* @__PURE__ */ t(le, {
          children: s
        })]
      })]
    })
  }) : null;
}, pe = i(Q)`
  position: absolute;
  box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);
  border-top: 1px solid #e1e3eb;
  z-index: ${P.queryResultPanel};
  width: 100%;
  bottom: 0;
  left: 0;
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;

  .react-resizable-handle {
    position: absolute;
    border-top: transparent solid 3px;
    width: 100%;
    padding: 0 3px 3px 0;
    top: 0;
    cursor: row-resize;
  }
`, ue = i.div`
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
`, v = (r) => {
  r.preventDefault();
}, he = () => {
  window.addEventListener("mousedown", v);
}, ye = () => {
  window.removeEventListener("mousedown", v);
}, xe = (r) => {
  var l;
  const e = (l = r.comp) == null ? void 0 : l.result(), [c, p] = g(360), {
    header: u,
    body: h
  } = ee({
    ...e ?? {
      data: "",
      dataType: "default",
      success: !0
    },
    onClose: r.onClose
  });
  if (!e)
    return null;
  const s = document.documentElement.clientHeight, y = (n, d) => {
    p(d.size.height), ye();
  };
  return /* @__PURE__ */ t(pe, {
    width: 1 / 0,
    height: c,
    resizeHandles: ["n"],
    minConstraints: [680, 285],
    maxConstraints: [1 / 0, s - 48 - 95],
    onResizeStart: he,
    onResizeStop: y,
    children: /* @__PURE__ */ o(ue, {
      children: [/* @__PURE__ */ t(te, {
        style: {
          cursor: "default"
        },
        children: u
      }), h]
    })
  });
}, fe = {
  query: J(O, (r) => /* @__PURE__ */ t(K.Provider, {
    value: {
      datasourceId: r.children.datasourceId.getView(),
      disableJSCompletion: !0,
      placement: "queryLibrary"
    },
    children: /* @__PURE__ */ t(N, {
      comp: r,
      placement: "queryLibrary"
    })
  })),
  inputs: _
}, ge = S(fe), Qe = class extends ge {
  propertyView(r) {
    return /* @__PURE__ */ t(be, {
      comp: this,
      onPublish: r.onPublish,
      onHistoryShow: r.onHistoryShow
    });
  }
  getQueryPropertyView() {
    return this.children.query.getPropertyView();
  }
  getRightPropertyView() {
    return /* @__PURE__ */ o(x, {
      children: [/* @__PURE__ */ t(w, {
        name: a("prop.inputs"),
        width: 296,
        noMargin: !0,
        children: this.children.inputs.getPropertyView()
      }, "inputs"), /* @__PURE__ */ t(w, {
        name: a("prop.meta"),
        width: 296,
        noMargin: !0,
        children: /* @__PURE__ */ t("div", {
          style: {
            padding: " 0 8px"
          },
          children: /* @__PURE__ */ t(j, {
            dataSourceId: this.children.query.children.datasourceId.getView(),
            datasourceType: this.children.query.children.compType.getView()
          })
        })
      }, "meta")]
    });
  }
  nameAndExposingInfo() {
    const r = {};
    return this.children.inputs.getView().forEach((e) => {
      r[e.children.name.getView()] = e.exposingInfo();
    }), r;
  }
}, be = (r) => {
  const {
    comp: e,
    onPublish: c,
    onHistoryShow: p
  } = r, u = I(), [h, s] = g(!1), y = e.children.query.children.datasourceId.getView(), l = B(y);
  f(() => {
    s(!1);
  }, [e.children.query.children.id.getView()]);
  const n = () => e.children.query.dispatch($({
    afterExecFunc: () => s(!0)
  }));
  return /* @__PURE__ */ t(H.Provider, {
    value: l,
    children: /* @__PURE__ */ t(T.Provider, {
      value: k(e.nameAndExposingInfo(), !1),
      children: /* @__PURE__ */ t(z, {
        global: !0,
        keyName: "command+enter",
        onKeyDown: n,
        allowRepeat: !0,
        wrapperStyle: {
          width: "100%"
        },
        children: /* @__PURE__ */ t(ce, {
          comp: e,
          title: /* @__PURE__ */ t(E, {
            text: e.children.query.children.name.getView(),
            onFinish: (d) => d !== e.children.query.children.name.getView() && e.dispatch(D(e.children.query.children.name.getView(), d))
          }),
          headerRight: /* @__PURE__ */ o(x, {
            children: [/* @__PURE__ */ t(F, {
              items: [{
                text: a("queryLibrary.publish"),
                onClick: c
              }, {
                text: a("queryLibrary.historyVersion"),
                onClick: p
              }],
              del: () => M.confirm({
                title: a("queryLibrary.deleteQueryLabel"),
                content: a("queryLibrary.deleteQueryContent"),
                onConfirm: () => u(A({
                  queryLibraryId: e.children.query.children.id.getView()
                })),
                confirmBtnType: "delete",
                okText: a("delete")
              }),
              children: /* @__PURE__ */ t(we, {
                children: /* @__PURE__ */ t(me, {
                  tabIndex: -1
                })
              })
            }), /* @__PURE__ */ o(Le, {
              onClick: n,
              loading: e.children.query.children.isFetching.getView(),
              buttonType: "primary",
              children: [/* @__PURE__ */ t(ve, {}), a("queryLibrary.run")]
            })]
          }),
          bodyLeft: /* @__PURE__ */ o(x, {
            children: [e.getQueryPropertyView(), h && /* @__PURE__ */ t(xe, {
              comp: e.children.query,
              onClose: () => s(!1)
            })]
          }),
          bodyRight: /* @__PURE__ */ t(W, {
            children: e.getRightPropertyView()
          })
        })
      })
    })
  });
}, me = i(G)`
  flex-shrink: 0;

  g {
    fill: #8b8fa3;
  }
`, we = i.div`
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 32px;
  width: 32px;
  border: 1px solid #d7d9e0;
  border-radius: 4px;

  &:hover {
    background-color: #f5f5f6;
    border: 1px solid #d7d9e0;

    g {
      fill: #222222;
    }
  }
`, ve = i(U)`
  transform: rotate(-90deg);
  display: inline-block;
  padding-right: 2px;
  margin-right: 4px;
`, Le = i(X)`
  padding: 0;
  width: 80px;
  height: 32px;
  border: none;

  &:hover {
    padding: 0;
    border: none;
    box-shadow: none;
  }

  &:focus {
    padding: 0;
    border: none;
    box-shadow: none;
  }

  &:after {
    content: "";
  }
`;
export {
  Qe as QueryLibraryComp
};
