var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
  return value;
};
import { dI as e, i2 as t, i3 as i, hE as r, hI as o, f as n, eX as s, ac as d, dH as a, hZ as l, h_ as p, i4 as h, cO as c, es as m, fG as y, fK as u, ev as f, i5 as b, dc as g, e as x, i6 as w, i7 as j, Q as v, dz as K, fL as q, i8 as k, ey as E } from "./index-f927b013.js";
import "./lodash-b5661970.js";
import { lz as V, lI as L, lJ as D } from "./ant-design-icons-6bfdc7d5.js";
import "./loglevel-b4003767.js";
import C, { useState as I, useEffect as P } from "react";
import { Q as z, a as T, I as U } from "./inputListComp-fb1b78aa.js";
import { u as H } from "./styled-components-7cfa37e6.js";
import { p as R } from "./fontawesome-3904a214.js";
import { h as S } from "./hotkeys-js-699906bc.js";
import { D as N } from "./BottomMetaDrawer-db0cdfbb.js";
import { u as M, H as Q } from "./index-37c096d4.js";
import "./axios-04f95181.js";
import "./redux-devtools-8dd21e4f.js";
import "./alasql-f60045ee.js";
import "./antd-2abdded3.js";
import "react-dom";
import "./dayjs-2035e031.js";
import "./dnd-kit-8227a2db.js";
import "./moment-059406e8.js";
import "./numbro-47982265.js";
import "./papaparse-07642d76.js";
import "./uuid-bd83cae2.js";
import "./supabase-b2e314d0.js";
import "./fetch-648a91f6.js";
import "./react-draggable-ed505bfc.js";
import "./remark-gfm-18306abe.js";
import "./buffer-d3713d77.js";
import "./rehype-raw-6ebcba88.js";
import "./parse5-f837f753.js";
import "./rehype-sanitize-953d0761.js";
import "./simplebar-react-2133d981.js";
import "./react-best-gradient-color-picker-92c01739.js";
import "./ua-parser-js-c952c07b.js";
import "./clsx-469c2c43.js";
import "./file-saver-55285fc1.js";
import "./codemirror-8412b963.js";
import "./really-relaxed-json-056be70b.js";
import "./immer-c0428a8d.js";
import "./cnchar-e1339167.js";
import "./react-documents-041601c7.js";
import "./react-sortable-hoc-4fbe0c32.js";
import "./sql-formatter-577b4ab0.js";
import "./rc-trigger-3f038851.js";
import "./react-json-view-5330ce92.js";
import "./qrcode-react-d377d762.js";
class A extends C.Component {
  constructor(e2) {
    super(e2);
    __publicField(this, "isKeyDown", false);
    __publicField(this, "preKey", "");
    __publicField(this, "handle");
    __publicField(this, "state");
    this.onKeyDown = this.onKeyDown.bind(this), this.onKeyUp = this.onKeyUp.bind(this), this.handleKeyUpEvent = this.handleKeyUpEvent.bind(this), this.handle = {}, this.state = { enableHotKey: e2.global || false };
  }
  componentDidMount() {
    const { splitKey: e2, filter: t2 } = this.props;
    t2 && (S.filter = t2), S.unbind(this.props.keyName), S(this.props.keyName, { splitKey: e2 }, this.onKeyDown), document && document.body.addEventListener("keyup", this.handleKeyUpEvent);
  }
  componentWillUnmount() {
    S.unbind(this.props.keyName), this.isKeyDown = true, this.handle = {}, document && document.body.removeEventListener("keyup", this.handleKeyUpEvent);
  }
  onKeyUp(e2, t2) {
    if (!this.state.enableHotKey)
      return;
    const { onKeyUp: i2, disabled: r2 } = this.props;
    !r2 && i2 && i2(t2.shortcut, e2, t2);
  }
  onKeyDown(e2, t2) {
    if (!this.state.enableHotKey)
      return;
    const { onKeyDown: i2, allowRepeat: r2, disabled: o2 } = this.props, n2 = t2.shortcut;
    this.isKeyDown && !r2 && this.preKey === n2 || (this.preKey = n2, this.isKeyDown = true, this.handle = t2, !o2 && i2 && i2(n2, e2, t2));
  }
  handleKeyUpEvent(e2) {
    this.isKeyDown && (this.isKeyDown = false, this.props.keyName && this.props.keyName.indexOf(this.handle.shortcut) < 0 || (this.onKeyUp(e2, this.handle), this.handle = {}));
  }
  render() {
    const { global: e2, wrapperStyle: t2 } = this.props;
    return V("div", { style: t2, tabIndex: -1, onFocus: () => !e2 && this.setState({ enableHotKey: true }), onBlur: () => {
      !e2 && this.setState({ enableHotKey: false });
    }, children: this.props.children || null });
  }
}
__publicField(A, "defaultProps", { filter(e2) {
  const t2 = e2.target || e2.srcElement, i2 = t2.tagName;
  return !(!e2.metaKey || "Enter" !== e2.code) || !(t2.isContentEditable || "INPUT" === i2 || "SELECT" === i2 || "TEXTAREA" === i2);
} });
__publicField(A, "propTypes", { keyName: R.string, filter: R.func, onKeyDown: R.func, onKeyUp: R.func, disabled: R.bool, splitKey: R.string });
const F = H.div`
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  min-width: min-content;
`, B = H.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;
`, O = H.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;
    }
  }
`, G = H.div`
  display: flex;
  align-items: center;
  gap: 20px;
  font-size: 13px;
  color: #b8b9bf;
`, J = H.div`
  display: flex;
  align-items: center;
  gap: 12px;
`, X = H.div`
  position: relative;
  display: flex;
  height: calc(100% - 95px);
  width: 100%;
`, W = H.div`
  position: relative;
  padding: 16px 16px 80px;
  flex-grow: 1;
  width: calc(100% - 297px);
`, Z = H.div`
  height: 100%;
  width: 297px;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-left: 1px solid #e1e3eb;
`, $ = (r2) => {
  var _a;
  const { comp: o2, title: n2, subTitle: s2, headerRight: d2, bodyLeft: a2, bodyRight: l2 } = r2, p2 = o2.children.query, h2 = e(t), [c2, m2] = I();
  return P(() => {
    const e2 = new T(o2, (e3) => {
      m2((t2) => t2 ? e3(t2) : void 0);
    });
    m2(e2);
  }, []), P(() => {
    null != c2 && c2.setComp(() => o2);
  }, [o2]), c2 ? V(z.Provider, { value: c2, children: L(F, { children: [L(B, { children: [L(O, { children: [n2, L(G, { children: [i((_a = h2[p2.children.id.getView()]) == null ? void 0 : _a.createTime, 2592e6), s2] })] }), V(J, { children: d2 })] }), L(X, { children: [V(W, { children: a2 }), V(Z, { children: l2 })] })] }) }) : null;
}, _ = H(o)`
  position: absolute;
  box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);
  border-top: 1px solid #e1e3eb;
  z-index: ${r.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;
  }
`, Y = H.div`
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
`, ee = (e2) => {
  e2.preventDefault();
}, te = () => {
  window.addEventListener("mousedown", ee);
}, ie = (e2) => {
  var _a;
  const t2 = (_a = e2.comp) == null ? void 0 : _a.result(), [i2, r2] = I(360), { header: o2, body: n2 } = M({ ...t2 ?? { data: "", dataType: "default", success: true }, onClose: e2.onClose });
  if (!t2)
    return null;
  const s2 = document.documentElement.clientHeight;
  return V(_, { width: 1 / 0, height: i2, resizeHandles: ["n"], minConstraints: [680, 285], maxConstraints: [1 / 0, s2 - 48 - 95], onResizeStart: te, onResizeStop: (e3, t3) => {
    r2(t3.size.height), window.removeEventListener("mousedown", ee);
  }, children: L(Y, { children: [V(Q, { style: { cursor: "default" }, children: o2 }), n2] }) });
}, re = n({ query: x(v, (e2) => V(w.Provider, { value: { datasourceId: e2.children.datasourceId.getView(), disableJSCompletion: true, placement: "queryLibrary" }, children: V(j, { comp: e2, placement: "queryLibrary" }) })), inputs: U }), oe = class extends re {
  propertyView(e2) {
    return V(ne, { comp: this, onPublish: e2.onPublish, onHistoryShow: e2.onHistoryShow, setModify: e2.setModify, modify: e2.modify });
  }
  getQueryPropertyView() {
    return this.children.query.getPropertyView();
  }
  getRightPropertyView() {
    return L(D, { children: [V(s, { name: d("prop.inputs"), width: 296, noMargin: true, children: this.children.inputs.getPropertyView() }, "inputs"), V(s, { name: d("prop.meta"), width: 296, noMargin: true, children: V("div", { style: { padding: " 0 8px" }, children: V(N, { dataSourceId: this.children.query.children.datasourceId.getView(), datasourceType: this.children.query.children.compType.getView() }) }) }, "meta")] });
  }
  nameAndExposingInfo() {
    const e2 = {};
    return this.children.inputs.getView().forEach((t2) => {
      e2[t2.children.name.getView()] = t2.exposingInfo();
    }), e2;
  }
}, ne = (e2) => {
  const { comp: t2, onPublish: i2, onHistoryShow: r2, setModify: o2, modify: n2 } = e2, s2 = a(), [x2, w2] = I(false), j2 = t2.children.query.children.datasourceId.getView(), v2 = l(j2);
  P(() => {
    w2(false);
  }, [t2.children.query.children.id.getView()]);
  const q2 = () => t2.children.query.dispatch(K({ afterExecFunc: () => w2(true) }));
  return V(p.Provider, { value: v2, children: V(h.Provider, { value: c(t2.nameAndExposingInfo(), false), children: V(A, { global: true, keyName: "command+enter", onKeyDown: q2, allowRepeat: true, wrapperStyle: { width: "100%" }, children: V($, { comp: t2, title: V(m, { text: t2.children.query.children.name.getView(), onFinish: (e3) => e3 !== t2.children.query.children.name.getView() && t2.dispatch(y(t2.children.query.children.name.getView(), e3)) }), headerRight: L(D, { children: [V(u, { items: [{ text: d("queryLibrary.publish"), onClick: i2 }, { text: d("queryLibrary.historyVersion"), onClick: r2 }], del: () => f.confirm({ title: d("queryLibrary.deleteQueryLabel"), content: d("queryLibrary.deleteQueryContent"), onConfirm: () => {
    s2(b({ queryLibraryId: t2.children.query.children.id.getView() })), setTimeout(() => {
      o2(!n2);
    }, 500);
  }, confirmBtnType: "delete", okText: d("delete") }), children: V(de, { children: V(se, { tabIndex: -1 }) }) }), L(le, { onClick: q2, loading: t2.children.query.children.isFetching.getView(), buttonType: "primary", children: [V(ae, {}), d("queryLibrary.run")] })] }), bodyLeft: L(D, { children: [t2.getQueryPropertyView(), x2 && V(ie, { comp: t2.children.query, onClose: () => w2(false) })] }), bodyRight: V(g, { children: t2.getRightPropertyView() }) }) }) }) });
}, se = H(q)`
  flex-shrink: 0;

  g {
    fill: #8b8fa3;
  }
`, de = H.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;
    }
  }
`, ae = H(k)`
  transform: rotate(-90deg);
  display: inline-block;
  padding-right: 2px;
  margin-right: 4px;
`, le = H(E)`
  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 {
  oe as QueryLibraryComp
};
