/** * Custom Event Type Definitions * * Type-safe custom events for EDC management components */ import type { TabId, Asset, PolicyDefinition, ContractDefinition, SortDirection } from './edc-types'; // ============================================================================ // Navigation Events // ============================================================================ export interface TabSelectedEventDetail { tabId: TabId; } export class TabSelectedEvent extends CustomEvent { constructor(tabId: TabId) { super('tab-selected', { detail: { tabId }, bubbles: true, composed: true }); } } // ============================================================================ // Asset Events // ============================================================================ export interface AssetEventDetail { asset: Asset; } export class AssetCreatedEvent extends CustomEvent { constructor(asset: Asset) { super('asset-created', { detail: { asset }, bubbles: true, composed: true }); } } export class AssetUpdatedEvent extends CustomEvent { constructor(asset: Asset) { super('asset-updated', { detail: { asset }, bubbles: true, composed: true }); } } export interface AssetDeletedEventDetail { assetId: string; } export class AssetDeletedEvent extends CustomEvent { constructor(assetId: string) { super('asset-deleted', { detail: { assetId }, bubbles: true, composed: true }); } } export class AssetEditClickedEvent extends CustomEvent { constructor(asset: Asset) { super('edit-clicked', { detail: { asset }, bubbles: true, composed: true }); } } export class AssetDeleteClickedEvent extends CustomEvent { constructor(asset: Asset) { super('delete-clicked', { detail: { asset }, bubbles: true, composed: true }); } } // ============================================================================ // Policy Events // ============================================================================ export interface PolicyEventDetail { policy: PolicyDefinition; } export class PolicyCreatedEvent extends CustomEvent { constructor(policy: PolicyDefinition) { super('policy-created', { detail: { policy }, bubbles: true, composed: true }); } } export class PolicyUpdatedEvent extends CustomEvent { constructor(policy: PolicyDefinition) { super('policy-updated', { detail: { policy }, bubbles: true, composed: true }); } } export interface PolicyDeletedEventDetail { policyId: string; } export class PolicyDeletedEvent extends CustomEvent { constructor(policyId: string) { super('policy-deleted', { detail: { policyId }, bubbles: true, composed: true }); } } export class PolicyEditClickedEvent extends CustomEvent { constructor(policy: PolicyDefinition) { super('edit-clicked', { detail: { policy }, bubbles: true, composed: true }); } } export class PolicyDeleteClickedEvent extends CustomEvent { constructor(policy: PolicyDefinition) { super('delete-clicked', { detail: { policy }, bubbles: true, composed: true }); } } // ============================================================================ // Contract Events (Future) // ============================================================================ export interface ContractEventDetail { contract: ContractDefinition; } export class ContractCreatedEvent extends CustomEvent { constructor(contract: ContractDefinition) { super('contract-created', { detail: { contract }, bubbles: true, composed: true }); } } export class ContractUpdatedEvent extends CustomEvent { constructor(contract: ContractDefinition) { super('contract-updated', { detail: { contract }, bubbles: true, composed: true }); } } export interface ContractDeletedEventDetail { contractId: string; } export class ContractDeletedEvent extends CustomEvent { constructor(contractId: string) { super('contract-deleted', { detail: { contractId }, bubbles: true, composed: true }); } } // ============================================================================ // Search & Sort Events // ============================================================================ export interface SearchChangedEventDetail { searchTerm: string; } export class SearchChangedEvent extends CustomEvent { constructor(searchTerm: string) { super('search-changed', { detail: { searchTerm }, bubbles: true, composed: true }); } } export interface SortChangedEventDetail { sortBy: string; } export class SortChangedEvent extends CustomEvent { constructor(sortBy: string) { super('sort-changed', { detail: { sortBy }, bubbles: true, composed: true }); } } export interface DirectionChangedEventDetail { direction: SortDirection; } export class DirectionChangedEvent extends CustomEvent { constructor(direction: SortDirection) { super('direction-changed', { detail: { direction }, bubbles: true, composed: true }); } } // ============================================================================ // Form Events // ============================================================================ export interface FormSubmitEventDetail { data: T; } export class FormSubmitEvent extends CustomEvent> { constructor(data: T) { super('submit', { detail: { data }, bubbles: true, composed: true }); } } export class FormCancelEvent extends CustomEvent { constructor() { super('cancel', { bubbles: true, composed: true }); } } // ============================================================================ // Message Events // ============================================================================ export class MessageDismissedEvent extends CustomEvent { constructor() { super('dismissed', { bubbles: true, composed: true }); } } // ============================================================================ // Locale Events // ============================================================================ export interface LocaleChangedEventDetail { locale: string; } export class LocaleChangedEvent extends CustomEvent { constructor(locale: string) { super('locale-changed', { detail: { locale }, bubbles: true, composed: true }); } } // ============================================================================ // Store Events // ============================================================================ export interface StoreInitializedEventDetail { status: 'connected' | 'partial' | 'mock'; } export class StoreInitializedEvent extends CustomEvent { constructor(status: 'connected' | 'partial' | 'mock') { super('store-initialized', { detail: { status }, bubbles: true, composed: true }); } } // ============================================================================ // Type Guards // ============================================================================ export function isTabSelectedEvent(event: Event): event is TabSelectedEvent { return event.type === 'tab-selected'; } export function isAssetCreatedEvent(event: Event): event is AssetCreatedEvent { return event.type === 'asset-created'; } export function isPolicyCreatedEvent(event: Event): event is PolicyCreatedEvent { return event.type === 'policy-created'; } export function isSearchChangedEvent(event: Event): event is SearchChangedEvent { return event.type === 'search-changed'; }