/** * Voice-over recording UI state. * Transient by nature — a recording never survives a reload, so unlike most * stores here this one is intentionally NOT persisted (same pattern as * editor-store / properties-store). */ import { create } from "zustand"; import { persist } from "zustand/middleware"; import type { MediaTime } from "@/wasm"; import { DEFAULT_VOICE_OVER_ENHANCEMENTS, type VoiceOverEnhancementSettings, } from "@/voiceover/enhancements"; export type VoiceOverStatus = "idle" | "recording" | "processing"; interface VoiceOverStore { status: VoiceOverStatus; startedAtMs: number | null; playheadStartTime: MediaTime | null; startRecording: ({ playheadTime }: { playheadTime: MediaTime }) => void; processRecording: () => void; stopRecording: () => void; } interface VoiceOverPreferencesStore { selectedDeviceId: string | null; enhancements: VoiceOverEnhancementSettings; setSelectedDeviceId: ({ deviceId }: { deviceId: string | null }) => void; setEnhancementEnabled: ({ id, enabled, }: { id: keyof VoiceOverEnhancementSettings; enabled: boolean; }) => void; } export const useVoiceOverStore = create()((set) => ({ status: "idle", startedAtMs: null, playheadStartTime: null, startRecording: ({ playheadTime }) => { set({ status: "recording", startedAtMs: Date.now(), playheadStartTime: playheadTime, }); }, processRecording: () => { set({ status: "processing", startedAtMs: null, }); }, stopRecording: () => { set({ status: "idle", startedAtMs: null, playheadStartTime: null, }); }, })); export const useVoiceOverPreferencesStore = create()( persist( (set) => ({ selectedDeviceId: null, enhancements: DEFAULT_VOICE_OVER_ENHANCEMENTS, setSelectedDeviceId: ({ deviceId }) => { set({ selectedDeviceId: deviceId }); }, setEnhancementEnabled: ({ id, enabled }) => { set((state) => ({ enhancements: { ...state.enhancements, [id]: enabled, }, })); }, }), { name: "voiceover-preferences-store", partialize: (state) => ({ selectedDeviceId: state.selectedDeviceId, enhancements: state.enhancements, }), }, ), );