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,EAAI,MAAM,iCAAiC,EAEvC,KAAK,QAAU,OACjB,aAAa,KAAK,MAAM,EACxB,KAAK,OAAS,KACd,KAAK,aAAe,KACtB,CAGK,QAAQ,CACLM,EAAA,GAAG,YAAa,IAAM,CAC5B,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACf,EAEOA,EAAA,GAAG,WAAY,IAAM,CAC3B,KAAK,iBAAiB,EACvB,EAEOA,EAAA,GAAG,YAAa,IAAM,CAC5B,KAAK,iBAAiB,EACvB,EAEO,sBACN,OAAO,0BAAsB,uFAE9B,KAAK,CAAC,CAAC,QAASC,KAAW,CACpBA,EAAA,GAAG,cAAe,IAAM,CAC5B,KAAK,WAAW,EACjB,EACF,EAGI,eAAgB,CACd,OAAAR,EAAQ,IAAIR,CAAU,GAAK,KAE7B,eAAgB,CACbQ,EAAA,IAAIR,EAAY,MAAM,EAEzB,kBAAmB,CACxBQ,EAAQ,OAAOR,CAAU,EAE7B,CAEM,MAAAiB,EAAQ,IAAIZ","names":["LIST_VIEW_CONCIERGE_TIMES","COOKIE_KEY","getListViewByType","PageInstance","getDefaultListViewTimeout","MapDefaults","TimerClass","period","period_with_default","Cookies","log","__vitePreload","BuyRent_Modal","Page","elapsed_time","new_period","MapMode","Modal","Timer"],"ignoreList":[],"sources":["../../../app/assets/javascripts/app/concierge/timer.ts"],"sourcesContent":["\nimport log from \"plugins/loglevel/index\"\nimport Cookies from \"plugins/cookies-js/index\"\n\nimport { Page } from \"app/multi_device\"\nimport MapMode from \"app/map/mode/manager\"\nimport PageInstance from \"app/page_instance/index\"\nimport MapDefaults from \"app/map/defaults\"\n\nconst LIST_VIEW_CONCIERGE_TIMES = {\n  RESIDENTIAL: {\n    DEFAULT:  70000,\n    TAIWAN:   30000,\n    CHINA:    15000,\n  },\n  COMMERCIAL: {\n    DEFAULT:  20000,\n    TAIWAN:   20000,\n    CHINA:    20000,\n  },\n}\n\nconst COOKIE_KEY = \"window.App.Pages.Cities.Search.Components.Concierge.Shown\"\n\nconst getListViewByType = () => {\n  if (PageInstance.isCommercial()){\n    return LIST_VIEW_CONCIERGE_TIMES.COMMERCIAL\n  }\n\n  return LIST_VIEW_CONCIERGE_TIMES.RESIDENTIAL\n}\n\nfunction getDefaultListViewTimeout(){\n  if (MapDefaults.getDefaultCountryCode() === \"CN\") {\n    return getListViewByType().CHINA\n  }\n  if (MapDefaults.getDefaultCountryCode() === \"TW\") {\n    return getListViewByType().TAIWAN\n  }\n\n  return getListViewByType().DEFAULT\n}\n\ninterface ITimer {\n  setTimer: (period?: number) => any,\n  delayTimer: () => any,\n  clearTimer: () => any,\n\n  getModalShown: () => boolean,\n  setModalShown: () => any,\n  setModalNotShown: () => any,\n\n  onLoad: () => any,\n}\nclass TimerClass implements ITimer {\n  private _timer = null as null | number\n  private _time_object = null as null | {\n    start_time: number,\n    period: number,\n  }\n\n  public setTimer(period?: number){\n    const period_with_default = period || getDefaultListViewTimeout()\n\n    if (this._timer != null) {\n      this.clearTimer()\n    }\n\n    // TODO: use cookies from app/search/filter instead\n    if (Cookies.get(\"window.App.Cells.ListingFilter.SAVED\")){\n      return\n    }\n\n    log.debug(`Concierge modal timeout started ${period_with_default}`)\n\n    this._time_object = {start_time: (new Date()).getTime(), period: period_with_default}\n    this._timer = window.setTimeout(() => {\n      // Avoid delaying timer after modal shown\n      this.clearTimer()\n      Promise.resolve(\n        import(\"concepts/cities/concierge/buy_rent/modal/index\")\n      )\n      .then(({default: BuyRent_Modal}) => {\n        BuyRent_Modal.show()\n      })\n    }, period_with_default)\n  }\n  public delayTimer(){\n    // delay timer by 30 secs for MOBILE only\n    if (!Page.isForMobile()){\n      return\n    }\n\n    if (this._timer != null && this._time_object != null){\n      const elapsed_time = (new Date()).getTime() - this._time_object.start_time\n      const new_period = (this._time_object.period - elapsed_time) + 30000\n\n      this.clearTimer()\n\n      this._time_object = {start_time: (new Date()).getTime(), period: new_period}\n      this._timer = window.setTimeout(() => {\n        // Avoid delaying timer after modal shown\n        this.clearTimer()\n        Promise.resolve(\n          import(\"concepts/cities/concierge/buy_rent/modal/index\")\n        )\n        .then(({default: BuyRent_Modal}) => {\n          BuyRent_Modal.show()\n        })\n      }, new_period)\n    }\n  }\n  public clearTimer(){\n    log.debug(\"Concierge modal timeout cleared\")\n\n    if (this._timer != null) {\n      clearTimeout(this._timer)\n      this._timer = null\n      this._time_object = null\n    }\n  }\n\n  public onLoad(){\n    MapMode.on(\"list_mode\", () => {\n      this.setModalNotShown()\n      this.setTimer()\n    })\n\n    MapMode.on(\"map_mode\", () => {\n      this.setModalNotShown()\n    })\n\n    MapMode.on(\"card_mode\", () => {\n      this.setModalNotShown()\n    })\n\n    Promise.resolve(\n      import(\"app/modal/show-modal\")\n    )\n    .then(({default: Modal}) => {\n      Modal.on(\"modal_shown\", () => {\n        this.delayTimer()\n      })\n    })\n  }\n\n  public getModalShown() {\n    return Cookies.get(COOKIE_KEY) != null\n  }\n  public setModalShown() {\n    Cookies.set(COOKIE_KEY, \"true\")\n  }\n  public setModalNotShown() {\n    Cookies.expire(COOKIE_KEY)\n  }\n}\n\nconst Timer = new TimerClass()\n\n\nexport {\n  Timer,\n  Timer as default,\n}\n"],"file":"assets/timer-D-Y2P1M-.js"}