// components/TierPanels/T3Panel.jsx
//
// T3 (Inner Circle) panel. The inner sanctum.
// Adds: Cerebras thinking raw trace, Sovereign override diagram,
//       IP portfolio summary, strategic roadmap, financial architecture.
// At T3, the architectural commitment is: there is nothing further being hidden.
// The substrate's depth is the design itself.
// Inherits: T0 + T1 + T2.
//
// Wire-in: window.T3Panel = T3Panel

const { useState, useEffect } = React;

function T3Panel({ persistence, cerebrasBackchannel }) {
  const [thinkingTraces, setThinkingTraces] = useState([]);
  const [showOverrideDiagram, setShowOverrideDiagram] = useState(false);

  // Subscribe to Cerebras thinking events
  useEffect(() => {
    if (!cerebrasBackchannel) return;
    const handler = (event) => {
      if (event.type === 'cerebras_thinking') {
        setThinkingTraces(prev => [event, ...prev].slice(0, 5));
      }
    };
    cerebrasBackchannel.on?.('event', handler);
    return () => cerebrasBackchannel.off?.('event', handler);
  }, [cerebrasBackchannel]);

  return React.createElement('aside', { className: 't3-panel' },
    React.createElement('header', { className: 't3-panel-header' },
      React.createElement('h3', null, 'T3. Inner Circle'),
      React.createElement('p', { className: 't3-panel-subtitle' },
        'The substrate has shown you everything. The depth is the design itself.'
      )
    ),

    React.createElement('section', { className: 't3-section' },
      React.createElement('h4', null, 'Cerebras LOG-5 base-7 _thinking trace (raw)'),
      React.createElement('p', { className: 't3-section-note' },
        'Raw model thinking on the most recent substantive turns. Not a summary; the actual reasoning.'
      ),
      thinkingTraces.length === 0
        ? React.createElement('p', { className: 't3-empty' },
            'No thinking traces yet. Speak to Morphy to see the reasoning.'
          )
        : React.createElement('div', { className: 't3-thinking-stack' },
            thinkingTraces.map((trace, i) =>
              React.createElement('details', { key: i, className: 't3-thinking-trace' },
                React.createElement('summary', null,
                  `Turn at ${new Date(trace.timestamp).toLocaleTimeString()}`
                ),
                React.createElement('pre', { className: 't3-thinking-payload' },
                  trace._thinking || trace.thinking || '(thinking content empty)'
                )
              )
            )
          )
    ),

    React.createElement('section', { className: 't3-section' },
      React.createElement('h4', null, 'Sovereign override mechanism'),
      React.createElement('p', { className: 't3-section-note' },
        'When Sovereign is physically present at a demo, the keystroke below elevates the current visitor in real time. You cannot trigger this yourself; only the Sovereign session can. The mechanism is shown here as architectural transparency.'
      ),
      React.createElement('button', {
        className: 't3-override-toggle',
        onClick: () => setShowOverrideDiagram(!showOverrideDiagram),
      }, showOverrideDiagram ? 'Hide override diagram' : 'Show override diagram'),
      showOverrideDiagram && React.createElement('div', { className: 't3-override-diagram' },
        React.createElement('div', { className: 't3-keystroke-glyph' },
          React.createElement('kbd', null, 'Cmd'),
          ' + ',
          React.createElement('kbd', null, 'Shift'),
          ' + ',
          React.createElement('kbd', null, 'S'),
          React.createElement('kbd', null, 'S'),
          React.createElement('kbd', null, 'S'),
          ' (triple-tap S within 800ms)'
        ),
        React.createElement('p', null,
          'Triggers Sovereign-presence elevation. Generates ephemeral Ed25519 token signed with Kaitiaki private key. Writes Kaitiaki receipt with grant_mechanism: "sovereign_presence". Token expires when session ends.'
        ),
        React.createElement('p', { className: 't3-override-architecture' },
          'Architectural commitment: highest-trust elevation requires physical co-presence with Sovereign. The substrate binds the deepest grant act to the physical world.'
        )
      )
    ),

    React.createElement('section', { className: 't3-section' },
      React.createElement('h4', null, 'IP portfolio (summary)'),
      React.createElement('p', { className: 't3-placeholder-note' },
        'Sovereign-authored content goes here before Patrick visits.'
      ),
      React.createElement('ul', { className: 't3-ip-stub' },
        React.createElement('li', null, 'Kaitiaki cryptographic provenance (under Galbraith review)'),
        React.createElement('li', null, 'iHum Mediator Clean Pipe Matrix (stigmergic anonymity)'),
        React.createElement('li', null, 'Morphy Substrate (Constitution Stack architecture)'),
        React.createElement('li', null, 'CKICAS framework (eight-stock community resilience model)'),
        React.createElement('li', null, 'KSFE methodology (Kinetic Stock-Flow Elicitation)')
      )
    ),

    React.createElement('section', { className: 't3-section' },
      React.createElement('h4', null, 'Strategic roadmap (with confidential timing)'),
      React.createElement('p', { className: 't3-placeholder-note' },
        'Sovereign-authored content goes here before Patrick visits.'
      ),
      React.createElement('ul', { className: 't3-roadmap-stub' },
        React.createElement('li', null, 'Substrate v2.0 finalisation: 4-5 weeks from 2026-05-07'),
        React.createElement('li', null, 'First commercial pilot: target Q3 2026'),
        React.createElement('li', null, 'PhD thesis defence + ISDC 2026 paper: Q3 2026'),
        React.createElement('li', null, 'Series Seed: timing TBD with capital partners'),
        React.createElement('li', null, 'Substrate v3.0 (federated): 2027 horizon')
      )
    ),

    React.createElement('section', { className: 't3-section' },
      React.createElement('h4', null, 'Financial architecture'),
      React.createElement('p', { className: 't3-placeholder-note' },
        'Sovereign-authored content goes here before Patrick visits.'
      ),
      React.createElement('p', { className: 't3-financial-stub' },
        'Company structure, equity allocation framework, capital strategy. Authored by Sovereign before specific T3 visitors arrive.'
      )
    ),

    React.createElement('section', { className: 't3-inner-sanctum-disclosure' },
      React.createElement('p', null,
        React.createElement('strong', null, 'This is the inner sanctum.'),
        ' Nothing further is being hidden. The substrate\u2019s depth is the design itself. Every layer shown is a real layer. There is no proprietary mystery beneath this. The moat is the architecture, fully disclosed.'
      )
    )
  );
}

window.T3Panel = T3Panel;
