import settings, { type Settings } from "$stores/settings"; import type { CommandPaletteAction } from "./actions"; const TITLE_FORMATS: Settings["displayTitleFormat"][] = [ "english", "romaji", "native", ]; const OUTBOUND_TARGETS: Settings["displayOutboundLinksTo"][] = [ "anilist", "livechartme", "animeschedule", "myanimelist", ]; const OUTBOUND_LABELS: Record = { anilist: "AniList", livechartme: "LiveChart", animeschedule: "AnimeSchedule", myanimelist: "MyAnimeList", }; type BooleanKey = NonNullable< { [K in keyof Settings]: Settings[K] extends boolean ? K : never; }[keyof Settings] >; const boolToggle = ( current: boolean, key: BooleanKey, enableLabel: string, disableLabel: string, tags: string[], ): CommandPaletteAction => ({ name: current ? disableLabel : enableLabel, url: "#", preventDefault: true, tags, onClick: () => settings.setKey(key, !current), }); export const toggleActions = (current: Settings): CommandPaletteAction[] => { const titleIndex = TITLE_FORMATS.indexOf(current.displayTitleFormat); const nextTitle = TITLE_FORMATS[(titleIndex + 1) % TITLE_FORMATS.length]; const outboundIndex = OUTBOUND_TARGETS.indexOf(current.displayOutboundLinksTo); const nextOutbound = OUTBOUND_TARGETS[(outboundIndex + 1) % OUTBOUND_TARGETS.length]; return [ boolToggle( current.display24HourTime, "display24HourTime", "Switch to 24-hour time", "Switch to 12-hour time", ["time", "clock", "24h", "12h", "format"], ), boolToggle( current.displayDisableAnimations, "displayDisableAnimations", "Disable animations", "Enable animations", ["motion", "animation", "accessibility"], ), boolToggle( current.displayBlurAdultContent, "displayBlurAdultContent", "Blur adult content", "Show adult content unblurred", ["nsfw", "adult", "blur", "censor"], ), boolToggle( current.displayCoverModeAnime, "displayCoverModeAnime", "Show anime covers", "Hide anime covers", ["cover", "image", "anime", "display"], ), boolToggle( current.displayCoverModeManga, "displayCoverModeManga", "Show manga covers", "Hide manga covers", ["cover", "image", "manga", "novels", "display"], ), boolToggle( current.displayHoverCover, "displayHoverCover", "Enable hover cover preview", "Disable hover cover preview", ["cover", "hover", "preview"], ), boolToggle( current.displayScheduleListMode, "displayScheduleListMode", "Schedule: list mode", "Schedule: grid mode", ["schedule", "list", "grid", "view"], ), boolToggle( current.displayReverseSort, "displayReverseSort", "Reverse sort order", "Restore default sort order", ["sort", "reverse", "order"], ), boolToggle( current.displayDataSaver, "displayDataSaver", "Enable data saver", "Disable data saver", ["data", "bandwidth", "saver", "performance"], ), boolToggle( current.displayDisableNotifications, "displayDisableNotifications", "Disable in-app notifications", "Enable in-app notifications", ["notifications", "alerts", "toast"], ), { name: current.displayLanguage === "en" ? "Switch language to 日本語" : "Switch language to English", url: "#", preventDefault: true, tags: ["language", "locale", "translate", "japanese", "english"], onClick: () => settings.setKey( "displayLanguage", current.displayLanguage === "en" ? "ja" : "en", ), }, { name: `Title format: ${current.displayTitleFormat} → ${nextTitle}`, url: "#", preventDefault: true, tags: ["title", "format", "english", "romaji", "native"], onClick: () => settings.setKey("displayTitleFormat", nextTitle), }, { name: `Outbound links: ${OUTBOUND_LABELS[current.displayOutboundLinksTo]} → ${OUTBOUND_LABELS[nextOutbound]}`, url: "#", preventDefault: true, tags: [ "outbound", "links", "anilist", "livechart", "animeschedule", "myanimelist", "mal", ], onClick: () => settings.setKey("displayOutboundLinksTo", nextOutbound), }, ]; };