import { sleep } from '../infrastructure/sleep' ; import { Surveys } from '../model/survey' ; export const DEFAULT_PROMPT_IMPRESSION_DELAY_MS = 3000 ; export class OutlineSurveys implements Surveys { constructor ( private view , private storage = localStorage , private promptImpressionDelayMs = DEFAULT_PROMPT_IMPRESSION_DELAY_MS , private dataLimitsAvailabilityDate ? ) { } async presentDataLimitsEnabledSurvey ( ) { if ( this . isSurveyExpired ( this . dataLimitsAvailabilityDate ) ) { return ; } await this . presentSurvey ( 'dataLimitsEnabledSurvey' , this . view . localize ( 'survey-data-limits-title' ) , 'https://docs.google.com/forms/d/e/1FAIpQLSeXQ5WUHXQHlF1Ul_ViX52GjTUPlrRB_7rhwbol3dKJfM4Kiw/viewform' ) ; } async presentDataLimitsDisabledSurvey ( ) { if ( this . isSurveyExpired ( this . dataLimitsAvailabilityDate ) ) { return ; } await this . presentSurvey ( 'dataLimitsDisabledSurvey' , this . view . localize ( 'survey-data-limits-title' ) , 'https://docs.google.com/forms/d/e/1FAIpQLSc2ZNx0C1a-alFlXLxhJ8jWk-WgcxqKilFoQ5ToI8HBOK9qRA/viewform' ) ; } private async presentSurvey ( surveyId , surveyTitle , surveyLink ) { if ( this . storage . getItem ( surveyId ) ) { return ; } await sleep ( this . promptImpressionDelayMs ) ; this . view . open ( surveyTitle , surveyLink ) ; this . storage . setItem ( surveyId , 'true' ) ; } private isSurveyExpired ( surveyAvailabilityDate ) { const now = new Date ( ) ; return surveyAvailabilityDate && now > surveyAvailabilityDate ; } }