// @bun
var{defineProperty:J,getOwnPropertyNames:P,getOwnPropertyDescriptor:Q}=Object,R=Object.prototype.hasOwnProperty;function U(b){return this[b]}var X=(b)=>{var j=(K??=new WeakMap).get(b),q;if(j)return j;if(j=J({},"__esModule",{value:!0}),b&&typeof b==="object"||typeof b==="function"){for(var z of P(b))if(!R.call(j,z))J(j,z,{get:U.bind(b,z),enumerable:!(q=Q(b,z))||q.enumerable})}return K.set(b,j),j},K;var V=(b)=>b;function W(b,j){this[b]=V.bind(null,j)}var Y=(b,j)=>{for(var q in j)J(b,q,{get:j[q],enumerable:!0,configurable:!0,set:W.bind(j,q)})};var Z=(b,j)=>()=>(b&&(j=b(b=0)),j);var _=import.meta.require;function x(b){let j=new Map;for(let k of b)j.set(k.name,{name:k.name,path:k.path,dependencies:k.dependencies,dependents:[],depth:0});for(let k of b)for(let A of k.dependencies){let F=j.get(A);if(F)F.dependents.push(k.name)}let q=new Set;function z(k,A){let F=j.get(k);if(!F||q.has(k))return;F.depth=Math.max(F.depth,A),q.add(k);for(let E of F.dependencies)z(E,A+1);q.delete(k)}let B=[],w=[];for(let[k,A]of j){if(A.dependents.length===0)B.push(k),z(k,0);if(A.dependencies.length===0)w.push(k)}return{nodes:j,roots:B,leaves:w}}function G(b,j){let q=new Set,z=new Set;function B(w){if(z.has(w))return;z.add(w);let k=b.nodes.get(w);if(!k)return;for(let A of k.dependencies)q.add(A),B(A)}return B(j),Array.from(q)}function L(b,j){let q=new Set,z=new Set;function B(w){if(z.has(w))return;z.add(w);let k=b.nodes.get(w);if(!k)return;for(let A of k.dependents)q.add(A),B(A)}return B(j),Array.from(q)}function M(b){let j=[],q=new Set,z=[];function B(w){if(z.includes(w)){let A=z.indexOf(w);j.push([...z.slice(A),w]);return}if(q.has(w))return;q.add(w),z.push(w);let k=b.nodes.get(w);if(k)for(let A of k.dependencies)B(A);z.pop()}for(let w of b.nodes.keys())B(w);return j}function T(b,j){let q=Array.from(b.nodes.values()),z=Math.max(...q.map((k)=>k.depth),0),B=[];for(let k=0;k<=z;k++)B.push(q.filter((A)=>A.depth===k));let w=B.map((k,A)=>{let F=k.map((E)=>{let O=E.name===j,I=["dep-node"];if(O)I.push("selected");if(b.roots.includes(E.name))I.push("root");if(b.leaves.includes(E.name))I.push("leaf");return`
            <div
              class="${I.join(" ")}"
              onclick="window.__stxStory.selectComponent('${E.name}')"
              title="${E.path}"
            >
              <span class="dep-node-name">${E.name}</span>
              <span class="dep-node-count">
                ${E.dependencies.length>0?`\u2193${E.dependencies.length}`:""}
                ${E.dependents.length>0?`\u2191${E.dependents.length}`:""}
              </span>
            </div>
          `}).join("");return`
        <div class="dep-level" data-depth="${A}">
          <div class="dep-level-label">Level ${A}</div>
          <div class="dep-level-nodes">${F}</div>
        </div>
      `}).join("");return`
    <div class="stx-dependency-graph">
      <div class="dep-graph-header">
        <span>Component Dependencies</span>
        <span class="dep-graph-stats">
          ${b.nodes.size} components,
          ${b.roots.length} roots,
          ${b.leaves.length} leaves
        </span>
      </div>
      <div class="dep-graph-body">
        ${w}
      </div>
    </div>
  `}function f(){return`
    .stx-dependency-graph {
      padding: 16px;
    }
    .dep-graph-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 16px;
      font-weight: 600;
    }
    .dep-graph-stats {
      font-size: 12px;
      color: var(--text-secondary);
      font-weight: normal;
    }
    .dep-graph-body {
      display: flex;
      flex-direction: column;
      gap: 16px;
    }
    .dep-level {
      display: flex;
      align-items: flex-start;
      gap: 12px;
    }
    .dep-level-label {
      width: 60px;
      font-size: 11px;
      color: var(--text-secondary);
      text-transform: uppercase;
      padding-top: 8px;
    }
    .dep-level-nodes {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      flex: 1;
    }
    .dep-node {
      padding: 8px 12px;
      background: var(--bg-secondary);
      border: 1px solid var(--border);
      border-radius: 4px;
      cursor: pointer;
      display: flex;
      align-items: center;
      gap: 8px;
    }
    .dep-node:hover {
      border-color: var(--primary);
    }
    .dep-node.selected {
      background: var(--primary);
      color: white;
      border-color: var(--primary);
    }
    .dep-node.root {
      border-left: 3px solid #22c55e;
    }
    .dep-node.leaf {
      border-left: 3px solid #f59e0b;
    }
    .dep-node-name {
      font-size: 13px;
    }
    .dep-node-count {
      font-size: 11px;
      color: var(--text-secondary);
    }
    .dep-node.selected .dep-node-count {
      color: rgba(255,255,255,0.7);
    }
  `}function C(b,j){let q=b.nodes.get(j);if(!q)return'<div class="dep-detail-empty">Component not found</div>';let z=q.dependencies.length>0?q.dependencies.map((w)=>`
        <div class="dep-link" onclick="window.__stxStory.selectComponent('${w}')">
          \u2193 ${w}
        </div>
      `).join(""):'<div class="dep-none">No dependencies</div>',B=q.dependents.length>0?q.dependents.map((w)=>`
        <div class="dep-link" onclick="window.__stxStory.selectComponent('${w}')">
          \u2191 ${w}
        </div>
      `).join(""):'<div class="dep-none">No dependents</div>';return`
    <div class="stx-component-detail">
      <div class="dep-detail-header">
        <span class="dep-detail-name">${j}</span>
        <span class="dep-detail-path">${q.path}</span>
      </div>

      <div class="dep-detail-section">
        <div class="dep-detail-title">Dependencies (${q.dependencies.length})</div>
        ${z}
      </div>

      <div class="dep-detail-section">
        <div class="dep-detail-title">Used by (${q.dependents.length})</div>
        ${B}
      </div>

      <div class="dep-detail-actions">
        <button onclick="window.__stxStory.openStory('${j}')">
          Open Story
        </button>
        <button onclick="window.__stxStory.openSource('${q.path}')">
          View Source
        </button>
      </div>
    </div>
  `}export{f as getDependencyGraphStyles,L as getAllDependents,G as getAllDependencies,T as generateDependencyGraphHTML,C as generateComponentDetailHTML,M as detectCircularDependencies,x as buildDependencyGraph};
