import { a3 as i, hj as R, lm as V, H as t, ad as o, ln as C, le as P, lj as Q, f as S, I as m, iL as v, a4 as d, hi as I, lo as H, lp as T, gA as k, lq as z, ia as B, je as E, ji as D, cW as j, lr as M, eh as F, e as A, ls as W, lt as $, Q as G, cd as J, jj as K, lu as N, ii as O } from "./56c67d3b.js";
import { useState as b, useEffect as g } from "react";
import { Q as U, a as X, I as Y } from "./4541c1b9.js";
import { D as Z } from "./e6615772.js";
import { u as _, H as ee } from "./0f39f5bd.js";
import { M as te } from "./c320947b.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;
`, de = i.div`
  display: flex;
  align-items: center;
  gap: 12px;
`, se = i.div`
  position: relative;
  display: flex;
  height: calc(100% - 95px);
  width: 100%;
`, ae = 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 f;
  const {
    comp: e,
    title: l,
    subTitle: c,
    headerRight: p,
    bodyLeft: u,
    bodyRight: h
  } = r, y = e.children.query, n = R(V), [s, a] = b();
  return g(() => {
    const x = new X(e, (q) => {
      a((w) => w ? q(w) : void 0);
    });
    a(x);
  }, []), g(() => {
    s != null && s.setComp(() => e);
  }, [e]), s ? /* @__PURE__ */ t(U.Provider, {
    value: s,
    children: /* @__PURE__ */ o(re, {
      children: [/* @__PURE__ */ o(ie, {
        children: [/* @__PURE__ */ o(oe, {
          children: [l, /* @__PURE__ */ o(ne, {
            children: [C((f = n[y.children.id.getView()]) == null ? void 0 : f.createTime, 30 * 24 * 60 * 60 * 1e3), c]
          })]
        }), /* @__PURE__ */ t(de, {
          children: p
        })]
      }), /* @__PURE__ */ o(se, {
        children: [/* @__PURE__ */ t(ae, {
          children: u
        }), /* @__PURE__ */ t(le, {
          children: h
        })]
      })]
    })
  }) : 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;
`, L = (r) => {
  r.preventDefault();
}, he = () => {
  window.addEventListener("mousedown", L);
}, ye = () => {
  window.removeEventListener("mousedown", L);
}, fe = (r) => {
  var n;
  const e = (n = r.comp) == null ? void 0 : n.result(), [l, c] = b(360), {
    header: p,
    body: u
  } = _({
    ...e ?? {
      data: "",
      dataType: "default",
      success: !0
    },
    onClose: r.onClose
  });
  if (!e)
    return null;
  const h = document.documentElement.clientHeight, y = (s, a) => {
    c(a.size.height), ye();
  };
  return /* @__PURE__ */ t(pe, {
    width: 1 / 0,
    height: l,
    resizeHandles: ["n"],
    minConstraints: [680, 285],
    maxConstraints: [1 / 0, h - 48 - 95],
    onResizeStart: he,
    onResizeStop: y,
    children: /* @__PURE__ */ o(ue, {
      children: [/* @__PURE__ */ t(ee, {
        style: {
          cursor: "default"
        },
        children: p
      }), u]
    })
  });
}, xe = {
  query: A(G, (r) => /* @__PURE__ */ t(W.Provider, {
    value: {
      datasourceId: r.children.datasourceId.getView(),
      disableJSCompletion: !0,
      placement: "queryLibrary"
    },
    children: /* @__PURE__ */ t($, {
      comp: r,
      placement: "queryLibrary"
    })
  })),
  inputs: Y
}, me = S(xe), Ie = class extends me {
  propertyView(r) {
    return /* @__PURE__ */ t(ge, {
      comp: this,
      onPublish: r.onPublish,
      onHistoryShow: r.onHistoryShow,
      setModify: r.setModify,
      modify: r.modify
    });
  }
  getQueryPropertyView() {
    return this.children.query.getPropertyView();
  }
  getRightPropertyView() {
    return /* @__PURE__ */ o(m, {
      children: [/* @__PURE__ */ t(v, {
        name: d("prop.inputs"),
        width: 296,
        noMargin: !0,
        children: this.children.inputs.getPropertyView()
      }, "inputs"), /* @__PURE__ */ t(v, {
        name: d("prop.meta"),
        width: 296,
        noMargin: !0,
        children: /* @__PURE__ */ t("div", {
          style: {
            padding: " 0 8px"
          },
          children: /* @__PURE__ */ t(Z, {
            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;
  }
}, ge = (r) => {
  const {
    comp: e,
    onPublish: l,
    onHistoryShow: c,
    setModify: p,
    modify: u
  } = r, h = I(), [y, n] = b(!1), s = e.children.query.children.datasourceId.getView(), a = H(s);
  g(() => {
    n(!1);
  }, [e.children.query.children.id.getView()]);
  const f = () => e.children.query.dispatch(J({
    afterExecFunc: () => n(!0)
  }));
  return /* @__PURE__ */ t(te.Provider, {
    value: a,
    children: /* @__PURE__ */ t(T.Provider, {
      value: k(e.nameAndExposingInfo(), !1),
      children: /* @__PURE__ */ t(z, {
        global: !0,
        keyName: "command+enter",
        onKeyDown: f,
        allowRepeat: !0,
        wrapperStyle: {
          width: "100%"
        },
        children: /* @__PURE__ */ t(ce, {
          comp: e,
          title: /* @__PURE__ */ t(B, {
            text: e.children.query.children.name.getView(),
            onFinish: (x) => x !== e.children.query.children.name.getView() && e.dispatch(E(e.children.query.children.name.getView(), x))
          }),
          headerRight: /* @__PURE__ */ o(m, {
            children: [/* @__PURE__ */ t(D, {
              items: [{
                text: d("queryLibrary.publish"),
                onClick: l
              }, {
                text: d("queryLibrary.historyVersion"),
                onClick: c
              }],
              del: () => j.confirm({
                title: d("queryLibrary.deleteQueryLabel"),
                content: d("queryLibrary.deleteQueryContent"),
                onConfirm: () => {
                  h(M({
                    queryLibraryId: e.children.query.children.id.getView()
                  })), setTimeout(() => {
                    p(!u);
                  }, 500);
                },
                confirmBtnType: "delete",
                okText: d("delete")
              }),
              children: /* @__PURE__ */ t(we, {
                children: /* @__PURE__ */ t(be, {
                  tabIndex: -1
                })
              })
            }), /* @__PURE__ */ o(Le, {
              onClick: f,
              loading: e.children.query.children.isFetching.getView(),
              buttonType: "primary",
              children: [/* @__PURE__ */ t(ve, {}), d("queryLibrary.run")]
            })]
          }),
          bodyLeft: /* @__PURE__ */ o(m, {
            children: [e.getQueryPropertyView(), y && /* @__PURE__ */ t(fe, {
              comp: e.children.query,
              onClose: () => n(!1)
            })]
          }),
          bodyRight: /* @__PURE__ */ t(F, {
            children: e.getRightPropertyView()
          })
        })
      })
    })
  });
}, be = i(K)`
  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(N)`
  transform: rotate(-90deg);
  display: inline-block;
  padding-right: 2px;
  margin-right: 4px;
`, Le = i(O)`
  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 {
  Ie as QueryLibraryComp
};
