# CalendarApp Event Specification

## 1. Oversigt

CalendarApp initialiseres med `CalendarApp.create(container)`.

Kommunikation sker via DOM events:
- **Command events**: Host → Calendar
- **Status events**: Calendar → Host

Settings hentes fra `SettingsService` (IndexedDB).

---

## 2. Command Events (Host → Calendar)

| Event | Payload | Beskrivelse |
|-------|---------|-------------|
| `calendar:cmd:render` | `{ viewConfig }` | Render kalenderen med ViewConfig |

```typescript
interface IRenderCommandPayload {
  viewConfig: ViewConfig;
}
```

**Eksempel:**
```typescript
document.dispatchEvent(new CustomEvent('calendar:cmd:render', {
  detail: {
    viewConfig: {
      templateId: 'team',
      groupings: [
        { type: 'team', values: ['team1', 'team2'] },
        { type: 'resource', values: ['EMP001', 'EMP002'], idProperty: 'resourceId', belongsTo: 'team.resourceIds' },
        { type: 'date', values: ['2025-12-08', '2025-12-09'], idProperty: 'date', derivedFrom: 'start' }
      ]
    }
  }
}));
```

---

## 3. Status Events (Calendar → Host)

| Event | Payload | Beskrivelse |
|-------|---------|-------------|
| `calendar:status:ready` | `{}` | Calendar initialiseret |
| `calendar:status:rendered` | `{ templateId }` | Rendering færdig |
| `calendar:status:error` | `{ message, code }` | Fejl opstået |

```typescript
interface IRenderedStatusPayload {
  templateId: string;
}

interface IErrorStatusPayload {
  message: string;
  code: 'INVALID_PAYLOAD' | 'RENDER_FAILED';
}
```

---

## 4. CalendarApp

### 4.1 Initialisering
```typescript
await CalendarApp.create(container);
```

### 4.2 Dependencies (via DI)
- CalendarOrchestrator
- SettingsService
- TimeAxisRenderer
- ScrollManager
- DragDropManager
- EdgeScrollManager
- ResizeManager
- HeaderDrawerManager
- EventBus

### 4.3 Ansvar
- Subscribe på `calendar:cmd:render`
- Emit `calendar:status:ready` ved init
- Emit `calendar:status:rendered` efter render
- Emit `calendar:status:error` ved fejl

---

## 5. Filer

| Fil | Beskrivelse |
|-----|-------------|
| `src/v2/CalendarApp.ts` | Entry point |
| `src/v2/types/CommandTypes.ts` | Payload interfaces |
| `src/v2/constants/CommandEvents.ts` | Event konstanter |
