# Slidev UI Components

Stream B implementation for Issue #101 - UI Components for Slidev presentation control.

## Components Created

### 1. SlidevControls (`src/components/SlidevControls.tsx`)

Main component for generating and controlling Slidev presentations.

#### Features
- **Generation**: Button to trigger deck generation via API
- **Loading States**: Progress bar and messaging for 30-60s GitHub Pages publish time
- **Deck URL Display**: Shows GitHub Pages URL with external link icon
- **Control Buttons**: Next, Previous, and Go to Slide controls
- **Error Handling**: User-friendly error messages with visual indicators
- **Success States**: Confirmation when deck is ready
- **Accessibility**: Full ARIA labels, screen reader support, keyboard navigation

#### Props
```typescript
interface SlidevControlsProps {
  sessionId: string;                                    // Required: Session ID for deck generation
  onDeckGenerated?: (deckUrl: string, deckId: string) => void; // Callback when deck is ready
  onError?: (error: string) => void;                    // Callback for error handling
}
```

#### Usage
```tsx
import { SlidevControls } from '@/components/SlidevControls';

function MyComponent() {
  const handleDeckGenerated = (deckUrl: string, deckId: string) => {
    console.log('Deck ready:', deckUrl);
    // Optional: trigger screenshare automatically
  };

  return (
    <SlidevControls
      sessionId="demo-session-123"
      onDeckGenerated={handleDeckGenerated}
      onError={(error) => console.error('Deck error:', error)}
    />
  );
}
```

#### States
1. **Initial State**: Shows "Generate Presentation" button
2. **Loading State**: Shows spinner, progress bar, and message about GitHub Pages publish time
3. **Ready State**: Shows deck URL, control buttons, and success message
4. **Error State**: Shows error message with icon

#### API Integration
The component expects these endpoints (configure via `NEXT_PUBLIC_MOTIA_API_URL` environment variable):

```typescript
// Generation endpoint
POST /api/slidev/generate
Body: { sessionId, templateId, data }
Response: { deckId, deckUrl, message }

// Control endpoint
POST /api/slidev/control
Body: { deckId, command, slideId? }
Response: success status
```

### 2. DeckViewer (`src/components/DeckViewer.tsx`)

Optional component for displaying Slidev decks inline via iframe.

#### Features
- **Iframe Embedding**: Displays presentation in responsive container
- **16:9 Aspect Ratio**: Maintains proper presentation dimensions
- **Loading States**: Shows spinner while deck loads
- **Error Handling**: Fallback to external window if iframe fails
- **Sandbox Security**: Proper iframe security attributes

#### Props
```typescript
interface DeckViewerProps {
  deckUrl: string;  // GitHub Pages URL of the deck
  deckId: string;   // Unique deck identifier
}
```

#### Usage
```tsx
import { DeckViewer } from '@/components/DeckViewer';

function MyComponent() {
  return (
    <DeckViewer
      deckUrl="https://buzztrail.github.io/buzztrail-presentations/abc123/"
      deckId="abc123"
    />
  );
}
```

## Styling

### CSS Module (`src/styles/slidev-controls.module.css`)

Follows existing demo-experience-ui design patterns:
- **Glassmorphic Design**: Backdrop blur and transparency
- **Rounded Buttons**: 9999px border radius (full rounded)
- **White/Blue Color Scheme**: Consistent with device controls
- **Smooth Animations**: Hover states, transitions, progress bars
- **Responsive Layout**: Flexbox-based, mobile-friendly
- **Accessibility**: High contrast, screen reader utilities

Key style classes:
- `.slidevControls` - Main container
- `.generateButton` - Primary action button
- `.loadingContainer` - Loading state layout
- `.spinner` - Animated loading spinner
- `.progressBar` - Animated progress indicator
- `.deckInfo` - Deck URL display section
- `.controlButtons` - Control button layout
- `.error` / `.success` - Status messages

## Types

### Type Definitions (`src/types/slidev.ts`)

Mock types for component development. These should be replaced when Stream A's types are available:

```typescript
// Request/Response types
interface GenerateDeckRequest
interface GenerateDeckResponse
interface ControlCommand

// Component prop types
interface SlidevControlsProps
interface DeckViewerProps
```

**TODO**: Update imports to use types from Stream A when available:
```typescript
// Replace mock types with:
import type { ... } from '@/types/slidev';
// or from Stream A's type location
```

## Environment Variables

Add to `.env.local`:

```bash
# Motia API URL (Railway deployment)
NEXT_PUBLIC_MOTIA_API_URL=https://your-railway-api.railway.app

# Optional: Slidev API Key (if required by backend)
NEXT_PUBLIC_SLIDEV_API_KEY=your-api-key-here
```

## Integration with Other Streams

### Stream A (API Client)
The SlidevControls component currently has inline API calls. When Stream A's API client is available, refactor to use it:

```typescript
// Current (inline):
const response = await fetch(`${MOTIA_API_URL}/api/slidev/generate`, {...});

// Should become:
import { generateDeck } from '@/lib/api/slidev';
const result = await generateDeck({ sessionId, templateId, data });
```

### Stream C (Screenshare Integration)
To integrate screenshare functionality:

```tsx
import { useScreenshare } from '@/hooks/useScreenshare';
import { SlidevControls } from '@/components/SlidevControls';

function PresentationFlow() {
  const { startSharing } = useScreenshare();

  const handleDeckGenerated = (deckUrl: string) => {
    // Automatically start screensharing when deck is ready
    startSharing(deckUrl);
  };

  return (
    <SlidevControls
      sessionId="session-123"
      onDeckGenerated={handleDeckGenerated}
    />
  );
}
```

### Stream D (Integration)
Stream D should:
1. Import and place SlidevControls in the demo experience flow
2. Connect to session management for `sessionId` prop
3. Wire up callbacks for deck generation events
4. Integrate with screenshare flow
5. Add to appropriate route/page

Example integration:
```tsx
// In demo experience page
import { SlidevControls } from '@/components/SlidevControls';
import { useSession } from '@/hooks/useSession';

function DemoPage() {
  const { sessionId } = useSession();

  return (
    <div className="demo-container">
      {/* Other demo UI */}

      <SlidevControls sessionId={sessionId} />

      {/* Video call interface, etc. */}
    </div>
  );
}
```

## Design Consistency

Components match existing demo-experience-ui patterns:
- Same glassmorphic styling as device controls
- Consistent button styling and hover states
- Matching color palette (white, blue, transparent)
- Similar layout patterns (flex, gaps, padding)
- Same accessibility patterns (sr-only, ARIA labels)

Compare with: `src/components/cvi/components/device-select/`

## Accessibility Features

- **Keyboard Navigation**: All controls are keyboard accessible
- **ARIA Labels**: Buttons and interactive elements have descriptive labels
- **Screen Reader Support**: Hidden text for icon-only buttons
- **Focus Indicators**: Clear focus states for keyboard users
- **Progress Indicators**: Proper ARIA progressbar attributes
- **Error Announcements**: Error messages use `role="alert"`

## Browser Support

Tested patterns compatible with:
- Chrome/Edge (latest)
- Firefox (latest)
- Safari (latest)

## Testing Checklist

- [ ] Component renders with valid sessionId
- [ ] Generate button triggers API call
- [ ] Loading state displays during generation
- [ ] Progress bar animates during loading
- [ ] Deck URL displays when ready
- [ ] Control buttons send commands
- [ ] Go to slide input accepts numbers
- [ ] Error messages display on failures
- [ ] External link opens in new window
- [ ] Keyboard navigation works
- [ ] Screen reader announces states
- [ ] Responsive design works on mobile

## Known Limitations

1. **Mock API Calls**: API endpoints are not implemented yet. Component will fail in production until backend is ready.
2. **Mock Types**: Using local type definitions. Should migrate to shared types when Stream A is integrated.
3. **No Storybook Stories**: Storybook stories not yet created (future enhancement).
4. **Hardcoded Data**: Demo data in generation request is hardcoded.

## Future Enhancements

1. **Storybook Stories**: Add component documentation and testing
2. **Custom Templates**: Allow template selection in UI
3. **Slide Thumbnails**: Show preview of current slide
4. **Slide Count**: Display total slides and current position
5. **Auto-advance**: Timer-based automatic slide progression
6. **Presenter Notes**: Display notes for current slide
7. **Full-screen Toggle**: Maximize deck viewer
8. **Dark Mode**: Support for dark theme

## Files Created

```
apps/demo-experience-ui/src/
├── components/
│   ├── SlidevControls.tsx       (Main control component)
│   └── DeckViewer.tsx            (Optional viewer component)
├── styles/
│   └── slidev-controls.module.css (Component styles)
└── types/
    └── slidev.ts                 (Mock type definitions)
```

## Support

For questions or issues with Stream B components:
- Check progress file: `.claude/epics/slidev-control-mvp/updates/101/stream-b.md`
- Review commit: `d39f063 Issue #101 Stream B: Create SlidevControls UI components`
- See task details: `.claude/epics/slidev-control-mvp/101.md`
