import { a3 as n, hh as y, hi as j, hj as m, hk as L, hl as P, hm as z, ad as x, I as B, H as e, hn as V, a4 as b, ho as q, _ as A, hp as F, hq as K, hr as O, hs as G } from "./56c67d3b.js";
import { useState as f, useEffect as v } from "react";
const H = n.div`
  height: 23px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-right: 8px;

  svg g g {
    fill: #8b8fa3;
  }
`, N = n.span`
  ${y};
  font-weight: 500;
  color: #222222;
  line-height: 17px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 210px;
`, W = n.div`
  height: 23px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-right: 8px;
  cursor: default;
`, X = n.span`
  ${y};
  color: #333333;
`, _ = n.span`
  ${y};
  color: #8b8fa3;
`, J = n.span`
  ${y};
  color: #8b8fa3;
  line-height: 13px;
  display: block;
  margin: 0 0 7px 8px;
`, Q = n(O)`
  transform: ${(r) => r.$deg};
`, U = 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%"
}, Y = n(G)`
  .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);
    }
  }
`, Z = (r) => {
  const [t, o] = f(!1);
  return /* @__PURE__ */ x(H, {
    onMouseEnter: () => {
      o(!0);
    },
    onMouseLeave: () => {
      o(!1);
    },
    children: [/* @__PURE__ */ e(N, {
      children: r.name
    }), t && /* @__PURE__ */ e(K, {
      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 = m(L), S = m(P), u = (D = p[t]) == null ? void 0 : D.map((a) => ({
    title: /* @__PURE__ */ e(Z, {
      name: a.name
    }),
    key: a.name,
    children: a.columns.map((s) => ({
      title: /* @__PURE__ */ x(W, {
        children: [/* @__PURE__ */ e(X, {
          children: s.name
        }), /* @__PURE__ */ e(_, {
          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(z({
      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(q, {
        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 I = u.map((l) => {
              var M;
              const $ = (M = l.children) == null ? void 0 : M.filter((R) => R.key.toString().toLowerCase().indexOf(s) !== -1);
              return l.key.toString().toLowerCase().indexOf(s) !== -1 || !A.isEmpty($) ? {
                ...l,
                children: $
              } : null;
            }).filter((l) => l !== null);
            d(I), c(I.map((l) => l.key));
          } else
            d(u), c([]);
          w(s);
        }
      })
    }), /* @__PURE__ */ e(J, {
      children: b("bottomPanel.allData")
    }), /* @__PURE__ */ e(F, {
      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 = m(L), d = (p = m(P)[o]) == null ? void 0 : p.hasStructureInfo;
  if (v(() => {
    d && g(z({
      datasourceId: t
    }));
  }, [t, g, d, o]), !w[t])
    return null;
  const h = (S) => /* @__PURE__ */ e("div", {
    style: S.style,
    children: /* @__PURE__ */ x(U, {
      onClick: () => c(!i),
      children: [b("bottomPanel.metaData"), /* @__PURE__ */ e(Q, {
        $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(Y, {
      $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
};
