const path = require('path'); /** * AppState - Manages application state */ class AppState { constructor() { this.currentDirectory = null; this.currentFiles = []; this.currentShow = null; this.currentSeasons = []; this.currentEpisodes = []; this.selectedSeasonEpisodeCount = 0; this.isUpdatingEpisodeNumbers = false; // Navigation stack for folder navigation this.navigationStack = []; this.currentDepth = 0; } /** * Set the current directory * @param {string} directory - Directory path */ setCurrentDirectory(directory) { this.currentDirectory = directory; } /** * Get the current directory * @returns {string|null} Current directory path */ getCurrentDirectory() { return this.currentDirectory; } /** * Set current files * @param {Array} files - Array of file objects */ setCurrentFiles(files) { this.currentFiles = files; } /** * Get current files * @returns {Array} Array of file objects */ getCurrentFiles() { return this.currentFiles; } /** * Set current show * @param {Object} show - Show object */ setCurrentShow(show) { this.currentShow = show; } /** * Get current show * @returns {Object|null} Current show object */ getCurrentShow() { return this.currentShow; } /** * Set current seasons * @param {Array} seasons - Array of season objects */ setCurrentSeasons(seasons) { this.currentSeasons = seasons; } /** * Get current seasons * @returns {Array} Array of season objects */ getCurrentSeasons() { return this.currentSeasons; } /** * Set current episodes * @param {Array} episodes - Array of episode objects */ setCurrentEpisodes(episodes) { this.currentEpisodes = episodes; } /** * Get current episodes * @returns {Array} Array of episode objects */ getCurrentEpisodes() { return this.currentEpisodes; } /** * Set selected season episode count * @param {number} count - Episode count */ setSelectedSeasonEpisodeCount(count) { this.selectedSeasonEpisodeCount = count; } /** * Get selected season episode count * @returns {number} Episode count */ getSelectedSeasonEpisodeCount() { return this.selectedSeasonEpisodeCount; } /** * Check if episode numbers are currently updating * @returns {boolean} True if updating */ isUpdatingEpisodeNumbers() { return this.isUpdatingEpisodeNumbers; } /** * Set episode numbers updating flag * @param {boolean} updating - Updating state */ setUpdatingEpisodeNumbers(updating) { this.isUpdatingEpisodeNumbers = updating; } /** * Reset state to initial values */ reset() { this.currentDirectory = null; this.currentFiles = []; this.currentShow = null; this.currentSeasons = []; this.currentEpisodes = []; this.selectedSeasonEpisodeCount = 0; this.isUpdatingEpisodeNumbers = false; this.navigationStack = []; this.currentDepth = 0; } /** * Add directory to navigation stack * @param {string} directory - Directory path to add */ addToNavigationStack(directory) { // Remove any forward history if navigating from middle of stack this.navigationStack = this.navigationStack.slice(0, this.currentDepth + 1); this.navigationStack.push(directory); this.currentDepth = this.navigationStack.length - 1; } /** * Go back to previous directory in navigation stack * @returns {string|null} Previous directory path or null if at root */ goBack() { if (this.canGoBack()) { this.navigationStack.pop(); this.currentDepth--; return this.navigationStack[this.currentDepth]; } return null; } /** * Check if can go back in navigation history * @returns {boolean} True if can go back */ canGoBack() { return this.currentDepth > 0; } /** * Get current directory from navigation stack * @returns {string|null} Current directory path */ getCurrentDirectoryFromStack() { return this.navigationStack[this.currentDepth] || null; } /** * Get navigation depth * @returns {number} Current navigation depth */ getNavigationDepth() { return this.currentDepth; } /** * Get navigation stack * @returns {Array} Array of visited directories */ getNavigationStack() { return this.navigationStack; } } module.exports = AppState;