/*************************************************************************
* 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{LOCAL_FILE_PERMISSION_URL as e,POPUP_CONTEXT as n}from"../../../common/constant";import{dcLocalStorage as t}from"../../../common/local-storage";import{privateApi as r}from"../content-privateApi";import{largeBlobStorage as o}from"../../../common/large-blob-storage";export function getTranslation(e,n=""){if(!e)return n;try{return chrome.i18n.getMessage(e)||n||e}catch(t){return n||e}}export function isDebugMode(){return SETTINGS.DEBUG_MODE}export function onSaveEnvironmentPreference(e,n,t){chrome.runtime.sendMessage({main_op:"update_env",env:n})}export async function getEnvironmentPreference(){return await chrome.runtime.sendMessage({main_op:"getEnv"})||"prod"}export const getGenAIServiceVariant=()=>{const e=t.getItem("cluster");return e||("true"===t.getItem("adobeInternal")?"beta":"release")};const a=async()=>await chrome.runtime.sendMessage({main_op:"getVersion"})||-1;async function i(){return await a()>13}async function s(){return 13==await a()}export async function getConnectedApp(){return await i()?"acrobat":await s()?"reader":"no-app"}async function c(){if(SETTINGS.VIEWER_ENABLED)return!0;return await async function(){if(await chrome.runtime.sendMessage({main_op:"isEdge"})&&await r.isMimeHandlerAvailable()&&t.getItem("openInAcrobatEnable")&&"admin"!==t.getItem("installSource"))return!1;return!0}()}export async function isOpenPdfsInAcrobatEnabled(){return i()?!(!SETTINGS.VIEWER_ENABLED||!SETTINGS.VIEWER_ENABLED_FOR_ACROBAT):s(request)?await c():function(){if(SETTINGS.VIEWER_ENABLED)return!0}()}export async function showTurnOffLocalFilePermissionSetting(){const e=await chrome.extension.isAllowedFileSchemeAccess();return!(await chrome.runtime.sendMessage({main_op:"isEdge"})||!e)}export async function showTurnOnLocalFilePermissionSetting(){const e=await chrome.extension.isAllowedFileSchemeAccess();return!await chrome.runtime.sendMessage({main_op:"isEdge"})&&!e}export function onSaveThemePreference(e,n,t){window.dispatchEvent(new CustomEvent("themeChange",{detail:{theme:n}})),chrome.runtime.sendMessage({main_op:"themeChange",theme:n}),e.sendAnalytics("OPTIONS_APPEARENCE_THEME_CHANGED",{OLDTHEME:t,NEWTHEME:n})}export async function getLocalePreference(){const e=await chrome.runtime.sendMessage({main_op:"getFrictionlessLocale"});return t.getItem("viewer-locale")||e}export async function onSaveSaveLocationPreference(e,n,r){t.setItem("selectedSaveLocationPreference",!0),e.sendAnalytics("SAVE_LOCATION_PREFERENCE_CHANGED",{OLDPREF:r,NEWPREF:n})}export async function checkShowWhatsNewAutoOpenPreference(){const e=await chrome.runtime.sendMessage({main_op:"getWhatsNewFlag"}),n=(t.getItem("whatsNewState")||{}).disableAutoOpenByAdmin;return!(!e||n)}export function checkAutoOpenConvertedPDFPreference(){return i()}export function showWebpageConversionSettings(){return i()}export async function checkShowFeatureGuidanceFeatureFlag(){return await chrome.runtime.sendMessage({main_op:"getFloodgateFlag",flag:"dc-cv-feature-guidance"})}export async function checkShowExpressTouchpointsPreference(){const e=[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"})],[n,t,r,o,a,i,s,c]=await Promise.all(e);return n.shouldEnableExpressTouchpointsPreference||t.enableExpressOptionsPagePreference||r.enableExpressOptionsPagePreference||o.enableExpressOptionsPagePreference||a.enableExpressOptionsPagePreference||i.enableExpressOptionsPagePreference||s.enableExpressOptionsPagePreference||c.enableExpressOptionsPagePreference}export async function openLocalFileSettingsPrompt(t){const[r]=await chrome.tabs.query({active:!0,currentWindow:!0}),o=await chrome.windows.get(r.windowId),{height:a,width:i,left:s,top:c}=function(e){const n=Math.min(Math.round(.8*e.height),900),t=Math.min(Math.round(.9*e.width),1550);return{height:n,width:t,top:Math.round(.5*(e.height-n)+e.top),left:Math.round(.5*(e.width-t)+e.left)}}(o),u=await chrome.extension.isAllowedFileSchemeAccess();let h=e;u||(h=function(e,n={}){const t=e.split("#"),r=t[0],o=t[1],a=new URL(r);return Object.entries(n).forEach(([e,n])=>{a.searchParams.set(e,n)}),o?`${a.toString()}#${o}`:a.toString()}(e,{context:n.LOCAL_FILE_COACHMARK,autoDismiss:!0})),chrome.windows.create({height:a,width:i,left:s,top:c,focused:!0,type:"normal",url:h},()=>{chrome.runtime.lastError?reject(chrome.runtime.lastError):(t.sendAnalytics("LOCAL_FILE_OPTIONS_CLICKED",{STATE:u?"Disable":"Enable"}),u||chrome.action.openPopup().catch(e=>console.error(e)))})}export const showConversionSettingsDialog=e=>{chrome.runtime.sendMessage({main_op:"showConversionSettingsDialog"}),e.sendAnalytics("TREFOIL_HTML_PREFERENCES_CLICK")};export function syncMasterSwitchToOldTouchPointSetting(e,n){if("indeterminate"===n)return;const r=!0===n||"true"===n?"true":"false";t.setItem("acrobat-touch-points-in-other-surfaces",r)}export function onAcrobatDefaultViewershipPreferenceChange(e,n,t,r){((e,n)=>{chrome.runtime?.sendMessage({main_op:"changeDefaultViewershipForSurface",surfaceId:e,isDefault:n,source:"extensionPreferencePage",pageSource:"new_preferences_page"})})(r,!0===n||"true"===n)}export async function onPDFViewerPreferenceChange(e,n,o){const a=!0===n||"true"===n;let i;a?(t.setItem("viewer-enabled-source","ownership-consent"),i="true"):i="false";await chrome.runtime.sendMessage({main_op:"isEdge"})&&chrome.runtime.sendMessage({main_op:"pdfViewerChanged",value:i}),t.getWithTTL("ownership-upgrade")&&!1===a&&(e.sendAnalytics("USE_ACROBAT_VIEWER_DISABLED_DEFAULT_OWNERSHIP_EXPERIMENT",{SOURCE:"OptionsPage",EXPERIMENT:t.getItem("experiment-ownership")}),e.sendAnalytics("USE_ACROBAT_VIEWER_DISABLED_DEFAULT_OWNERSHIP",{SOURCE:"OptionsPage"}),t.removeItem("ownership-upgrade"),t.removeItem("defaultOwnerShipExperiment")),r.setViewerState(!0===a?"enabled":"disabled")}export const onAdobeExpressPreferenceChange=(e,n,t)=>{const r=!0===n||"true"===n;chrome.runtime.sendMessage({main_op:"toggle-express-touch-points",allowed:r})};export const onLocaleChangePreference=(e,n,t)=>{o.removeItem("anonGenAISSRHtml"),setTimeout(()=>{chrome.runtime.sendMessage({main_op:"toggle-add-webpage-to-project-context-menu"})},1e3)};export const onGenAIFeaturesPreferenceChange=(e,n,t)=>{setTimeout(()=>{chrome.runtime.sendMessage({main_op:"toggle-add-webpage-to-project-context-menu"})},1e3)};export async function onPreferencesPageLoad(){await r.isMimeHandlerAvailable()||chrome.runtime.sendMessage({main_op:"updateLoadedTabsInfo"})}export function onAcrobatShortcutPreferenceChange(e,n,t,r,...o){!function(e,n,t){let r;r=e?"acrobatTouchPointsEnabled":"acrobatTouchPointsDisabled",chrome.tabs.query({url:t},function(e){e?.forEach(function(e){chrome.tabs.sendMessage(e.id,{content_op:r,acrobatShortcutSurfaceId:n})})})}(!0===n||"true"===n,r,o)}export function isGoogleDriveShortcutDisabled(){return"false"!==t.getItem("gdrive-pdf-default-viewership")}export function isGmailShortcutDisabled(){return"false"!==t.getItem("gmail-pdf-default-viewership")}export function openDefaultViewershipSettings(){try{const e=new CustomEvent("navigateToPreference",{detail:{tabId:"general",accordionId:"acrobat-integrations-default-viewership-group"}});window.dispatchEvent(e)}catch(e){console.error("Error navigating to default viewership settings:",e)}}export const PreferenceUtils={isDebugMode:isDebugMode,onSaveEnvironmentPreference:onSaveEnvironmentPreference,getEnvironmentPreference:getEnvironmentPreference,getGenAIServiceVariant:getGenAIServiceVariant,getConnectedApp:getConnectedApp,isOpenPdfsInAcrobatEnabled:isOpenPdfsInAcrobatEnabled,showTurnOffLocalFilePermissionSetting:showTurnOffLocalFilePermissionSetting,showTurnOnLocalFilePermissionSetting:showTurnOnLocalFilePermissionSetting,onSaveThemePreference:onSaveThemePreference,getLocalePreference:getLocalePreference,onSaveSaveLocationPreference:onSaveSaveLocationPreference,checkShowWhatsNewAutoOpenPreference:checkShowWhatsNewAutoOpenPreference,checkAutoOpenConvertedPDFPreference:checkAutoOpenConvertedPDFPreference,showWebpageConversionSettings:showWebpageConversionSettings,checkShowFeatureGuidanceFeatureFlag:checkShowFeatureGuidanceFeatureFlag,checkShowExpressTouchpointsPreference:checkShowExpressTouchpointsPreference,openLocalFileSettingsPrompt:openLocalFileSettingsPrompt,showConversionSettingsDialog:showConversionSettingsDialog,onPDFViewerPreferenceChange:onPDFViewerPreferenceChange,onAdobeExpressPreferenceChange:onAdobeExpressPreferenceChange,onLocaleChangePreference:onLocaleChangePreference,onGenAIFeaturesPreferenceChange:onGenAIFeaturesPreferenceChange,onAcrobatShortcutPreferenceChange:onAcrobatShortcutPreferenceChange,onPreferencesPageLoad:onPreferencesPageLoad,onAcrobatDefaultViewershipPreferenceChange:onAcrobatDefaultViewershipPreferenceChange,isGoogleDriveShortcutDisabled:isGoogleDriveShortcutDisabled,isGmailShortcutDisabled:isGmailShortcutDisabled,openDefaultViewershipSettings:openDefaultViewershipSettings,syncMasterSwitchToOldTouchPointSetting:syncMasterSwitchToOldTouchPointSetting};