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 {
  a as l
} from "./chunk-WBEMC3FF.js";
import {
  a as d
} from "./chunk-5G5PMXGR.js";
import {
  a as o,
  f as p
} from "./chunk-HRN2KQZP.js";

// src/preview-api/modules/store/autoTitle.ts
import { once as g } from "storybook/internal/client-logger";
var u = p(d(), 1);
var h = /* @__PURE__ */ o((e) => {
  if (e.length === 0)
    return e;
  let i = e[e.length - 1], t = i?.replace(/(?:[.](?:story|stories))?([.][^.]+)$/i, "");
  if (e.length === 1)
    return [t];
  let r = e[e.length - 2];
  return t && r && t.toLowerCase() === r.toLowerCase() ? [...e.slice(0, -2), t] : t && (/^(story|stories)([.][^.]+)$/i.test(i) || /^index$/i.test(t)) ? e.slice(0, -1) : [...e.slice(0, -1), t];
}, "sanitize");
function f(e) {
  return e.flatMap((i) => i.split("/")).filter(Boolean).join("/");
}
o(f, "pathJoin");
var w = /* @__PURE__ */ o((e, i, t) => {
  let { directory: r, importPathMatcher: m, titlePrefix: n = "" } = i || {};
  typeof e == "number" && g.warn(u.dedent`
      CSF Auto-title received a numeric fileName. This typically happens when
      webpack is mis-configured in production mode. To force webpack to produce
      filenames, set optimization.moduleIds = "named" in your webpack config.
    `);
  let c = l(String(e));
  if (m.exec(c)) {
    if (!t) {
      let a = c.replace(r, ""), s = f([n, a]).split("/");
      return s = h(s), s.join("/");
    }
    return n ? f([n, t]) : t;
  }
}, "userOrAutoTitleFromSpecifier");

export {
  w as a
};
