import type {
  SignItem,
  SignLanguagePageContent,
} from '@/shared/types/app';
import type {
  SignLanguageCategoryFilter,
  SignLanguageViewMode,
} from '@/shared/constants/signLanguage';

export interface SignLanguageCategoryOption {
  readonly value: SignLanguageCategoryFilter;
  readonly label: string;
  readonly count: number;
}

export interface SignLanguageFilters {
  readonly searchQuery: string;
  readonly categoryFilter: SignLanguageCategoryFilter;
}

export interface SignLanguageStepDraft {
  readonly step: number;
  readonly instruction: string;
  readonly duration: number;
}

export interface SignLanguageDraft {
  readonly id: string | null;
  readonly word: string;
  readonly category: SignItem['category'];
  readonly description: string;
  readonly image: string;
  readonly tip: string;
  readonly videoUrl: string;
  readonly gifUrl: string;
  readonly youtubeSearchUrl: string;
  readonly videoSteps: readonly SignLanguageStepDraft[];
}

export type SignLanguageDraftMode = 'create' | 'edit';

export interface SignLanguageVideoModalState {
  readonly showSteps: boolean;
  readonly viewMode: SignLanguageViewMode;
  readonly gifLoaded: boolean;
  readonly gifError: boolean;
  readonly showStepGuide: () => void;
  readonly hideStepGuide: () => void;
  readonly toggleStepGuide: () => void;
  readonly setViewMode: (viewMode: SignLanguageViewMode) => void;
  readonly markGifLoaded: () => void;
  readonly markGifFailed: () => void;
}

export interface SignLanguagePage {
  readonly signs: readonly SignItem[];
  readonly filteredSigns: readonly SignItem[];
  readonly categories: readonly SignLanguageCategoryOption[];
  readonly filters: SignLanguageFilters;
  readonly learnedSignIds: ReadonlySet<string>;
  readonly learnedCount: number;
  readonly progressPercent: number;
  readonly canPersistProgress: boolean;
  readonly canManageSigns: boolean;
  readonly selectedSign: SignItem | null;
  readonly signOfWeekId: string | null;
  readonly signDraft: SignLanguageDraft | null;
  readonly signDraftMode: SignLanguageDraftMode | null;
  readonly signDraftError: string | null;
  readonly signManagementError: unknown;
  readonly signSaveMessage: string | null;
  readonly isSavingSigns: boolean;
  readonly pendingDeleteSign: SignItem | null;
  readonly pageContent: SignLanguagePageContent;
  readonly isLoading: boolean;
  readonly isSaving: boolean;
  readonly signsError: Error | null;
  readonly pageContentError: Error | null;
  readonly progressErrorMessage: string | null;
  readonly setSearchQuery: (value: string) => void;
  readonly clearSearch: () => void;
  readonly setCategoryFilter: (value: SignLanguageCategoryFilter) => void;
  readonly selectSign: (id: string) => void;
  readonly closeSign: () => void;
  readonly toggleLearned: (id: string) => Promise<void>;
  readonly startCreateSign: () => void;
  readonly startEditSign: (sign: SignItem) => void;
  readonly updateSignDraft: (updates: Partial<SignLanguageDraft>) => void;
  readonly updateSignDraftStep: (index: number, updates: Partial<SignLanguageStepDraft>) => void;
  readonly addSignDraftStep: () => void;
  readonly removeSignDraftStep: (index: number) => void;
  readonly cancelSignDraft: () => void;
  readonly saveSignDraft: () => void;
  readonly requestDeleteSign: (sign: SignItem) => void;
  readonly cancelDeleteSign: () => void;
  readonly confirmDeleteSign: () => void;
  readonly selectSignOfWeek: (signId: string) => void;
}
