import { dU as e, dV as t, dW as o, dX as a, dY as n, dZ as r, d_ as i, av as d, d$ as s, e0 as l, e1 as p, e2 as c } from "./index-0c01125c.js";
import { useState as h, useEffect as m } from "react";
import { lR as x, lS as g, lA as u } from "./ant-design-icons-14ab96af.js";
import { _ as b } from "./lodash-226cb5b1.js";
import { A as f } from "./antd-97b654da.js";
import { d as y } from "./styled-components-c6abe9a3.js";
const w = y.div`
  height: 23px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-right: 8px;

  svg g g {
    fill: #8b8fa3;
  }
`, v = y.span`
  ${e};
  font-weight: 500;
  color: #222222;
  line-height: 17px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 210px;
`, k = y.div`
  height: 23px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-right: 8px;
  cursor: default;
`, S = y.span`
  ${e};
  color: #333333;
`, $ = y.span`
  ${e};
  color: #8b8fa3;
`, I = y.span`
  ${e};
  color: #8b8fa3;
  line-height: 13px;
  display: block;
  margin: 0 0 7px 8px;
`, j = y(c)`
  transform: ${(e2) => e2.$deg};
`, C = y.div`
  color: #222222;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 500;

  &:hover {
    cursor: pointer;

    svg g path {
      fill: #315efb;
    }
  }
`, L = { borderBottom: "none", zIndex: 2, height: "40px", padding: "9px 16px", width: "100%" }, P = y(f)`
  .ant-drawer-content {
    border-radius: 8px 8px 0 0;
    overflow: ${(e2) => e2.$vis ? "auto" : "hidden"};
  }

  .ant-drawer-body {
    &::-webkit-scrollbar {
      width: 16px;
    }

    &::-webkit-scrollbar-thumb {
      border: 5px solid transparent;
      background-clip: content-box;
      border-radius: 9999px;
      background-color: rgba(139, 143, 163, 0.2);
      min-height: 30px;
    }

    &::-webkit-scrollbar-thumb:hover {
      background-color: rgba(139, 143, 163, 0.36);
    }
  }
`, z = (e2) => {
  const [t2, o2] = h(false);
  return x(w, { onMouseEnter: () => {
    o2(true);
  }, onMouseLeave: () => {
    o2(false);
  }, children: [u(v, { children: e2.name }), t2 && u(p, { text: e2.name })] });
}, D = (e2) => {
  var _a, _b;
  const { dataSourceId: p2, datasourceType: c2 } = e2, [f2, y2] = h([]), [w2, v2] = h(""), [j2, C2] = h([]), L2 = t(), P2 = o(a), D2 = o(n), R2 = (_a = P2[p2]) == null ? void 0 : _a.map((e3) => ({ title: u(z, { name: e3.name }), key: e3.name, children: e3.columns.map((t2) => ({ title: x(k, { children: [u(S, { children: t2.name }), u($, { children: t2.type })] }), key: e3.name + "-" + t2.name, isLeaf: true })) }));
  m(() => {
    var _a2;
    C2(R2), y2([(_a2 = R2 == null ? void 0 : R2[0]) == null ? void 0 : _a2.key]);
  }, [P2[p2]]);
  const E = (_b = D2[c2]) == null ? void 0 : _b.hasStructureInfo;
  return m(() => {
    E && L2(r({ datasourceId: p2 }));
  }, [p2, L2, E, c2]), P2[p2] ? x(g, { children: [u("div", { style: { backgroundColor: "#ffffff", position: "sticky", top: "0px", zIndex: 2, padding: "8px 0 12px 0" }, children: u(s, { style: { padding: "0 8px", margin: "0" }, placeholder: d("bottomPanel.metaSearchPlaceholder"), value: w2, onChange: (e3) => {
    const t2 = e3.target.value.toLowerCase();
    if (t2.length > 0) {
      const e4 = R2.map((e5) => {
        var _a2;
        const o2 = (_a2 = e5.children) == null ? void 0 : _a2.filter((e6) => -1 !== e6.key.toString().toLowerCase().indexOf(t2));
        return -1 === e5.key.toString().toLowerCase().indexOf(t2) && b.isEmpty(o2) ? null : { ...e5, children: o2 };
      }).filter((e5) => null !== e5);
      C2(e4), y2(e4.map((e5) => e5.key));
    } else
      C2(R2), y2([]);
    v2(t2);
  } }) }), u(I, { children: d("bottomPanel.allData") }), u(l, { treeData: j2, expandedKeys: f2, onExpand: (e3) => y2(e3) })] }) : u(i, { style: { margin: "0 8px" }, text: d("bottomPanel.noMetadata") });
};
function R(e2) {
  var _a;
  const { dataSourceId: i2, queryType: s2 } = e2, [l2, p2] = h(false), c2 = t(), b2 = o(a), f2 = o(n), y2 = (_a = f2[s2]) == null ? void 0 : _a.hasStructureInfo;
  if (m(() => {
    y2 && c2(r({ datasourceId: i2 }));
  }, [i2, c2, y2, s2]), !b2[i2])
    return null;
  const w2 = (e3) => u("div", { style: e3.style, children: x(C, { onClick: () => p2(!l2), children: [d("bottomPanel.metaData"), u(j, { $deg: l2 ? "rotate(180deg)" : "rotate(0deg)" })] }) });
  return x(g, { children: [u(w2, { style: { ...L, boxShadow: "0 -2px 5px 0 rgba(0, 0, 0, 0.05)", borderRadius: "8px 8px 0 0" } }), u(P, { $vis: l2, mask: false, rootStyle: { position: "absolute", height: "100%", bottom: 0, zIndex: 2 }, title: u(w2, {}), styles: { header: L, wrapper: { height: "100%", boxShadow: "none", borderRadius: "0" }, body: { padding: "0 0 0 8px", overflowX: "hidden", scrollbarGutter: "stable" } }, placement: "bottom", closable: false, onClose: () => p2(false), open: l2, getContainer: false, children: u(D, { dataSourceId: i2, datasourceType: s2 }) })] });
}
export {
  R as B,
  D
};
