/* ========================================================================
   PRIMITIVES — Lucide Icon + DS-bundle re-exports
   The DS bundle (window.PursuitDesignSystem2026_7f6065 namespace, assigned
   onto window) provides Btn, Badge, Avatar, Logomark and a small fixed
   Icon set. The app's icon vocabulary is the full Lucide library, so we
   define a Lucide-backed <Icon/> and let it take over window.Icon AFTER
   capturing the DS original (DS components keep their closure copy).
   ======================================================================== */

const DSKit = {
  Icon: window.Icon,        // DS inline set (kept for reference)
  Btn: window.Btn,
  Badge: window.Badge,
  Avatar: window.Avatar,
  Logomark: window.Logomark,
  Header: window.Header,
  Sidebar: window.Sidebar,
};

const __lucideHtmlCache = {};
function lucideSvgHtml(name) {
  if (__lucideHtmlCache[name] != null) return __lucideHtmlCache[name];
  let html = '';
  try {
    const pascal = String(name).split('-').map(p => p.charAt(0).toUpperCase() + p.slice(1)).join('');
    const node = window.lucide && lucide.icons && lucide.icons[pascal];
    if (node) {
      const el = lucide.createElement(node);
      el.setAttribute('width', '100%');
      el.setAttribute('height', '100%');
      html = el.outerHTML;
    }
  } catch (e) { html = ''; }
  __lucideHtmlCache[name] = html;
  return html;
}

/* Real brand logos (full-color) — keyed names bypass the Lucide path. */
const BRAND_LOGOS = {
  'brand-salesforce': '<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="#00A1E0"><path d="M10.006 5.415a4.195 4.195 0 0 1 3.045-1.306c1.56 0 2.954.9 3.69 2.205.63-.3 1.35-.45 2.1-.45 2.85 0 5.159 2.34 5.159 5.22s-2.31 5.22-5.16 5.22c-.345 0-.689-.044-1.02-.104a3.75 3.75 0 0 1-3.27 1.93c-.6 0-1.155-.15-1.65-.39a4.305 4.305 0 0 1-4.005 2.716 4.32 4.32 0 0 1-4.05-2.85 4.51 4.51 0 0 1-.825.074C2.041 17.68.241 15.879.241 13.629c0-1.5.825-2.805 2.025-3.51a4.661 4.661 0 0 1-.39-1.86c0-2.58 2.1-4.665 4.68-4.665 1.516 0 2.851.721 3.705 1.821"/></svg>',
  'brand-hubspot': '<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="#FF7A59"><path d="M18.164 7.931V5.084a2.198 2.198 0 0 0 1.267-1.978v-.067A2.2 2.2 0 0 0 17.238.845h-.067a2.2 2.2 0 0 0-2.193 2.194v.067a2.196 2.196 0 0 0 1.252 1.973l.013.006v2.852a6.22 6.22 0 0 0-2.969 1.31l.012-.01-7.86-6.12a2.495 2.495 0 1 0-1.169 1.527l-.012-.006 7.736 6.024a6.232 6.232 0 0 0-1.04 3.463 6.286 6.286 0 0 0 1.073 3.502l-.014-.022-2.352 2.353a1.989 1.989 0 0 0-.58-.095 2.018 2.018 0 1 0 2.017 2.017 1.989 1.989 0 0 0-.095-.58l.005.017 2.328-2.329a6.247 6.247 0 1 0 4.733-11.177l-.04-.007zm-1.166 9.353a3.206 3.206 0 1 1 .002-6.412 3.206 3.206 0 0 1-.002 6.412z"/></svg>',
};

/* <Icon name="search" size={16}/> — drop-in for the old <i data-lucide>. */
function Icon({ name, size = 16, width, height, className = '', style, strokeWidth, ...rest }) {
  const brand = BRAND_LOGOS[name];
  let html = brand || lucideSvgHtml(name);
  if (!brand && strokeWidth && html) html = html.replace('stroke-width="2"', `stroke-width="${strokeWidth}"`);
  const w = width != null ? Number(width) : size;
  const h = height != null ? Number(height) : size;
  return (
    <span
      className={('luc ' + className).trim()}
      style={{ width: w, height: h, ...style }}
      dangerouslySetInnerHTML={{ __html: html }}
      {...rest}
    ></span>
  );
}

/* Tiny class-name join helper. */
function cx(...parts) { return parts.filter(Boolean).join(' '); }

Object.assign(window, { DSKit, Icon, cx, lucideSvgHtml });
