import CJS_COMPAT_NODE_URL from 'node:url';
import CJS_COMPAT_NODE_PATH from 'node:path';
import CJS_COMPAT_NODE_MODULE from "node:module";

const __filename = CJS_COMPAT_NODE_URL.fileURLToPath(import.meta.url);
const __dirname = CJS_COMPAT_NODE_PATH.dirname(__filename);
const require = CJS_COMPAT_NODE_MODULE.createRequire(import.meta.url);
// ------------------------------------------------------------
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
// ------------------------------------------------------------
import {
  k as c
} from "./chunk-IX4DFZA3.js";
import {
  a as o
} from "./chunk-HRN2KQZP.js";

// ../node_modules/@storybook/docs-mdx/dist/index.js
var m = /* @__PURE__ */ o((n, t) => n.attributes.find((e) => e.type === "JSXAttribute" && e.name.name === t), "getAttr"), v = /* @__PURE__ */ o((n, t) => m(n, t)?.value, "getAttrValue"), f = /* @__PURE__ */ o((n, t) => {
  let e = v(n, t);
  if (e) {
    if (e.type === "Literal")
      return e.value;
    throw new Error(`Expected string literal ${t}, received ${e.type}`);
  }
}, "getAttrLiteral"), u = /* @__PURE__ */ o((n, t) => {
  let e = v(n, "of");
  if (e)
    if (e.type === "JSXExpressionContainer") {
      let r = e.expression;
      if (r?.type === "Identifier") {
        let i = t[r.name];
        if (i)
          return i;
        throw new Error(`Unknown identifier ${r.name}`);
      } else
        throw new Error(`Expected identifier, received ${r.type}`);
    } else
      throw new Error(`Expected JSX expression, received ${e.type}`);
}, "getOf"), y = /* @__PURE__ */ o((n) => {
  let t = m(n, "tags");
  if (!t)
    return;
  let e = t.value;
  if (e.type === "JSXExpressionContainer") {
    let r = e.expression;
    if (r.type === "ArrayExpression")
      return r.elements.map((a) => {
        if (a.type === "Literal" && typeof a.value == "string")
          return a.value;
        throw new Error(`Expected string literal tag, received ${a.type}`);
      });
    throw new Error(`Expected tags array, received ${r.type}`);
  } else
    throw new Error(`Expected JSX expression tags, received ${e.type}`);
}, "getTags"), d = /* @__PURE__ */ o((n) => {
  let t = m(n, "isTemplate");
  if (!t)
    return !1;
  let e = t.value;
  if (e == null)
    return !0;
  if (e.type === "JSXExpressionContainer") {
    let r = e.expression;
    if (r.type === "Literal" && typeof r.value == "boolean")
      return r.value;
    throw new Error(`Expected boolean isTemplate, received ${typeof r.value}`);
  } else
    throw new Error(`Expected expression isTemplate, received ${e.type}`);
}, "getIsTemplate"), E = /* @__PURE__ */ o((n, t) => {
  let e = { title: void 0, of: void 0, name: void 0, isTemplate: !1 }, r = n.body.filter(
    (a) => a.type === "ExpressionStatement" && a.expression.type === "JSXFragment"
  );
  if (r.length > 1)
    throw new Error("duplicate contents");
  return r.length === 0 || r[0].expression.children.forEach((a) => {
    if (a.type === "JSXElement") {
      let { openingElement: s } = a;
      if (s.name.name === "Meta") {
        if (e.title || e.name || e.of)
          throw new Error("Meta can only be declared once");
        e.title = f(s, "title"), e.name = f(s, "name"), e.of = u(s, t), e.isTemplate = d(s), e.metaTags = y(s);
      }
    } else if (a.type !== "JSXExpressionContainer")
      throw new Error(`Unexpected JSX child: ${a.type}`);
  }), e;
}, "extractTitle"), g = /* @__PURE__ */ o((n) => {
  let t = {};
  return n.body.forEach((e) => {
    if (e.type === "ImportDeclaration") {
      let { source: r, specifiers: i } = e;
      if (r.type === "Literal")
        i.forEach((a) => {
          t[a.local.name] = r.value.toString();
        });
      else
        throw new Error("MDX: unexpected import source");
    }
  }), t;
}, "extractImports"), w = /* @__PURE__ */ o((n) => (t) => {
  let e = c(t), r = g(e), { title: i, of: a, name: s, isTemplate: p, metaTags: l } = E(e, r);
  return n.title = i, n.of = a, n.name = s, n.isTemplate = p, n.metaTags = l, n.imports = Array.from(new Set(Object.values(r))), t;
}, "plugin"), T = /* @__PURE__ */ o(async (n) => {
  let t = {
    title: void 0,
    of: void 0,
    name: void 0,
    isTemplate: !1,
    metaTags: void 0,
    imports: void 0
  }, { compile: e } = await import("./mdx-N42X6CFJ-LDAZZGYL.js");
  await e(n, {
    rehypePlugins: [[w, t]]
  });
  let { title: r, of: i, name: a, isTemplate: s, metaTags: p, imports: l = [] } = t;
  return { title: r, of: i, name: a, isTemplate: s, metaTags: p, imports: l };
}, "analyze");
export {
  T as analyze,
  g as extractImports,
  w as plugin
};
