/*************************************************************************
* 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{events as o}from"../../../common/analytics.js";import{LOCAL_FILE_PERMISSION_URL as t,ONE_DAY_IN_MS as n,POPUP_CONTEXT as r}from"../../../common/constant.js";import{floodgate as i}from"../../../sw_modules/floodgate.js";import{util as a}from"../../js/content-util.js";import{loggingApi as s}from"../../../common/loggingApi.js";import{setExperimentCodeForAnalytics as l}from"../../../common/experimentUtils.js";import{CACHE_PURGE_SCHEME as c}from"../../../sw_modules/constant.js";import{fetchCombinationOfLocalFilePromptCooldownConfig as m,fetchLocalFileAccessAndSummaryCoachmarkCooldownConfig as g}from"../../../common/util.js";const d="Error in Local File Prompt";let u=!1;async function p(){try{a.translateElements(".translate");const o=document.getElementById("local-file-animated-fte");u=await async function(){return await chrome.runtime.sendMessage({main_op:"getFloodgateFlag",flag:"dc-cv-show-animation-on-settings",cachePurge:c.NO_CALL})}();let t="fte_old.svg";if(u&&(t="fte.svg",l("LFS")),await e.init(),o){const n=e.getItem("appLocale")||chrome.i18n.getMessage("@@ui_locale");o.style.backgroundImage=`url(../../images/LocalizedFte/${n}/${t}),url(../../images/LocalizedFte/en_US/${t})`,u&&(o.style.backgroundColor="transparent")}else s.error({message:d+"initialize: FTE element not found"});document.getElementById("localFilePromptContinueButton").addEventListener("click",f)}catch(e){s.error({message:d,error:`initialize: Error in initialization: ${e}`})}}async function f(){try{a.sendAnalytics(o.LOCAL_FTE_GO_TO_SETTINGS_CLICKED);!function(o){try{let t=e.getItem("localFileConfig");t||(t={promptCount:1}),t.eligibleDate=function(e){const o=Number(e?.settingsCoolDown);Number.isNaN(o)&&s.error({message:d,error:`_getLocalFilePromptCooldown: cooldownConfig.settingsCoolDown must be a valid number: ${e?.settingsCoolDown}`});return new Date(Date.now()+o*n).toISOString()}(o),e.setItem("localFileConfig",t)}catch(e){s.error({message:d,error:`_updateLocalFilePromptCooldown: Error updating local file prompt cooldown: ${e}`})}}(await async function(){let e;try{if(await chrome.runtime.sendMessage({main_op:"getFloodgateFlag",flag:"dc-cv-combination-of-local-file-prompt",cachePurge:c.NO_CALL}))return e=await m(),e;if(await chrome.runtime.sendMessage({main_op:"getFloodgateFlag",flag:"dc-cv-local-file-access-and-summary-coachmark",cachePurge:c.NO_CALL}))return e=await g(),e;e=i.getFeatureMeta("dc-cv-local-file-permission-prompt"),e=JSON.parse(e)}catch(o){e={promptLimit:5,ignoreCoolDown:7,settingsCoolDown:7,dismissCoolDown:7}}return e}());const l=e.getItem("localFteWindow");if(l){const{id:o,height:n,width:i,left:a,top:c}=l;let m="popup",g=t;if(u){m="normal";const e=t.split("#"),o=e[0],n=e[1];g=`${o}&context=${r.LOCAL_FILE_COACHMARK}&autoDismiss=true#${n}`}chrome.windows.create({height:n,width:i,left:a,top:c,focused:!0,type:m,url:g},t=>{chrome.runtime.lastError?s.error({message:d,error:"handleSettingsButtonCLick: Error creating window"}):(u&&chrome.action.openPopup().catch(e=>console.error(e)),e.setItem("settingsWindow",{id:t.tabs[0].id}),chrome.windows.remove(o))})}else s.error({message:d,error:"handleSettingsButtonCLick: Window configuration not found in storage"})}catch(e){s.error({message:d,error:`handleSettingsButtonCLick: Error in button click handler: ${e}`})}}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",p):p();