# Execution Checklist

## Pre-flight

- [ ] Read all current files
- [ ] Backup or rename original files
- [ ] Create folder structure

## Phase 1: Folder Structure

```bash
cd src/tools/VideoPlayer
mkdir -p types hooks utils components context
```

- [ ] Create `types/` directory
- [ ] Create `hooks/` directory
- [ ] Create `utils/` directory
- [ ] Create `components/` directory
- [ ] Create `context/` directory

## Phase 2: Types

- [ ] Create `types/sources.ts` - Source type definitions
- [ ] Create `types/player.ts` - Player config and main types
- [ ] Create `types/provider.ts` - Provider-specific types
- [ ] Create `types/index.ts` - Re-exports
- [ ] Run `pnpm check`

## Phase 3: Utils

- [ ] Create `utils/resolvers.ts` - resolvePlayerMode, isSimpleStreamSource
- [ ] Create `utils/fileSource.ts` - resolveFileSource
- [ ] Create `utils/index.ts` - Re-exports
- [ ] Run `pnpm check`

## Phase 4: Hooks

- [ ] Create `hooks/useVideoPositionCache.ts` - Position caching logic
- [ ] Create `hooks/index.ts` - Re-exports
- [ ] Run `pnpm check`

## Phase 5: Components

- [ ] Move `VideoPlayer.tsx` to `components/`
- [ ] Move `VideoControls.tsx` to `components/`
- [ ] Move `VideoErrorFallback.tsx` to `components/`
- [ ] Create `components/index.ts`
- [ ] Update imports in all moved files
- [ ] Run `pnpm check`

## Phase 6: Context

- [ ] Move `VideoPlayerContext.tsx` to `context/`
- [ ] Create `context/index.ts`
- [ ] Update imports
- [ ] Run `pnpm check`

## Phase 7: Update Providers

- [ ] Update imports in `VidstackProvider.tsx`
- [ ] Update imports in `NativeProvider.tsx`
- [ ] Update imports in `StreamProvider.tsx`
- [ ] Optionally integrate `useVideoPositionCache` hook
- [ ] Run `pnpm check`

## Phase 8: Main Index

- [ ] Update `index.ts` with new imports
- [ ] Verify all exports work
- [ ] Run `pnpm check`

## Phase 9: Cleanup

- [ ] Delete old `types.ts`
- [ ] Delete old `VideoPlayer.tsx`
- [ ] Delete old `VideoControls.tsx`
- [ ] Delete old `VideoErrorFallback.tsx`
- [ ] Delete old `VideoPlayerContext.tsx`
- [ ] Run `pnpm check`
- [ ] Run `pnpm build` (optional)

## Post-flight

- [ ] Test video playback (URL source)
- [ ] Test YouTube embed
- [ ] Test stream playback
- [ ] Test error fallback
- [ ] Verify position caching works

## Final Structure

```
VideoPlayer/
├── index.ts
├── README.md
├── types/
│   ├── index.ts
│   ├── sources.ts
│   ├── player.ts
│   └── provider.ts
├── hooks/
│   ├── index.ts
│   └── useVideoPositionCache.ts
├── utils/
│   ├── index.ts
│   ├── resolvers.ts
│   └── fileSource.ts
├── components/
│   ├── index.ts
│   ├── VideoPlayer.tsx
│   ├── VideoControls.tsx
│   └── VideoErrorFallback.tsx
├── context/
│   ├── index.ts
│   └── VideoPlayerContext.tsx
└── providers/
    ├── index.ts
    ├── VidstackProvider.tsx
    ├── NativeProvider.tsx
    └── StreamProvider.tsx
```

## Metrics

| Metric | Before | After |
|--------|--------|-------|
| types.ts | 369 lines | Split into 3 files (~100 each) |
| Total files | 10 | 18 |
| Hooks | 0 | 1 (useVideoPositionCache) |
| Utils | 0 (in types.ts) | 2 |
| Duplicated code | Position caching x2 | Extracted to hook |

## Optional Improvements

After main refactoring, consider:
1. Integrate `useVideoPositionCache` into providers
2. Extract more shared logic from StreamProvider
3. Add unit tests for utils and hooks
