/*************************************************************************
* 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{analytics as e,events as t}from"../../common/analytics.js";import{dcLocalStorage as n}from"../../common/local-storage.js";import{util as s}from"./content-util.js";import{privateApi as a}from"./content-privateApi.js";import{LOCALES as i,LOCAL_FILE_PERMISSION_URL as o,OptionPageActions as r}from"../../common/constant.js";import{getGenAIServiceVariant as c}from"../../common/util.js";import l from"./highlight-overlay.js";import{loggingApi as p}from"../../common/loggingApi.js";import{largeBlobStorage as d}from"../../common/large-blob-storage.js";await n.init(),$(function(){const h="analyticsOptinTitle",u="web2pdfOptOut",g="web2pdfOptOutDisabled",m="LearnMoreURL",f="web2pdfPrivacy",S="web2pdfShowPDFTools",I="web2pdfFrictionlessToggleDescription",E="whatsNewAutoOpenTitle",T="whatsNewAutoOpenDescription",_="pdfOwnershipExploreOptionsTitle",b="pdfOwnershipExploreOptionsDescription",P="web2pdfOpenConvertedPDFTitle",v="web2pdfOpenConvertedPDFDescription",O="web2pdfShowPersistentOpen",A="web2pdfShowPersistentOpenDescription",w="webpagePDFConversion",N="webpagePDFConversionDescription",D="enableGenAIFeaturesTitle",R="enableGenAIFeaturesDescription",L="enableGenAIAutoSummarizeTitle",C="enableGenAIAutoSummarizeDescription",x="bypassGenAIWebpageEligibilityTitle",B="bypassGenAIWebpageEligibilityDescription",y="optionsSuccessPrompt",M="optionsSuccessPromptReloadRequired",F="optionsFailurePrompt",k="appearancePrefTitle",U="appearancePrefDesc",G="appearancePrefOp1",H="appearancePrefOp2",K="appearancePrefOp3",V="saveLocationPreferenceTitle",W="saveLocationPreferenceDescription",q="saveLocationOp1",j="saveLocationOp2",z="saveLocationOp3",X="userLocale",Y="acrobatGsuiteTouchPointPreferenceTitle",Z="acrobatGsuiteTouchPointPreferenceDescription",J="acrobatTouchPointInOtherSitesPreferenceTitle",Q="acrobatEmbeddedTouchPointPreferenceTitle",ee="acrobatEmbeddedTouchPointPreferenceDescription",te="acrobatTouchPointInOtherSurfacesPreferenceDescription",ne="acrobatLinkedInPDFTouchPointPreferenceDescription",se="expressTouchpointPreferenceTitle",ae="expressTouchpointPreferenceDescription",ie="aiMarkerTouchpointPreferenceTitle",oe="aiMarkerTouchpointPreferenceDescription",re="localFileOptionTitle",ce="localFileOptionDesc",le="askAssistantBannerTitle",pe="askAssistantBannerContentText",de="acrobatTouchPointInOtherSitesPrefDescription";let he=[],ue={},ge=null;class me{constructor(){this.showEligibleSaveButton(),this.ID="#web2pdfSaveButton",this.closePromptID="#prompt-close",this.enableState=!1,this.optionStates=new Set,this.timeoutId=null,this.reloadRequiredForPreference=!1,$(this.ID).click(e=>this.SavePreferences(e)),$(this.closePromptID).click(e=>this.HideSavedPrompt(e))}showEligibleSaveButton(){let e,t;[e,t]=[$("#saveButtonHeader"),$("#saveButtonFooter")],e.removeClass("hidden"),t.remove()}Reset(){this.enableState=!1,this.optionStates.clear(),$(this.ID).prop("disabled",!0)}setEnabled(e){this.optionStates.add(e),$(this.ID).prop("disabled",!1),this.enableState=!0}setDisabled(e){this.optionStates.has(e)&&(this.optionStates.delete(e),0===this.optionStates.size&&($(this.ID).prop("disabled",!0),this.enableState=!1))}GetState(){return this.enableState}_checkAndClearSSRBlobStorage(e=[]){e.some(e=>e.titleId===X)&&d.removeItem("anonGenAISSRHtml")}SavePreferences(){const e={analytics:[]};for(const t in ue)ue[t].hasUpdated&&(e[t]=ue[t].GetCurrentState());const t=he.find(e=>"pdfViewer"===e.storageKey&&e.hasUpdated);if(t){let e;!0===t.currentState||"true"===t.currentState?(n.setItem("viewer-enabled-source","ownership-consent"),e="true"):e="false",s.isEdge()&&s.messageToMain({main_op:"pdfViewerChanged",value:e})}ue.environment&&ue.environment.hasUpdated&&(s.messageToMain({main_op:"init-floodgate"}),s.messageToMain({main_op:"closeOffscreenDocument"}));const a=he.filter(e=>e.hasUpdated),i=a.length,o=[],r=n.getItem("optionsPageSource");this._checkAndClearSSRBlobStorage(a),a.map(e=>e.SavePreferences()).filter(e=>e).forEach(t=>{e.analytics.push([t,{optionsPageSource:r}]),o.push(t)}),i>0&&p.info({message:"Options preferences updated",updatedSettingsCount:i,analyticsEvents:o,optionsPageSource:r}),function(e,t){s.messageToMain({main_op:"save-preferences",...e},t)}(e,e=>{e.success?this.ShowSavedPrompt(!0):this.ShowSavedPrompt(!1),this.Reset(),Be(async e=>{Re(e.settings),await xe(e),Le()})})}ShowSavedPrompt(e){const t=$("#savePrompt"),n=$(".prompt"),a=$("#optionsSuccessPrompt");e?(this.reloadRequiredForPreference?a.text(s.getTranslation(M)):a.text(s.getTranslation(y)),this.reloadRequiredForPreference=!1,n.removeClass("failure")):(a.text(s.getTranslation(F)),n.addClass("failure")),t.show(),this.timeoutId&&clearTimeout(this.timeoutId),this.timeoutId=setTimeout(e=>this.HideSavedPrompt(),5e3)}HideSavedPrompt(){$("#savePrompt").hide()}}class fe{constructor(e,t,s,a){this.titleId=e,this.descriptionId=t,this.storageKey=a,this.defaultState=n.getItem(this.storageKey)||s,this.currentState=this.defaultState,this.hasUpdated=!1,this.savePreferencesButton=null}AttachEventHandler(e){this.savePreferencesButton=e}RenderInputItem(){return $("<div/>")}Render(e=""){const t=$("<div/>",{class:"option "+e}),n=$("<label/>",{class:"label",for:this.titleId}),a=$("<span/>",{class:"label-title",text:s.getTranslation(this.titleId)||this.titleId,id:this.titleId}),i=$("<span/>",{class:"label-description",text:s.getTranslation(this.descriptionId)||this.descriptionId,id:this.descriptionId});n.append(a),n.append(i),t.append(n);const o=this.RenderInputItem();return t.append(o),t}GetCurrentState(){return this.currentState}SavePreferences(){this.hasUpdated&&(this.storageKey&&(s.consoleLog("Updating Preference for ",this.storageKey,"from",n.getItem(this.storageKey,this.defaultState),"to",this.currentState),"pdfViewer"===this.storageKey&&(n.getWithTTL("ownership-upgrade")&&!1===this.currentState&&(s.messageToMain({main_op:"analytics",analytics:[[t.USE_ACROBAT_VIEWER_DISABLED_DEFAULT_OWNERSHIP_EXPERIMENT,{SOURCE:"OptionsPage",EXPERIMENT:n.getItem("experiment-ownership")}],[t.USE_ACROBAT_VIEWER_DISABLED_DEFAULT_OWNERSHIP,{SOURCE:"OptionsPage"}]]}),n.removeItem("ownership-upgrade"),n.removeItem("defaultOwnerShipExperiment")),a.setViewerState(!0===this.currentState?"enabled":"disabled"),ge.reloadRequiredForPreference=!0,this.publishDVStatusUpdate("gmail"),this.publishDVStatusUpdate("gdrive")),"acrobat-touch-points-in-other-surfaces"!==this.storageKey&&"acrobat-gsuite-touch-points"!==this.storageKey||(ge.reloadRequiredForPreference=!0,this.sendAcrobatTouchPointsAlert(this.currentState),this.syncOldTouchPointSettingToIndividual(String(this.currentState))),"acrobat-touch-point-in-embedded-pdf"===this.storageKey&&(ge.reloadRequiredForPreference=!0),"express-touch-points"==this.storageKey&&(ge.reloadRequiredForPreference=!0,chrome.runtime.sendMessage({main_op:"toggle-express-touch-points",allowed:this.currentState})),n.setItem(this.storageKey,String(this.currentState)),"appLocale"!==this.storageKey&&"egaf"!==this.storageKey||setTimeout(()=>{chrome.runtime.sendMessage({main_op:"toggle-add-webpage-to-project-context-menu"})},1e3)),this.hasUpdated=!1,this.defaultState=this.currentState)}sendAcrobatTouchPointsAlert(e){let t;t=e?"acrobatTouchPointsEnabled":"acrobatTouchPointsDisabled",chrome.tabs.query({url:["https://mail.google.com/*","https://drive.google.com/*","https://outlook.office365.com/*","https://outlook.office.com/*","https://outlook.live.com/*"]},function(e){e?.forEach(function(e){chrome.tabs.sendMessage(e.id,{content_op:t})})})}publishDVStatusUpdate=e=>{chrome.runtime?.sendMessage({main_op:"changeDefaultViewershipForSurface",surfaceId:e,isDefault:this.currentState,source:"extensionPreferencePage"})};syncOldTouchPointSettingToIndividual(e){["acrobat-touch-point-in-gmail","acrobat-touch-point-in-gdrive","acrobat-touch-point-in-outlook","acrobat-touch-point-in-linkedin","acrobat-touch-point-in-google-docs"].forEach(t=>{n.setItem(t,e)});n.setItem("show-acrobat-shortcuts-master-switch",e)}}class Se extends fe{constructor(e,t,s,a,i,o){super(e,t,s,a),this.defaultState=function(e,t=!1){const s=n.getItem(e);return s&&""!==s?"true"===s:t}(this.storageKey,s),this.currentState=this.defaultState,this.analyticsId={enabled:i,disabled:o}}onToggleChange(e){const t=$(e.currentTarget);this.currentState=!t.hasClass("checked"),this.hasUpdated=!this.hasUpdated,t.toggleClass("checked"),this.savePreferencesButton&&this.currentState===this.defaultState?this.savePreferencesButton.setDisabled(this.titleId):this.savePreferencesButton.setEnabled(this.titleId),$e.checkAndRemoveIfHighlightedSettingChanged(t[0])}RenderDisabledInputItem(){const e=$("<span/>"),t=$("<button/>",{class:"option-toggle-disabled"});return e.append(t),e}RenderInputItem(){const e=$("<span/>"),t=$("<button/>",{class:"option-toggle"});return t.click(e=>this.onToggleChange(e)),this.currentState&&t.addClass("checked"),e.append(t),e}GetAnalytics(){return this.currentState?this.analyticsId.enabled:this.analyticsId.disabled}SavePreferences(){return super.SavePreferences(),this.GetAnalytics()}}class Ie extends fe{constructor(e,t,s,a,i,o,r){super(e,t,a,i),this.valuesMap=s,this.onSavePreferences=o,r&&!n.getItem(i)&&n.setItem(i,String(a))}onSelectionChange(e){this.currentState=$(e.currentTarget).val(),this.currentState===this.defaultState?(this.hasUpdated=!1,this.savePreferencesButton&&this.savePreferencesButton.setDisabled(this.titleId)):(this.hasUpdated=!0,this.savePreferencesButton&&this.savePreferencesButton.setEnabled(this.titleId)),$e.checkAndRemoveIfHighlightedSettingChanged(e.currentTarget)}RenderInputItem(){const e=$("<span/>"),t=$("<select/>",{class:"option-select"});for(const e in this.valuesMap){const n=$("<option/>",{value:e,text:this.valuesMap[e]});t.append(n)}return t.change(e=>this.onSelectionChange(e)),this.currentState&&t.val(this.currentState),e.append(t),e}SavePreferences(){const e=this.defaultState;super.SavePreferences(),this.onSavePreferences&&this.onSavePreferences(this.currentState,e)}}class Ee extends Se{constructor(){let e="false"===n.getItem("ANALYTICS_OPT_IN_ADMIN")?g:u;super(h,e,!0,"logAnalytics",t.OPTIONS_ENABLED_ANALYTICS,t.OPTIONS_DISABLED_ANALYTICS),this.learnMoreLink=m,this.learnMoreTitle=f}Render(){const e=$("<div/>",{class:"option"}),a=$("<label/>",{class:"label",for:this.titleId}),i=$("<span/>",{class:"label-title",text:s.getTranslation(this.titleId),id:this.titleId}),o=$("<span/>",{class:"label-description",text:s.getTranslation(this.descriptionId)+" ",id:this.descriptionId}),r=$("<a/>",{class:"learn-more",href:s.getTranslation(this.learnMoreLink),text:s.getTranslation(this.learnMoreTitle),target:"_blank"});let c;return r.click(function(){s.messageToMain({main_op:"analytics",analytics:[[t.OPTIONS_ABOUT_ADOBE_ACROBAT_CLICKED]]})}),a.append(i),a.append(o),e.append(a),"false"===n.getItem("ANALYTICS_OPT_IN_ADMIN")?c=this.RenderDisabledInputItem():(c=this.RenderInputItem(),o.append(r)),e.append(c),e}SavePreferences(){if(this.hasUpdated)return this.hasUpdated=!1,this.defaultState=this.currentState,this.GetAnalytics()}}class Te extends Se{constructor(e,t,n,s,a,i){super(e,t,n,s,a,i)}Render(){return $("<div/>",{class:"ai-contextual-menu-toggle"}).append(super.Render())}}class _e extends Se{Render(){return $("<div/>",{class:"whats-new-auto-open-toggle"}).append(super.Render())}}class be extends fe{constructor(e,t,s){super(e,t,[],s),this.currentState=n.getItem(this.storageKey)||[]}RenderInputItem(){const e=$("<div/>",{class:"domain-container"}),t=this.renderTags(this.currentState);return $("<button/>",{id:"show-more-btn",text:"Show all"}).click(()=>{}),e.append(t),e}renderTags(e){const t=$("<div/>",{class:"tag-list",id:"tag-list"});for(let n of e){const e=$("<div/>",{class:"tag"});e.html(`${n} <span class="close-btn">×</span>`),t.append(e)}return t.on("click",".close-btn",e=>{const t=e.currentTarget.parentElement,n=t.textContent.trim();this.removeDomain(n.slice(0,-2)),t.remove()}),t}Render(){if(this.currentState?.length)return super.Render("domain-option")}removeDomain(e){this.currentState=this.currentState.filter(t=>t!==e),this.hasUpdated=!0,this.savePreferencesButton?.setEnabled(this.titleId)}SavePreferences(){this.hasUpdated&&(this.storageKey&&(s.consoleLog("Updating domains for",this.storageKey,"to",this.currentState),n.setItem(this.storageKey,this.currentState)),this.hasUpdated=!1,this.defaultState=this.currentState)}}class Pe extends fe{constructor(e,t){super(e,t,null,null)}onButtonClick(n){chrome.tabs.create({url:o,active:!0}),chrome.extension.isAllowedFileSchemeAccess().then(n=>{e.event(t.LOCAL_FILE_OPTIONS_CLICKED,{STATE:n?"Disable":"Enable"})})}RenderInputItem(){const e=$("<span/>"),t=$("<button/>",{class:"option-localfile"}),n=$("<span/>",{class:"option-localfile-text"});return chrome.extension.isAllowedFileSchemeAccess().then(e=>{n.text(s.getTranslation(e?"Disable":"Enable")),t.append(n),t.append($("<img>",{class:"option-localfile-icon"}).attr("src","../images/SDC_LinkOut_13_N.svg"))}),t.click(e=>this.onButtonClick(e)),e.append(t),e}SavePreferences(){}}class ve extends fe{constructor(e,t){super(e,t,null,null)}handleClick(){s.messageToMain({main_op:"analytics",analytics:[t.TREFOIL_HTML_PREFERENCES_CLICK]}),s.messageToMain({main_op:"showConversionSettingsDialog"})}RenderInputItem(){const e=$("<span/>"),t=$("<button/>",{class:"option-webpage-conversion"}),n=$("<span/>",{class:"option-webpage-conversion-text"});return n.text(s.getTranslation("editMegaVerbText")),t.append(n),t.click(this.handleClick),e.append(t),e}}class Oe extends fe{constructor(e,t,n,s){super(e),this.optionClassOverride=s,this.contentTextId=t,this.contentImagePath=n}Render(){const e=$("<div/>",{class:"option "+this.optionClassOverride}),t=$("<label/>",{class:"label",for:this.titleId}),n=$("<span/>",{class:"label-title",id:this.titleId});n.append(document.createTextNode(s.getTranslation(this.titleId)||this.titleId),$("<span/>",{text:"Beta",class:"beta-label"}));const a=$("<span/>",{class:"label-description",text:s.getTranslation(this.descriptionId)||this.descriptionId,id:this.descriptionId}),i=$("<div/>",{class:"preference-item-banner-content-wrapper"}),o=$("<div/>",{class:"banner-content-text-wrapper"}),r=$("<span/>",{class:"banner-content-text",text:s.getTranslation(this.contentTextId)||this.contentTextId});if(o.append(r),i.append(o),this.contentImagePath){const e=$("<div/>",{class:"banner-content-image-wrapper"}),t=$("<img>",{class:"banner-content-image"}).attr("src",this.contentImagePath);e.append(t),i.append(e)}return t.append(n),t.append(a),e.append(t),e.append(i),e}}class Ae extends fe{constructor(e,t){super(),this.optionClassOverride=e,this.contentImagePath=t}Render(){const e=$("<div/>",{class:`${this.optionClassOverride}`}),t=$("<div/>",{class:`option ${this.optionClassOverride}`}).append($("<img>",{class:"banner-image",src:this.contentImagePath,id:"aiMarkerTouchpointBanner"}));return e.append(t),e}}function we(e){return e.version>13}function Ne(e){return 13==e.version}function De(){const e=n.getItem("fteDenied")||"0",t="false"===n.getItem("pdfViewer");return SETTINGS.VIEWER_SHOW_OPEN_IN_ACRO&&(10===parseInt(e)||t)}function Re(e){if(e&&e.settings){for(const t in e.settings)SETTINGS[t]=e.settings[t];(function(e){return null===e.locale})(e)&&(SETTINGS.FRICTIONLESS_ENABLED=!1)}}function Le(){null==ge&&(ge=new me);const e=$("#toggles");$("#progress").remove(),e.empty(),he.forEach(t=>{t.AttachEventHandler(ge);const n=t.Render();e.append(n)})}async function Ce(e){try{const t=await chrome.runtime.sendMessage({main_op:"getFloodgateMeta",flag:e}),n=JSON.parse(t||"{}");return{isEnLocalEnabled:n.enLocaleEnabled||!1,isNonEnLocalEnabled:n.nonEnLocaleEnabled||!1}}catch(e){return{isEnLocalEnabled:!1,isNonEnLocalEnabled:!1}}}async function xe(e){he=[],ue={};const o=new Ee,r=new _e(E,T,!0,"whatsNewAutoOpen",t.OPTIONS_ENABLE_WHATS_NEW_AUTO_OPEN,t.OPTIONS_DISABLE_WHATS_NEW_AUTO_OPEN),l=new Se(S,I,!0,"always-show-pdftools",t.FRICTIONLESS_AUTO_SUGGESTION_ENABLED,t.FRICTIONLESS_AUTO_SUGGESTION_DISABLED),p=new Te(ie,oe,!0,"aiMarkers",t.OPTIONS_ENABLE_AI_MARKERS,t.OPTIONS_DISABLE_AI_MARKERS),d=new Se(_,b,!1,"pdfViewer",t.USE_ACROBAT_IN_CHROME_ENABLED,t.USE_ACROBAT_IN_CHROME_DISABLED),h=new Se(P,v,!0,"ViewResultsPref",t.TREFOIL_HTML_OPENPDF_PREF_ON,t.TREFOIL_HTML_OPENPDF_PREF_OFF),u=new Se(O,A,!0,"always-show-pdf-menu",t.OPTIONS_ENABLED_OPEN_IN_ACROBAT,t.OPTIONS_DISABLED_OPEN_IN_ACROBAT),g=new Se(D,R,!0,"egaf",t.OPTIONS_ENABLE_GENAI_FEATURES,t.OPTIONS_DISABLE_GENAI_FEATURES),m=new Se(L,C,!0,"autoSum",t.OPTIONS_ENABLE_GENAI_AUTO_SUMMARIZE,t.OPTIONS_DISABLE_GENAI_AUTO_SUMMARIZE),f=new Se(x,B,!1,"bypassGenAIWebpageEligibility",void 0,void 0),y=new Pe(re,ce),M=new ve(w,N);we(e)?(he.push(h),SETTINGS.VIEWER_ENABLED&&SETTINGS.VIEWER_ENABLED_FOR_ACROBAT?(he.push(d),De()&&he.push(u)):he.push(u)):Ne(e)?await async function(){const e=await async function(){return!(s.isEdge()&&await a.isMimeHandlerAvailable()&&n.getItem("openInAcrobatEnable")&&"admin"!==n.getItem("installSource"))}();SETTINGS.VIEWER_ENABLED?(he.push(d),De()&&e&&he.push(u)):e&&he.push(u)}():SETTINGS.VIEWER_ENABLED&&he.push(d);const F=[],ge=["dc-cv-gmail-acrobat-touch-point","dc-cv-gdrive-prompt","dc-cv-embedded-pdf-touch-point","dc-cv-outlook-pdf-touch-point","dc-cv-linkedin-pdf-touch-point","dc-cv-linkedin-chat-pdf-touch-point"];for(const ct of ge)F.push(chrome.runtime.sendMessage({main_op:"getFloodgateFlag",flag:ct}));const[me,Re,Le,xe,Be,ye]=await Promise.all(F),Me=me||Re||xe||Be||ye,$e="en-US"===n.getItem("locale")||"en-GB"===n.getItem("locale");if(Me){let lt=Y,pt=Z;if(xe&&(lt=J,pt=te),Be||ye){let ht=!1,ut=!1;if(Be){const gt=await Ce("dc-cv-linkedin-pdf-touch-point");ht||=gt.isEnLocalEnabled,ut||=gt.isNonEnLocalEnabled}if(ye){const mt=await Ce("dc-cv-linkedin-chat-pdf-touch-point");ht||=mt.isEnLocalEnabled,ut||=mt.isNonEnLocalEnabled}($e&&ht||!$e&&ut)&&(lt=J,pt=ne)}$e&&(pt=de);const dt=new Se(lt,pt,!0,"acrobat-touch-points-in-other-surfaces",t.OPTIONS_ACROBAT_TOUCH_POINT_ENABLED,t.OPTIONS_ACROBAT_TOUCH_POINT_DISABLED);he.push(dt)}if(Le){const ft=new Se(Q,ee,!0,"acrobat-touch-point-in-embedded-pdf",t.OPTIONS_ACROBAT_EMBEDDED_TOUCH_POINT_ENABLED,t.OPTIONS_ACROBAT_EMBEDDED_TOUCH_POINT_DISABLED);ft.Render=function(){return fe.prototype.Render.call(this,"embedded-pdf-touchpoint-section")},he.push(ft)}const Fe=await chrome.runtime.sendMessage({main_op:"getFloodgateFlag",flag:"dc-cv-genai-disable-pref"}),ke="true"===n.getItem("genAIEligible");ke&&Fe&&(he.push(g),n.getItem("autoSummaryEligible")&&he.push(m));const Ue=await chrome.runtime.sendMessage({main_op:"getWhatsNewFlag"}),Ge=(n.getItem("whatsNewState")||{}).disableAutoOpenByAdmin;Ue&&!Ge&&he.push(r),SETTINGS.FRICTIONLESS_ENABLED&&he.push(l);const He=await chrome.runtime.sendMessage({main_op:"getFloodgateFlag",flag:"dc-cv-local-file-fte"}),Ke=await chrome.extension.isAllowedFileSchemeAccess();!He||s.isEdge()||Ke||he.push(y);const Ve=s.getTranslation(G),We=s.getTranslation(H),qe=s.getTranslation(K);const je=new Ie(k,U,{auto:Ve,dark:We,light:qe},"auto","theme",function(e,n){s.messageToMain({main_op:"themeChange",analytics:[[t.OPTIONS_APPEARENCE_THEME_CHANGED,{OLDTHEME:n,NEWTHEME:e}]]})},!0);if(he.push(je),!0===n.getItem("isSaveLocationPrefEnabled")){const St=s.getTranslation(q),It=s.getTranslation(j),Et=s.getTranslation(z);function Tt(e,a){s.messageToMain({main_op:"analytics",analytics:[[t.SAVE_LOCATION_PREFERENCE_CHANGED,{OLDPREF:a,NEWPREF:e}]]}),n.setItem("selectedSaveLocationPreference",!0)}const _t=new Ie(V,W,{ask:St,cloud:It,local:Et},"ask","saveLocation",Tt,!0);he.push(_t)}const ze=new Ie(X,null,i,n.getItem("viewer-locale")||s.getFrictionlessLocale(chrome.i18n.getMessage("@@ui_locale")),"appLocale",async()=>{},!0);he.push(ze);const Xe=[chrome.runtime.sendMessage({main_op:"express-init"}),chrome.runtime.sendMessage({main_op:"whatsapp-express-init"}),chrome.runtime.sendMessage({main_op:"gmail-express-init"}),chrome.runtime.sendMessage({main_op:"google-image-preview-express-init"}),chrome.runtime.sendMessage({main_op:"gdrive-express-init"}),chrome.runtime.sendMessage({main_op:"facebook-express-init"}),chrome.runtime.sendMessage({main_op:"chatgpt-express-init"}),chrome.runtime.sendMessage({main_op:"outlook-express-init"})],[Ye,Ze,Je,Qe,et,tt,nt,st]=await Promise.all(Xe);if(Ye.shouldEnableExpressTouchpointsPreference||Ze.enableExpressOptionsPagePreference||Je.enableExpressOptionsPagePreference||Qe.enableExpressOptionsPagePreference||et.enableExpressOptionsPagePreference||tt.enableExpressOptionsPagePreference||nt.enableExpressOptionsPagePreference||st.enableExpressOptionsPagePreference){const bt=new Se(se,ae,!0,"express-touch-points",t.OPTIONS_EXPRESS_TOUCHPOINT_ENABLED,t.OPTIONS_EXPRESS_TOUCHPOINT_DISABLED);bt.Render=function(){return fe.prototype.Render.call(this,"express-touchpoints-section")},he.push(bt)}he.push(o),ue.analytics_on=o,function(e){function t(e){s.messageToMain({panel_op:"common",type:"update_env",env:e})}const a=new Ie("Development Environment","Select the target environment for the extension.",{prod:"Production",stage:"Stage",test:"Test",dev:"Dev","local-dev":"Local Dev"},e.environment||"prod","env",t),i=new Ie("GenAI Cluster","Select the target cluster for the extension.",{develop:"Develop",beta:"Beta",release:"Release"},c(),"cluster"),o=new Ie("Development Environment","Select the target environment for the extension.",{prod:"Production",stage:"Stage"},e.environment||"prod","env",t),r=we(e)?"acrobat":Ne(e)?"reader":"no-app",l=new Ie("Connected Application","Select the target connected application for the extension functionalities. This settings only mock the views, the functionality may be broken.",{acrobat:"Acrobat",reader:"Reader","no-app":"No App"},r||"acrobat"),p="true"===n.getItem("adobeInternal");SETTINGS.DEBUG_MODE?(he.push(a,i,l),ue.environment=a,ue.product=l):p&&(he.push(o),ue.environment=o)}(e),we(e)&&he.push(M);const at=new Oe(le,pe,"../images/ai_assistant_web_page.svg","ai-assistant-banner-header-wrapper"),it=new Se("genAIFabPreferenceTitle","genAIFabPreferenceDescription",!1,"enableGenAIFab",t.OPTIONS_ENABLE_GEN_AI_FAB,t.OPTIONS_DISABLE_GEN_AI_FAB),ot=(new class extends fe{constructor(e,t,n,a){super(e,t,null,null),this.url=n,this.buttonText=s.getTranslation(a)}onButtonClick(e){chrome.tabs.create({url:this.url,active:!0})}RenderInputItem(){const e=$("<span/>"),t=$("<button/>",{class:"option-localfile"}),n=$("<span/>",{class:"option-localfile-text"});return n.text(this.buttonText),t.append(n),t.append($("<img>",{class:"option-localfile-icon"}).attr("src","../images/SDC_LinkOut_13_N.svg")),t.click(e=>this.onButtonClick(e)),e.append(t),e}SavePreferences(){}}("sidepanelLocationPreferenceTitle","sidepanelLocationPreferenceDescription","chrome://settings/appearance#:~:text=Side%20panel%20position","sidepanelLocationPreferenceButtonText"),new be("domainPreferenceTitle","","hideFabDomainList"));if(n.getItem("sidePanelRegistered")){he.push(at),it.Render=function(){return fe.prototype.Render.call(this,"fab-preference-toggle")},he.push(it),he.push(ot);"true"===n.getItem("adobeInternal")&&he.push(f)}const rt=await chrome.runtime.sendMessage({main_op:"getFloodgateFlag",flag:"dc-cv-genai-markers"});if(ke&&Fe&&rt){const Pt=new Ae("ai-contextual-menu-section","../images/SummarizeBanner.svg");he.push(Pt),he.push(p)}}function Be(e){s.messageToMain({main_op:"fetch-preferences"},e)}function ye(e){const t=he.filter(t=>t.titleId===e);return t.length>0?t[0]:null}function Me(e,t,n){if(SETTINGS.TEST_MODE)return;const s=e.toggleId,a=ye(s),i=e.requestType;let o,c;switch(i){case r.OPTIONS_UPDATE_TOGGLE:a?(a.currentState=e.toggleVal,a.savePreferencesButton.SavePreferences(),o=a.currentState):c="Toggle not visible.",n&&n({requestType:i,toggleId:s,response:o,error:c});case r.OPTIONS_HIGHLIGHT_SECTION:e.sectionClassNames&&function(e){$e.remove();const t=[];if(e.forEach(e=>{if(!e)return;$(`.${e}`).each(function(){t.push($(this))})}),0===t.length)return;let n=1/0,s=1/0,a=-1/0,i=-1/0;t.forEach(e=>{const t=e.offset(),o=e.outerWidth(),r=e.outerHeight();n=Math.min(n,t.top),s=Math.min(s,t.left),a=Math.max(a,t.top+r),i=Math.max(i,t.left+o)});const o=0,r=38;n-=o,s-=r,a+=o,i+=r;const c={top:n,left:s,width:i-s,height:a-n};$e.create(c,e);const l=n+(a-n)/2,p=$("<div/>").css({position:"absolute",top:l+"px",left:"0px",height:"1px",width:"1px"});$("body").append(p),p[0].scrollIntoView({behavior:"smooth",block:"center"}),p.remove()}(e.sectionClassNames),n&&n({success:!0})}}let $e=new l;$(document).ready(function(){$e.remove(),s.translateElements(".translate"),Be(async e=>{Re(e),await xe(e),Le(),s.addMainListener(Me),function(){if(!SETTINGS.TEST_MODE)return;const e="check_toggle_state",t="update_toggle_state";chrome.runtime.onMessage.addListener(function(n,s,a){if(!n.panel_op||"test"!==n.panel_op)return;const i=n.test_extension,o=n.toggleId,r=ye(o);let c,l;switch(i){case e:r?c=r.currentState:l="Toggle not visible.";break;case t:r?(r.currentState=n.toggleVal,r.hasUpdated=!0,r.savePreferencesButton.SavePreferences(),c=r.currentState):l="Toggle not visible.";break;default:l="Invalid request type."}a({requestType:i,toggleId:o,response:c,error:l})})}();await a.isMimeHandlerAvailable()||chrome.runtime.sendMessage({main_op:"updateLoadedTabsInfo"})})}),$(document).on("visibilitychange",()=>{document.hidden&&$e.remove()})});