import { X as n, fz as m, hX as j, hY as y, hZ as z, h_ as L, h$ as P, a6 as x, G as B, F as e, i0 as V, Y as b, i1 as F, _ as X, i2 as A, i3 as G, gJ as K, i4 as O } from "./603b75d9.js";
import { useState as f, useEffect as v } from "react";
const Y = n.div`
  height: 23px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-right: 8px;

  svg g g {
    fill: #8b8fa3;
  }
`, _ = n.span`
  ${m};
  font-weight: 500;
  color: #222222;
  line-height: 17px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 210px;
`, q = n.div`
  height: 23px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-right: 8px;
  cursor: default;
`, J = n.span`
  ${m};
  color: #333333;
`, N = n.span`
  ${m};
  color: #8b8fa3;
`, W = n.span`
  ${m};
  color: #8b8fa3;
  line-height: 13px;
  display: block;
  margin: 0 0 7px 8px;
`, Z = n(K)`
  transform: ${(r) => r.$deg};
`, H = n.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;
    }
  }
`, E = {
  borderBottom: "none",
  zIndex: 2,
  height: "40px",
  padding: "9px 16px",
  width: "100%"
}, Q = n(O)`
  .ant-drawer-content {
    border-radius: 8px 8px 0 0;
    overflow: ${(r) => r.$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);
    }
  }
`, U = (r) => {
  const [t, o] = f(!1);
  return /* @__PURE__ */ x(Y, {
    onMouseEnter: () => {
      o(!0);
    },
    onMouseLeave: () => {
      o(!1);
    },
    children: [/* @__PURE__ */ e(_, {
      children: r.name
    }), t && /* @__PURE__ */ e(G, {
      text: r.name
    })]
  });
}, ee = (r) => {
  var D, C;
  const {
    dataSourceId: t,
    datasourceType: o
  } = r, [i, c] = f([]), [g, w] = f(""), [k, d] = f([]), h = j(), p = y(z), S = y(L), u = (D = p[t]) == null ? void 0 : D.map((a) => ({
    title: /* @__PURE__ */ e(U, {
      name: a.name
    }),
    key: a.name,
    children: a.columns.map((s) => ({
      title: /* @__PURE__ */ x(q, {
        children: [/* @__PURE__ */ e(J, {
          children: s.name
        }), /* @__PURE__ */ e(N, {
          children: s.type
        })]
      }),
      key: a.name + "-" + s.name,
      isLeaf: !0
    }))
  }));
  v(() => {
    var a;
    d(u), c([(a = u == null ? void 0 : u[0]) == null ? void 0 : a.key]);
  }, [p[t]]);
  const T = (C = S[o]) == null ? void 0 : C.hasStructureInfo;
  return v(() => {
    T && h(P({
      datasourceId: t
    }));
  }, [t, h, T, o]), p[t] ? /* @__PURE__ */ x(B, {
    children: [/* @__PURE__ */ e("div", {
      style: {
        backgroundColor: "#ffffff",
        position: "sticky",
        top: "0px",
        zIndex: 2,
        padding: "8px 0 12px 0"
      },
      children: /* @__PURE__ */ e(F, {
        style: {
          padding: "0 8px",
          margin: "0"
        },
        placeholder: b("bottomPanel.metaSearchPlaceholder"),
        value: g,
        onChange: (a) => {
          const s = a.target.value.toLowerCase();
          if (s.length > 0) {
            const $ = u.map((l) => {
              var M;
              const I = (M = l.children) == null ? void 0 : M.filter((R) => R.key.toString().toLowerCase().indexOf(s) !== -1);
              return l.key.toString().toLowerCase().indexOf(s) !== -1 || !X.isEmpty(I) ? {
                ...l,
                children: I
              } : null;
            }).filter((l) => l !== null);
            d($), c($.map((l) => l.key));
          } else
            d(u), c([]);
          w(s);
        }
      })
    }), /* @__PURE__ */ e(W, {
      children: b("bottomPanel.allData")
    }), /* @__PURE__ */ e(A, {
      treeData: k,
      expandedKeys: i,
      onExpand: (a) => c(a)
    })]
  }) : /* @__PURE__ */ e(V, {
    style: {
      margin: "0 8px"
    },
    text: b("bottomPanel.noMetadata")
  });
};
function re(r) {
  var p;
  const {
    dataSourceId: t,
    queryType: o
  } = r, [i, c] = f(!1), g = j(), w = y(z), d = (p = y(L)[o]) == null ? void 0 : p.hasStructureInfo;
  if (v(() => {
    d && g(P({
      datasourceId: t
    }));
  }, [t, g, d, o]), !w[t])
    return null;
  const h = (S) => /* @__PURE__ */ e("div", {
    style: S.style,
    children: /* @__PURE__ */ x(H, {
      onClick: () => c(!i),
      children: [b("bottomPanel.metaData"), /* @__PURE__ */ e(Z, {
        $deg: i ? "rotate(180deg)" : "rotate(0deg)"
      })]
    })
  });
  return /* @__PURE__ */ x(B, {
    children: [/* @__PURE__ */ e(h, {
      style: {
        ...E,
        boxShadow: "0 -2px 5px 0 rgba(0, 0, 0, 0.05)",
        borderRadius: "8px 8px 0 0"
      }
    }), /* @__PURE__ */ e(Q, {
      $vis: i,
      mask: !1,
      rootStyle: {
        position: "absolute",
        height: "100%",
        bottom: 0,
        zIndex: 2
      },
      title: /* @__PURE__ */ e(h, {}),
      styles: {
        header: E,
        wrapper: {
          height: "100%",
          boxShadow: "none",
          borderRadius: "0"
        },
        body: {
          padding: "0 0 0 8px",
          overflowX: "hidden",
          scrollbarGutter: "stable"
        }
      },
      placement: "bottom",
      closable: !1,
      onClose: () => c(!1),
      open: i,
      getContainer: !1,
      children: /* @__PURE__ */ e(ee, {
        dataSourceId: t,
        datasourceType: o
      })
    })]
  });
}
export {
  re as B,
  ee as D
};
