# MetaMuLate Component Mapping

This document maps the original HTML sections from `metamulate_decompose.html` to proposed React components, indicating which `@theorchard/suite-components` to use.

## Component Hierarchy

```
MetamulateOAPanel/
├── Header/
│   ├── BrandLogo
│   ├── DataMenu (dropdown)
│   └── ActionButtons
├── MainLayout/
│   ├── ArtistSearch/               (Left Panel - 320px)
│   │   ├── SearchInput
│   │   ├── TrackList
│   │   └── QueueFooter
│   ├── MetadataMatrix/             (Center Panel - Flex)
│   │   ├── ContextHeader
│   │   ├── MatrixGrid/
│   │   │   ├── MatrixHeaderRow
│   │   │   ├── MatrixCategory/     (Collapsible)
│   │   │   │   └── MatrixRow/
│   │   │   │       └── MatrixCell
│   │   │   └── ...
│   │   └── EmptyState
│   └── GoldenRecordPanel/          (Right Panel - 320px)
│       ├── PreviewArtwork
│       ├── GoldenFields/
│       │   └── EditableField
│       └── ResolveButton
├── ConsoleLog/                      (Bottom Panel - Resizable)
│   ├── ConsoleHeader
│   └── LogEntries
└── Modals/
    ├── ConnectionsModal
    ├── WebScrapeModal
    ├── BandcampUrlModal
    ├── WikidataEditorModal
    ├── LyricsModal
    └── DocsModal
```

---

## Detailed Component Mapping

### 1. MetamulateOAPanel (Container)

**Original HTML:** `<body>` wrapper with all state management

**Purpose:** Root container, provides context, initializes app state

**Suite Components:**
- `OAPanel` or custom layout container
- `OAModuleProvider` for application context

**Props Interface:**
```typescript
interface MetamulateOAPanelProps {
  initialArtist?: string;
  onTrackResolved?: (goldenRecord: GoldenRecord) => void;
  theme?: 'default' | 'orchard';
}
```

---

### 2. Header Component

**Original HTML:** `<header id="appHeader">`

**Purpose:** App branding, navigation, data menu, action buttons

**Suite Components:**
- `Header` or custom `<header>` with glass effect
- `Button` for actions
- `Dropdown` for Data & Config menu
- `Tooltip` for help text

**Child Components:**
- `BrandLogo` - Logo with version badge
- `DataMenu` - Export/Import dropdown
- `ConnectionsButton` - Opens config modal

**Example JSX:**
```tsx
<Header className="glass-header">
  <HeaderLeft>
    <BrandLogo version="9.95" />
    <span className="text-slate-400">Primary Data Reconciliation</span>
  </HeaderLeft>
  <HeaderRight>
    <DataMenu onExportSession={...} onImportSession={...} />
    <Button variant="secondary" onClick={openConnections}>
      <PlugIcon /> Connections
    </Button>
    <Button variant="danger" onClick={reset}>
      <TrashIcon /> Reset
    </Button>
    <Button variant="primary" onClick={exportXLSX}>
      <ExportIcon /> Export
    </Button>
  </HeaderRight>
</Header>
```

---

### 3. ArtistSearch Component

**Original HTML:** `<aside id="zoneSearch">`

**Purpose:** Artist discovery, track queue management

**Suite Components:**
- `SearchInput` with icon prefix
- `List` or `VirtualList` for track list
- `Spinner` for loading state
- `EmptyState` for no results

**Child Components:**
- `TrackListItem` - Individual track in queue

**State:**
```typescript
interface ArtistSearchState {
  query: string;
  tracks: TrackMetadata[];
  isLoading: boolean;
  selectedTrackId: string | null;
  hasMore: boolean;
}
```

**Example JSX:**
```tsx
<aside className="w-80 border-r">
  <div className="p-5 border-b">
    <Label>Artist Discovery</Label>
    <SearchInput
      value={query}
      onChange={setQuery}
      onSubmit={discover}
      placeholder="Search Artist (e.g. Daft Punk)"
    />
  </div>
  <TrackList
    tracks={tracks}
    selectedId={selectedTrackId}
    onSelect={selectTrack}
  />
  <QueueFooter count={tracks.length} onLoadMore={loadMore} />
</aside>
```

---

### 4. TrackList Component

**Original HTML:** `<div id="trackList">`

**Purpose:** Scrollable list of discovered tracks

**Suite Components:**
- `VirtualList` for performance with large lists
- Custom `TrackListItem` component

**Example JSX:**
```tsx
<div className="flex-1 overflow-y-auto">
  {tracks.map(track => (
    <TrackListItem
      key={track.id}
      track={track}
      isSelected={track.id === selectedId}
      isResolved={resolvedIds.has(track.id)}
      onClick={() => onSelect(track.id)}
    />
  ))}
</div>
```

---

### 5. TrackListItem Component

**Original HTML:** Rendered dynamically in `renderTrackItem()`

**Purpose:** Single track display with artwork, title, metadata badges

**Suite Components:**
- `Badge` for ISRC, authority score
- `Tooltip` for additional info

**Props:**
```typescript
interface TrackListItemProps {
  track: TrackMetadata;
  isSelected: boolean;
  isResolved: boolean;
  onClick: () => void;
}
```

---

### 6. MetadataMatrix Component

**Original HTML:** `<main id="zoneMatrix">`

**Purpose:** Central reconciliation workspace

**Suite Components:**
- Custom grid layout
- `Tabs` for column source selection (potential)
- `ResizeHandle` for column width adjustment

**Child Components:**
- `ContextHeader` - Current track info
- `MatrixHeaderRow` - Column headers with source icons
- `MatrixCategory` - Collapsible field groups
- `MatrixRow` - Single field across sources
- `MatrixCell` - Individual cell with selection

**State:**
```typescript
interface MatrixState {
  config: MatrixConfig;
  categories: MatrixCategory[];
  selectedCell: { fieldKey: string; sourceKey: string } | null;
}
```

---

### 7. MatrixCell Component

**Original HTML:** Cells in `.matrix-cell`

**Purpose:** Display single value with selection, hover, and provenance link

**Suite Components:**
- `Tooltip` for full value display
- `Badge` or icon for provenance

**Props:**
```typescript
interface MatrixCellProps {
  cell: MatrixCell;
  onSelect: () => void;
  isGolden: boolean;
}
```

**Example JSX:**
```tsx
<div 
  className={cn(
    "matrix-cell p-3 border rounded cursor-pointer",
    cell.isSelected && "selected",
    isGolden && "highlighted"
  )}
  onClick={onSelect}
>
  <span className="truncate">{cell.value.val}</span>
  {cell.value.url && (
    <a href={cell.value.url} target="_blank" className="prov-link">
      <ExternalLinkIcon />
    </a>
  )}
</div>
```

---

### 8. GoldenRecordPanel Component

**Original HTML:** `<aside id="zoneGolden">`

**Purpose:** Display/edit the resolved "golden" record

**Suite Components:**
- `Card` for artwork display
- `Form` with `Field` components for editing
- `Button` for resolve action

**Child Components:**
- `PreviewArtwork` - Album art display
- `EditableField` - Inline editable field
- `FieldCategory` - Grouped fields

**Example JSX:**
```tsx
<aside className="w-80 border-l flex flex-col">
  <div className="p-4 border-b">
    <Label>Golden Record</Label>
    <Button variant="success" onClick={resolveTrack}>
      <CheckIcon /> Confirm & Resolve Track
    </Button>
  </div>
  <PreviewArtwork src={track?.image} />
  <GoldenFields
    goldenRecord={golden}
    onFieldChange={updateField}
  />
</aside>
```

---

### 9. ConsoleLog Component

**Original HTML:** `<div id="consolePanel">`

**Purpose:** System log with colored entries, debug mode, export

**Suite Components:**
- Custom resizable panel
- `Toggle` for debug mode
- `Button` for clear/export

**Features:**
- Resizable height
- Collapsible
- Source-colored log entries
- Debug JSON expansion

**Example JSX:**
```tsx
<ResizablePanel 
  defaultHeight={160}
  minHeight={32}
  maxHeight="50vh"
  className="border-t"
>
  <ConsoleHeader
    debugMode={debugMode}
    onToggleDebug={setDebugMode}
    onClear={clearLogs}
    onExport={exportLogs}
  />
  <LogEntries entries={logs} debugMode={debugMode} />
</ResizablePanel>
```

---

### 10. ScrapeOverlay Component

**Original HTML:** `<div id="scrapingOverlay">`

**Purpose:** Modal overlay showing active scrape progress

**Suite Components:**
- `Modal` or custom overlay
- `ProgressBar` or spinner
- `Button` for cancel

**Child Components:**
- `ScrapeCard` - Individual source progress

**Example JSX:**
```tsx
<Modal isOpen={isActive} className="scraping-overlay">
  <ModalHeader>
    <span>Scraping: {trackName}</span>
    <span>{completedCount}/{totalCount}</span>
  </ModalHeader>
  <ModalBody>
    {sources.map(([key, state]) => (
      <ScrapeCard
        key={key}
        sourceKey={key}
        state={state}
        onCancel={() => cancelSource(key)}
      />
    ))}
  </ModalBody>
  <ModalFooter>
    <Button onClick={cancelAll}>Cancel All</Button>
    <Button onClick={closeOverlay}>Continue in Background</Button>
  </ModalFooter>
</Modal>
```

---

### 11. ConnectionsModal Component

**Original HTML:** `<div id="connectionsModal">`

**Purpose:** API configuration, secrets, proxy settings

**Suite Components:**
- `Modal` with `ModalHeader`, `ModalBody`, `ModalFooter`
- `Form`, `Field`, `Input`, `Select`
- `Toggle` for boolean settings
- `Button` for actions

**Sections:**
1. API Sources (Apple, Discogs, Genius, etc.)
2. CORS Proxy Gateway
3. Matrix Display Settings
4. Snowflake Configuration

---

### 12. WebScrapeModal Component

**Original HTML:** `<div id="webScrapeModal">`

**Purpose:** Manual URL/content scraping

**Suite Components:**
- `Modal`
- `Tabs` for URL vs Paste content
- `Input` for URL
- `Textarea` for pasted content
- `List` for detected candidates

---

### 13. TourOverlay Component

**Original HTML:** `#tourSpotlight`, `#tourTooltip`

**Purpose:** Guided onboarding tour

**Suite Components:**
- Custom overlay with spotlight effect
- `Tooltip` positioned dynamically
- `Button` for navigation

**State:**
```typescript
interface TourState {
  isActive: boolean;
  currentStep: number;
  steps: TourStep[];
}

interface TourStep {
  target: string; // CSS selector
  title: string;
  content: string;
  position: 'top' | 'bottom' | 'left' | 'right';
}
```

---

## Suite Components Usage Summary

| Suite Component | Usage Locations |
|-----------------|-----------------|
| `Button` | Header, Modals, GoldenRecord, Console |
| `Input` | ArtistSearch, ConnectionsModal, WebScrape |
| `Modal` | All modals (Connections, WebScrape, etc.) |
| `Tooltip` | MatrixCell, TrackListItem, various |
| `Badge` | TrackListItem, MatrixCell (ISRC, scores) |
| `Toggle` | DebugMode, Settings |
| `Dropdown` | DataMenu, Source selection |
| `Tabs` | WebScrapeModal (URL/Paste) |
| `Form/Field` | ConnectionsModal, GoldenFields |
| `Spinner` | Loading states |
| `EmptyState` | No tracks, no matrix data |
| `ProgressBar` | ScrapeOverlay (optional) |
| `VirtualList` | TrackList (performance) |

---

## CSS/Styling Notes

1. **Glass Effect Header**: Use `backdrop-filter: blur(16px)` with semi-transparent background
2. **Matrix Cell Hover**: `box-shadow: 0 0 0 1px rgba(accent-color, 0.3)`
3. **Selected Cell**: Green border/background for golden record selections
4. **Console Source Colors**: Map source names to specific text colors
5. **Theme System**: CSS custom properties for theme switching

---

## State Management Recommendations

1. **Apollo Client Cache**: Track list, golden records, resolved tracks
2. **React Context**: 
   - `ScrapeContext` for active scraping state
   - `MatrixContext` for column configuration
   - `ThemeContext` for theme switching
3. **Local State**: Modal visibility, form inputs, UI toggles
4. **localStorage**: Persist config, secrets, matrix settings
