/*************************************************************************
* ADOBE CONFIDENTIAL
* ___________________
*
*  Copyright 2015 Adobe Systems Incorporated
*  All Rights Reserved.
*
* NOTICE:  All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any.  The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and are protected by all applicable intellectual property laws,
* including trade secret and or copyright laws.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
**************************************************************************/
import{dcLocalStorage as e}from"../../../common/local-storage.js";import{LOCAL_FILE_PERMISSION_URL as o,ONE_DAY_IN_MS as t,POPUP_CONTEXT as r}from"../../../common/constant.js";import{events as n}from"../../../common/analytics.js";import{util as a}from"../../js/content-util.js";import{loggingApi as i}from"../../../common/loggingApi.js";import{fetchCombinationOfLocalFilePromptCooldownConfig as c,fetchLocalFileAccessAndSummaryCoachmarkCooldownConfig as l}from"../../../common/util.js";import{CACHE_PURGE_SCHEME as s}from"../../../sw_modules/constant.js";const m="Error in Local File Prompt";async function d(){try{a.translateElements(".translate"),await e.init();const o=document.getElementById("local-file-animated-fte");if(o){const t=e.getItem("appLocale")||chrome.i18n.getMessage("@@ui_locale");o.style.backgroundImage=`url(../../images/LocalizedFte/${t}/fte_old.svg),url(../../images/LocalizedFte/en_US/fte_old.svg)`}else i.error({message:m+"initialize: FTE element not found"});const t=document.getElementById("localFileBlockingPageOpenInChrome"),r=document.getElementById("localFilePromptContinueButton");t.addEventListener("click",g),r.addEventListener("click",f)}catch(e){i.error({message:m,error:`initialize: Error in initialization: ${e}`})}}function g(){try{a.sendAnalytics(n.LOCAL_FILE_OPEN_IN_CHROME_CLICKED),window.history.back()}catch(e){i.error({message:m,error:`handleOpenFileInChromeClick: Error in openInChrome button click handler: ${e}`})}}function u(o){try{let r=e.getItem("localFileConfig");r||(r={promptCount:1}),r.eligibleDate=function(e){const o=Number(e?.settingsCoolDown);return Number.isNaN(o)&&i.error({message:m,error:`_getLocalFilePromptCooldown: cooldownConfig.settingsCoolDown must be a valid number: ${e?.settingsCoolDown}`}),new Date(Date.now()+o*t).toISOString()}(o),e.setItem("localFileConfig",r)}catch(e){i.error({message:m,error:`_updateLocalFilePromptCooldown: Error updating local file blocking UI cooldown: ${e}`})}}async function f(){try{a.sendAnalytics(n.LOCAL_FTE_GO_TO_SETTINGS_CLICKED);if(await chrome.runtime.sendMessage({main_op:"getFloodgateFlag",flag:"dc-cv-combination-of-local-file-prompt",cachePurge:s.NO_CALL})){u(await c())}if(await chrome.runtime.sendMessage({main_op:"getFloodgateFlag",flag:"dc-cv-local-file-access-and-summary-coachmark",cachePurge:s.NO_CALL})){u(await l())}chrome.tabs.create({url:a.constructUrlWithParams(o,{context:r.LOCAL_FILE_COACHMARK,autoDismiss:!0})},o=>{chrome.runtime.lastError?i.error({message:m,error:"handleSwitchToAcrobatClick: Error creating tab"}):(chrome.action.openPopup().catch(e=>console.error(e)),e.setItem("settingsWindow",{id:o.id}),window.history.back())})}catch(e){i.error({message:m,error:`handleSwitchToAcrobatClick: Error in switchToAcrobat button click handler: ${e}`})}}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",d):d();