import 'package:flutter/material.dart'; class NavigationProvider extends ChangeNotifier { int _currentIndex = 0; final List _navigationHistory = [0]; String _currentRoute = '/'; String _currentTitle = '홈'; int get currentIndex => _currentIndex; List get navigationHistory => List.unmodifiable(_navigationHistory); String get currentRoute => _currentRoute; String get currentTitle => _currentTitle; static const Map routeToIndex = { '/': 0, '/add-subscription': -1, '/sms-scanner': 3, '/analysis': 1, '/settings': 4, '/subscription-detail': -1, }; static const Map indexToRoute = { 0: '/', 1: '/analysis', 3: '/sms-scanner', 4: '/settings', }; static const Map indexToTitle = { 0: '홈', 1: '분석', 3: 'SMS 스캔', 4: '설정', }; void updateCurrentIndex(int index, {bool addToHistory = true}) { if (_currentIndex == index) return; _currentIndex = index; _currentRoute = indexToRoute[index] ?? '/'; _currentTitle = indexToTitle[index] ?? '홈'; if (addToHistory && index >= 0) { _navigationHistory.add(index); if (_navigationHistory.length > 10) { _navigationHistory.removeAt(0); } } notifyListeners(); } void updateByRoute(String route) { final index = routeToIndex[route] ?? 0; _currentRoute = route; if (index >= 0) { _currentIndex = index; _currentTitle = indexToTitle[index] ?? '홈'; } else { switch (route) { case '/add-subscription': _currentTitle = '구독 추가'; break; case '/subscription-detail': _currentTitle = '구독 상세'; break; default: _currentTitle = '홈'; } } notifyListeners(); } bool canPop() { return _navigationHistory.length > 1; } void pop() { if (_navigationHistory.length > 1) { _navigationHistory.removeLast(); final previousIndex = _navigationHistory.last; updateCurrentIndex(previousIndex, addToHistory: false); } } void reset() { _currentIndex = 0; _currentRoute = '/'; _currentTitle = '홈'; _navigationHistory.clear(); _navigationHistory.add(0); notifyListeners(); } void clearHistoryAndGoHome() { _currentIndex = 0; _currentRoute = '/'; _currentTitle = '홈'; _navigationHistory.clear(); _navigationHistory.add(0); notifyListeners(); } }