/* Shared data, primitives, and Schedii-style components for both directions. */

/* ─── MCP directory data ────────────────────────────────────────────── */
/* Single namespace: @sch. Flags determine the mode.
 *   @sch        — Schedii workbench (base)
 *   @sch -d     — Pertel Dash    · lite intelligence
 *   @sch -f     — Pertel Sift    · filter
 *   @sch p      — Pertel (Full)  · everything
 */
const MCPS = [
  {
    id: 'workbench',
    name: 'Schedii',
    tag: 'base · the workbench',
    blurb: 'The Schedii workbench, as MCP tools. Brands, queues, drafts, integrations — callable from Claude, GPT, or Manus.',
    longBlurb: 'The base namespace. Schedii workbench surfaces (brands, posts, queue, integrations, drafts) exposed as tools. No intelligence overlay, no filter — just the workbench.',
    namespace: '@sch',
    flag: '',
    status: 'beta',
    works: ['Claude', 'GPT', 'Manus'],
    icon: 'core',
    tools: ['brands', 'queue', 'drafts', 'publish', 'integrations'],
    accent: 'cyan',
  },
  {
    id: 'dash',
    name: 'Pertel Dash',
    tag: 'lite intelligence',
    blurb: 'Storage, memory, logging, handoff. Keeps your context across Claude, GPT, and Manus so you never max a token window again.',
    longBlurb: 'The lite Pertel. Memory, append-only markdown logs, doc handoff between sessions. The “don’t blow my context” mode.',
    namespace: '@sch -d',
    flag: '-d',
    status: 'alpha',
    works: ['Claude', 'GPT', 'Manus'],
    icon: 'pertel',
    tools: ['begin', 'remember', 'recall', 'handoff', 'tail', 'forget'],
    accent: 'cyan',
  },
  {
    id: 'sift',
    name: 'Pertel Sift',
    tag: 'filter · AkrosInfra',
    blurb: 'A multi-every filter for your ideas, drafts, code, plans. Sifts results through the Schedii Bible + AkrosInfra frameworks.',
    longBlurb: 'Proprietary filter that runs your work through the Schedii Bible + AkrosInfra frameworks. Mid-work, pre-publish, or post-audit. Sifts, kills the junk, re-separates the rest.',
    namespace: '@sch -f',
    flag: '-f',
    status: 'alpha',
    works: ['Claude', 'GPT', 'Manus'],
    icon: 'filter',
    tools: ['full', 'ndv', 'ndvr', 'custom'],
    accent: 'amber',
  },
  {
    id: 'full',
    name: 'Pertel',
    tag: 'full · all capability',
    blurb: 'Everything. Workbench + Dash + Sift + discovery, in one namespace. All capability under @sch p.',
    longBlurb: 'Full Pertel — the everything package. Combines @sch (workbench), @sch -d (dash), @sch -f (sift), and discovery into one. The serious mode.',
    namespace: '@sch p',
    flag: 'p',
    status: 'alpha',
    works: ['Claude', 'GPT', 'Manus'],
    icon: 'pertel',
    tools: ['workbench', 'memory', 'sift', 'discovery', 'handoff'],
    accent: 'cyan',
  },
];

/* @sch -f modes — the proprietary filter has graded sub-modes */
const SCPF_MODES = [
  {
    cmd: '@sch -f mm',
    name: 'MmM',
    desc: 'Metered Mind Map. Concepts become nodes, relations become edges. Salience measured; the filter follows the strongest paths and reports the weakest joints.',
  },
  {
    cmd: '@sch -f ndv',
    name: 'Neurodivii',
    desc: 'Neurodivergent lens. Re-weights signal so unusual angles survive the standard cut. The "what if?" that a canonical pass would have killed gets a second look.',
  },
  {
    cmd: '@sch -f ndvr',
    name: 'Neurodivii + Reason',
    desc: 'Same lens, plus the why. Every keep, kill, and re-separation comes back with its reasoning attached. The filter that explains itself.',
  },
  {
    cmd: '@sch -f full',
    name: 'Full',
    desc: 'All three lenses run sequentially. The heaviest sift. Use when the work needs to survive every cut.',
  },
  {
    cmd: '@sch -f custom',
    name: 'Custom',
    desc: 'Multi-question tuning. Pick the criteria — all within Schedii scope. The tunable one.',
  },
];

const STATUS_LABEL = {
  alpha:   { text: 'ALPHA',    color: '#06b6d4' },
  beta:    { text: 'BETA',     color: '#22d3ee' },
  planned: { text: 'PLANNED',  color: '#94a3b8' },
};

/* ─── Iconography (Schedii pack-style monoline glyphs, currentColor) ── */
function McpGlyph({ kind, size = 22 }) {
  const common = {
    width: size, height: size, viewBox: '0 0 24 24',
    fill: 'none', stroke: 'currentColor', strokeWidth: 1.5,
    strokeLinecap: 'round', strokeLinejoin: 'round',
  };
  switch (kind) {
    case 'pertel':
      return (
        <svg {...common}>
          <path d="M8 4c-2.5 0-3.5 2-3.5 4v8c0 2 1 4 3.5 4" />
          <path d="M16 4c2.5 0 3.5 2 3.5 4v8c0 2-1 4-3.5 4" />
          <circle cx="12" cy="12" r="1.6" fill="currentColor" stroke="none" />
          <path d="M9 12h1.5" /><path d="M13.5 12H15" />
        </svg>
      );
    case 'core':
      return (
        <svg {...common}>
          <circle cx="12" cy="12" r="2.2" fill="currentColor" stroke="none" />
          <path d="M4 12A8 8 0 0 1 12 4" />
          <path d="M20 12A8 8 0 0 1 12 20" />
          <circle cx="12" cy="4"  r="1.2" fill="currentColor" stroke="none" />
          <circle cx="20" cy="12" r="1.2" fill="currentColor" stroke="none" />
          <circle cx="12" cy="20" r="1.2" fill="currentColor" stroke="none" />
          <circle cx="4"  cy="12" r="1.2" fill="currentColor" stroke="none" />
        </svg>
      );
    case 'filter':
      return (
        <svg {...common}>
          <path d="M4 5h16l-6 7.5V19l-4 1.5v-8L4 5z" />
          <circle cx="9.5" cy="8.5" r="0.8" fill="currentColor" stroke="none" />
          <circle cx="13"  cy="8.5" r="0.8" fill="currentColor" stroke="none" />
          <circle cx="16"  cy="8.5" r="0.8" fill="currentColor" stroke="none" />
        </svg>
      );
    case 'geniie':
      return (
        <svg {...common}>
          <path d="M12 3l1.6 3.6L17 8l-3.4 1.6L12 13l-1.6-3.4L7 8l3.4-1.4L12 3z" />
          <path d="M18 14l.9 2L21 17l-2.1.9L18 20l-.9-2L15 17l2.1-1L18 14z" />
          <path d="M6 14l.6 1.4L8 16l-1.4.7L6 18l-.6-1.3L4 16l1.4-.6L6 14z" />
        </svg>
      );
    case 'orbit':
      return (
        <svg {...common}>
          <ellipse cx="12" cy="12" rx="9" ry="4" />
          <ellipse cx="12" cy="12" rx="4" ry="9" />
          <circle cx="12" cy="12" r="1.6" fill="currentColor" stroke="none" />
          <circle cx="21" cy="12" r="0.9" fill="currentColor" stroke="none" />
        </svg>
      );
    case 'logo':
      return (
        <svg width={size} height={size} viewBox="0 0 24 24" fill="none">
          <path d="M8 4c-2.5 0-3.5 2-3.5 4v8c0 2 1 4 3.5 4"
                stroke="#06b6d4" strokeWidth="1.7" strokeLinecap="round" />
          <path d="M16 4c2.5 0 3.5 2 3.5 4v8c0 2-1 4-3.5 4"
                stroke="#06b6d4" strokeWidth="1.7" strokeLinecap="round" />
          <circle cx="12" cy="12" r="2.2" fill="#06b6d4" />
        </svg>
      );
    case 'arrow':
      return (
        <svg {...common}><path d="M5 12h14" /><path d="M13 6l6 6-6 6" /></svg>
      );
    case 'dot':
      return (
        <svg width={size} height={size} viewBox="0 0 8 8">
          <circle cx="4" cy="4" r="3" fill="#06b6d4" />
        </svg>
      );
    default: return null;
  }
}

/* ─── Status chip ─────────────────────────────────────────────────── */
function StatusChip({ stats, tone }) {
  return (
    <div className="schedii-chip" data-tone={tone || 'cyan'}>
      <span className="schedii-chip-dot" />
      {stats.map((s, i) => (
        <span key={s.label} className="schedii-chip-stat">
          {i > 0 && <span className="schedii-chip-sep">·</span>}
          <span className="schedii-chip-label">{s.label}</span>
          {s.count !== undefined && (
            <span className="schedii-chip-count" data-state={s.state || 'neutral'}>
              {s.count}
            </span>
          )}
        </span>
      ))}
    </div>
  );
}

/* ─── Hero header (kept for compat) ─────────────────────────────── */
function HeroHeader({ prefix, noun, suffix, size = 'page' }) {
  const fontSize = size === 'mega'
    ? 'clamp(40px, 4.8vw, 72px)'
    : 'clamp(30px, 3.2vw, 48px)';
  return (
    <h1 className="schedii-hero" style={{ fontSize }}>
      {prefix && <span>{prefix} </span>}
      <span className="schedii-hero-italic">{noun}</span>
      {suffix && <span>{suffix}</span>}
    </h1>
  );
}

/* ─── Pertel lockup ────────────────────────────────────────────── */
function PertelLockup({ variant = 'by', size = 28, showTagline = true }) {
  return (
    <div className="schedii-lockup" style={{ '--lockup-size': `${size}px` }}>
      <McpGlyph kind="logo" size={Math.round(size * 1.05)} />
      <div className="schedii-lockup-stack">
        <span className="schedii-lockup-name">Pertel</span>
        {showTagline && (
          <span className="schedii-lockup-tagline">intelligence</span>
        )}
      </div>
      {variant === 'by' && (
        <>
          <span className="schedii-lockup-by">by</span>
          <span className="schedii-lockup-host">Schedii</span>
        </>
      )}
      {variant === 'dot' && (
        <>
          <span className="schedii-lockup-sep">·</span>
          <span className="schedii-lockup-host">Schedii</span>
        </>
      )}
    </div>
  );
}

/* ─── Install snippets ──────────────────────────────────────────── */
const INSTALL_SNIPPETS = {
  claude: `{
  "mcpServers": {
    "schedii": {
      "command": "npx",
      "args": ["-y", "@schedii/mcp@latest", "p"],
      "env": {
        "SCHEDII_API_TOKEN":  "sk_live_•••",
        "SCHEDII_WORKSPACE":  "ws_•••"
      }
    }
  }
}`,
  cursor: `// .cursor/mcp.json
{
  "mcpServers": {
    "schedii": {
      "command": "npx",
      "args": ["-y", "@schedii/mcp@latest", "p"],
      "env": {
        "SCHEDII_API_TOKEN": "sk_live_•••",
        "SCHEDII_WORKSPACE": "ws_•••"
      }
    }
  }
}`,
  chatgpt: `# Custom connector → URL
https://mcp.schedii.app/sse

# Headers
Authorization:        Bearer sk_live_•••
X-Schedii-Workspace:  ws_•••
X-Schedii-Mode:       p     # p = full Pertel · -d = Dash · -f = Sift`,
  cli: `# one-line quickstart
npx -y @schedii/mcp@latest p \\
  --token      sk_live_••• \\
  --workspace  ws_•••

# or run lite
npx -y @schedii/mcp@latest -d     # dash
npx -y @schedii/mcp@latest -f     # sift`,
};

const INVOKE_LINES = [
  { who: 'you',     text: '@sch -d begin "Q4 launch debrief"' },
  { who: 'dash',    text: 'session opened · pertel/2026-05-22/q4-launch-debrief.md' },
  { who: 'you',     text: '@sch -d remember Rob owns ig + tt rollout, Mia owns paid.' },
  { who: 'dash',    text: 'logged · 2 facts pinned · context safe across model swap' },
  { who: 'you',     text: '@sch -f full — sift this launch plan against the bible' },
  { who: 'sift',    text: '7 kept · 3 killed · 2 re-separated · reasons attached' },
  { who: 'you',     text: '@sch p publish the bluesky draft we just approved' },
  { who: 'pertel',  text: 'proposed · confirmToken: txn_8f2a · dry-run · run again to apply' },
  { who: 'you',     text: '@sch -d handoff to claude' },
  { who: 'dash',    text: 'transcript + facts exported · 1 file · 8.2 kb · context preserved' },
];

Object.assign(window, {
  MCPS, SCPF_MODES, STATUS_LABEL,
  McpGlyph, StatusChip, HeroHeader, PertelLockup,
  INSTALL_SNIPPETS, INVOKE_LINES,
});
