{"version":3,"file":"index-BCgZ33VH.js","sources":["../../../app/assets/javascripts/apps/spacious_website/components/countries/follow_prompt_modal/index.ts"],"sourcesContent":["\n// region JS Imports\n\n// region External Modules\nimport { EventEmitter } from \"events\"\n\nimport $ from \"jquery\"\n// endregion External Modules\n\n// Private Modules\nimport {\n isLocalStorageEnabled,\n\n getDataFromLocalStorage,\n\n setDataToLocalStorage,\n} from \"app/local_storages/native_api_adapter\"\n// Private Modules\n\n// region Public Components\nimport Modal from \"app/modal/show-modal\"\n\nimport {\n init as CountryFollowButton_init,\n} from \"apps/spacious_website/components/countries/follow_button\"\n// endregion Public Components\n\n// region Private Components\n// endregion Private Components\n\n// endregion JS Imports\n\n\nconst COOKIE_KEY_PREFIX_FOR_SEEN = \"apps_spacious_website_components_countries_follow_prompt_modal__seen\"\n\n\ninterface Selector {\n main: string\n}\ninterface InputSelector {\n main?: string\n}\nconst default_selector = {\n main: \".cell--countries--follow_prompt_modal\",\n}\n\n\nclass CountryUpdateSubscriptionModal extends EventEmitter {\n private selector: Selector\n\n private readonly $el: JQuery\n private readonly $modal = null as JQuery | null\n\n constructor(selector?: InputSelector){\n super()\n\n this.selector = Object.assign({}, default_selector, selector)\n\n this.$el = $(this.selector.main)\n\n if (this.$el.length === 0){ return }\n\n const unix_time_now = new Date().getTime()\n const country_slug = this.$el.data(\"country-slug\")\n const cookie_key_for_seen = `${COOKIE_KEY_PREFIX_FOR_SEEN}/${country_slug}`\n\n if (country_slug.length === 0) { return }\n\n if (!isLocalStorageEnabled()) { return }\n\n // String\n const value_from_local_store = getDataFromLocalStorage(cookie_key_for_seen).data\n let unix_time_for_last_seen: null | number = null\n if (typeof value_from_local_store === \"string\") {\n const parsed_integer = parseInt(value_from_local_store, 10)\n if (!isNaN(parsed_integer)) {\n unix_time_for_last_seen = parsed_integer\n }\n }\n // (24 * 60 * 60 * 1000) = 1 day in ms\n const last_seen_within_time_period =\n unix_time_for_last_seen == null ?\n false :\n unix_time_for_last_seen + (24 * 60 * 60 * 1000) > unix_time_for_last_seen\n if (last_seen_within_time_period) { return }\n\n this.$modal = Modal.showModalWithContent(this.$el, {\n customContent: true,\n })\n\n CountryFollowButton_init({\n container: this.$modal[0] as HTMLElement,\n })\n .then((follow_buttons) => {\n follow_buttons.forEach((follow_button) => {\n follow_button.onFollowed(() => {\n this.close()\n })\n })\n })\n .done()\n\n setDataToLocalStorage(cookie_key_for_seen, unix_time_now.toString())\n }\n\n public close() {\n if (this.$modal == null) { return }\n\n this.$modal.modal(\"hide\")\n }\n}\n\nconst Factory = {\n create(selector?: InputSelector){\n return new CountryUpdateSubscriptionModal(selector)\n },\n}\n\nexport {\n Factory,\n}\n"],"names":["COOKIE_KEY_PREFIX_FOR_SEEN","default_selector","CountryUpdateSubscriptionModal","EventEmitter","selector","$","unix_time_now","country_slug","cookie_key_for_seen","isLocalStorageEnabled","value_from_local_store","getDataFromLocalStorage","unix_time_for_last_seen","parsed_integer","Modal","CountryFollowButton_init","follow_buttons","follow_button","setDataToLocalStorage","Factory"],"mappings":"uNAiCA,MAAMA,EAA6B,uEAS7BC,EAAmB,CACvB,KAAM,uCACR,EAGA,MAAMC,UAAuCC,EAAAA,YAAa,CAMxD,YAAYC,EAAyB,CAO/B,GANE,MAAA,EAHR,KAAiB,OAAS,KAKxB,KAAK,SAAW,OAAO,OAAO,CAAC,EAAGH,EAAkBG,CAAQ,EAE5D,KAAK,IAAMC,EAAE,KAAK,SAAS,IAAI,EAE3B,KAAK,IAAI,SAAW,EAAI,OAE5B,MAAMC,EAAgB,IAAI,KAAK,EAAE,QAAQ,EACnCC,EAAe,KAAK,IAAI,KAAK,cAAc,EAC3CC,EAAsB,GAAG,OAAAR,EAA0B,KAAI,OAAAO,GAIzD,GAFAA,EAAa,SAAW,GAExB,CAACE,IAA2B,OAG1B,MAAAC,EAAyBC,EAAwBH,CAAmB,EAAE,KAC5E,IAAII,EAAyC,KACzC,GAAA,OAAOF,GAA2B,SAAU,CACxC,MAAAG,EAAiB,SAASH,EAA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