import { Feedback , ReviewPriority , ScreenName , } from '@ulangi/ulangi-common/enums' ; import { SelectionItem } from '@ulangi/ulangi-common/interfaces' ; import { ObservableWritingSettingsScreen } from '@ulangi/ulangi-observable' ; import { boundClass } from 'autobind-decorator' ; import { config } from '../../constants/config' ; import { WritingSettingsScreenIds } from '../../constants/ids/WritingSettingsScreenIds' ; import { LessonScreenStyle } from '../../styles/LessonScreenStyle' ; import { DialogDelegate } from '../dialog/DialogDelegate' ; import { NavigatorDelegate } from '../navigator/NavigatorDelegate' ; import { ReviewFeedbackButtonDelegate } from '../review-feedback/ReviewFeedbackButtonDelegate' ; import { WritingSettingsDelegate } from './WritingSettingsDelegate' ; @ boundClass export class WritingSettingsScreenDelegate { private observableScreen : ObservableWritingSettingsScreen ; private writingSettingsDelegate : WritingSettingsDelegate ; private reviewFeedbackButtonDelegate : ReviewFeedbackButtonDelegate ; private dialogDelegate : DialogDelegate ; private navigatorDelegate : NavigatorDelegate ; public constructor ( observableScreen , writingSettingsDelegate , reviewFeedbackButtonDelegate , dialogDelegate , navigatorDelegate ) { this . observableScreen = observableScreen ; this . writingSettingsDelegate = writingSettingsDelegate ; this . reviewFeedbackButtonDelegate = reviewFeedbackButtonDelegate ; this . dialogDelegate = dialogDelegate ; this . navigatorDelegate = navigatorDelegate ; } public save ( ) { this . writingSettingsDelegate . saveSettings ( { initialInterval : this . observableScreen . selectedInitialInterval , limit : this . observableScreen . selectedLimit , feedbackButtons : this . observableScreen . selectedFeedbackButtons , autoplayAudio : this . observableScreen . selectedAutoplayAudio , autoShowKeyboard : this . observableScreen . selectedAutoShowKeyboard , highlightOnError : this . observableScreen . selectedHighlightOnError , reviewPriority : this . observableScreen . selectedReviewPriority , } , { onSaving : ( ) : void => this . dialogDelegate . showSavingDialog ( ) , onSaveSucceeded : ( ) : void => this . dialogDelegate . showSaveSucceededDialog ( ) , onSaveFailed : ( errorBag ) : void => this . dialogDelegate . showSaveFailedDialog ( errorBag ) , } ) ; } public showLimitMenu ( valuePairs , selectedLimit , onSelect ) { this . navigatorDelegate . showSelectionMenu ( { items : new Map ( valuePairs . map ( ( [ limit , limitText ] ) : [ number , SelectionItem ] => { return [ limit , { testID : WritingSettingsScreenIds . SELECT_LIMIT_BTN_BY_LIMIT ( limit ) , text : limitText , onPress : ( ) : void => { onSelect ( limit ) ; this . navigatorDelegate . dismissLightBox ( ) ; } , } , ] ; } ) ) , selectedIds : [ selectedLimit ] , title : 'Select' , } , LessonScreenStyle . LIGHT_BOX_SCREEN_STYLES ) ; } public showFeedbackButtonsMenu ( valuePairs , selectedFeedbackButtons , onSelect ) { this . navigatorDelegate . showSelectionMenu ( { items : new Map ( valuePairs . map ( ( [ feedbackButtons , feedbackButtonsText ] ) : [ number , SelectionItem ] => { return [ feedbackButtons , { testID : WritingSettingsScreenIds . SELECT_FEEDBACK_BUTTONS_BTN_BY_FEEDBACK_BUTTONS ( feedbackButtons ) , text : feedbackButtonsText , onPress : ( ) : void => { onSelect ( feedbackButtons ) ; this . dialogDelegate . dismiss ( ) ; } , } , ] ; } ) ) , selectedIds : [ selectedFeedbackButtons ] , title : 'Select' , } , LessonScreenStyle . LIGHT_BOX_SCREEN_STYLES ) ; } public showInitialIntervalMenu ( valuePairs , selectedLevel , onSelect ) { this . navigatorDelegate . showSelectionMenu ( { items : new Map ( valuePairs . map ( ( [ initialInterval , initialIntervalText ] ) : [ number , SelectionItem ] => { return [ initialInterval , { testID : WritingSettingsScreenIds . SELECT_INITIAL_INTERVAL_BTN_BY_INITIAL_INTERVAL ( initialInterval ) , text : initialIntervalText , onPress : ( ) : void => { onSelect ( initialInterval ) ; this . navigatorDelegate . dismissLightBox ( ) ; } , } , ] ; } ) ) , selectedIds : [ selectedLevel ] , title : 'Select' , } , LessonScreenStyle . LIGHT_BOX_SCREEN_STYLES ) ; } public getButtonsToShow ( numberOfFeedbackButtons ) { return this . reviewFeedbackButtonDelegate . getButtonsToShow ( numberOfFeedbackButtons ) ; } public showReviewPriorityMenu ( valuePairs , selectedReviewPriority , onSelect ) { this . navigatorDelegate . showSelectionMenu ( { items : new Map ( valuePairs . map ( ( [ reviewPriority , reviewPriorityText ] ) : [ ReviewPriority , SelectionItem ] => { return [ reviewPriority , { testID : WritingSettingsScreenIds . SELECT_REVIEW_PRIORITY_BTN_BY_REVIEW_PRIORITY ( reviewPriority ) , text : reviewPriorityText , onPress : ( ) : void => { onSelect ( reviewPriority ) ; this . navigatorDelegate . dismissLightBox ( ) ; } , } , ] ; } ) ) , selectedIds : [ selectedReviewPriority ] , title : 'Select' , } , LessonScreenStyle . LIGHT_BOX_SCREEN_STYLES ) ; } public showIntervalsLightBox ( ) { this . navigatorDelegate . showLightBox ( ScreenName . INTERVALS_SCREEN , { initialInterval : this . observableScreen . selectedInitialInterval , range : [ 1 , config . writing . maxLevel - 1 ] , } , LessonScreenStyle . LIGHT_BOX_SCREEN_STYLES ) ; } }