/*************************************************************************
* 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.
**************************************************************************/
(()=>{let t,e,o,n,r,s,c,a=!1,i=!1,l=!1;const u="outlook-acrobat-touch-point",d=()=>{const t=document.createElement("script");t.src=chrome.runtime.getURL("content_scripts/outlook/outlook-inject.js"),t.onload=function(){this.remove()},(document.head||document.documentElement).appendChild(t)},m=()=>{const e=o?.getElementFromParent(t?.config?.selectors?.title,document);return e&&e.innerText?e.innerText:""},h=async(n,s)=>{try{let c;if(n.startsWith("blob:"))c=(t=>{o?.sendAnalytics([["DCBrowserExt:Outlook:TouchPoint:BlobURL"]]);const e=o?.buildAcrobatPromotionSource("outlook_chrome","native_view");return chrome.runtime.getURL("viewer.html")+"?pdfurl="+encodeURIComponent(t)+"&acrobatPromotionSource="+e})(n);else{if(a)return void r?.showErrorToast();c=(e=>{const n=(t=>t&&t.includes("toolbar")?t.substring(0,t.indexOf("#toolbar=")):t)(e),r=new URL(n);r.searchParams.set("token",t.token);const s=o?.buildAcrobatPromotionSource("outlook_chrome","native_view");r.searchParams.set("acrobatPromotionSource",s);const c=r.toString();return o?.sendAnalytics([["DCBrowserExt:Outlook:TouchPoint:AttachmentURL"]]),chrome.runtime.getURL("viewer.html")+"?pdfurl="+encodeURIComponent(c)})(n)}const i=m();i&&(c+="&pdffilename="+encodeURIComponent(i)),window.open(c,"_blank"),chrome.runtime.sendMessage({main_op:"akamai-ping"}),o?.sendAnalytics("Enter"===s?.key?[["DCBrowserExt:Outlook:TouchPoint:EnterKeyDown"]]:" "===s?.key?[["DCBrowserExt:Outlook:TouchPoint:SpaceKeyDown"]]:[["DCBrowserExt:Outlook:TouchPoint:Clicked"]]),e?.acrobatTouchPointClicked("acrobat-outlook-fte-state")}catch(t){o?.sendErrorLog("OutlookTouchPoint","Failure in acrobatTouchPointEventHandler")}},p=e=>{const n=document.createElement("div"),r=o?.createAcrobatIconElement("acrobat-icon","browser/images/acrobat_dc_appicon_128.png"),s=(()=>{const e=document.createElement("span");return e.setAttribute("class","acrobat-text"),e.textContent=t?.config?.touchPointString||"Open in Acrobat",e})();return n.classList.add(u),n.setAttribute("data-is-focusable","true"),n.appendChild(r),n.appendChild(s),n.addEventListener("click",t=>h(e,t)),n.addEventListener("keydown",t=>{"Enter"!==t.key&&" "!==t.key||(t.preventDefault(),h(e,t))}),n},k=()=>{const e=document.getElementsByClassName(u);if(e.length>0){const t=e[0];s?.removeFteTooltip(),t?.remove()}t.lastTabUrl="",t.lastAttachmentURL="",t.lastFileName=""},b=()=>{try{if(i){const e=o?.getElementFromParent(t?.config?.selectors?.nativeViewer,document);if(e){const n=o?.getElementFromParent(t?.config?.selectors?.header,e);if(n){const r=o?.getElementFromParent(t?.config?.selectors?.url,e),s=m(),c=t?.lastAttachmentURL&&s===t?.lastFileName&&t?.token,a=r&&(t=>{const e=t.getAttribute("data");return"application/pdf"===t.getAttribute("type")&&e?.startsWith("blob:")})(r);if(c||a){((e,n)=>{try{const r=document.getElementsByClassName(u);if(r.length>0){const t=r[0];if(e.lastElementChild===t)return;return void e.append(t)}const s=p(n);e.append(s);const c=window.location.href;t?.lastTabUrl!==c&&(o?.sendAnalytics([["DCBrowserExt:Outlook:TouchPoint:Shown"]]),chrome.runtime.sendMessage({main_op:"outlook-touch-point-added"}),t.lastTabUrl=c)}catch(t){o?.sendErrorLog("OutlookTouchPoint","Failure in addAcrobatTouchPoint")}})(n,t?.lastAttachmentURL||r?.getAttribute("data")),t.lastFileName=s}else k()}else k()}else k()}}catch(t){o?.sendErrorLog("OutlookTouchPoint","Failure in processForDOMUpdate")}try{c?.processForOutlook()}catch(t){o?.sendErrorLog("OutlookTouchPoint","Failure in processForDOMUpdate for Express touchpoints: "+t)}},g=()=>{if(document?.body)try{const e={childList:!0,subtree:!0};n=new MutationObserver(function(){n.takeRecords(),chrome.runtime?.id?b():(n?.disconnect(),k(),t?.disconnectEventListeners())}),n.observe(document?.body,e)}catch(t){}else setTimeout(g,500)},E=()=>{chrome.runtime.onMessage.addListener(t=>{"add-fte-for-outlook-touch-point"===t?.type?s?.addFTE():"acrobatTouchPointsDisabled"===t?.content_op&&(t.acrobatShortcutSurfaceId&&"outlook"!==t.acrobatShortcutSurfaceId||(n?.disconnect(),k()))})};Promise.all([chrome.runtime.sendMessage({main_op:"outlook-init"}),chrome.runtime.sendMessage({main_op:"outlook-express-init"})]).then(async([n,u])=>{(n?.enableOutlookPDFTouchPoint||u?.enableOutlookNVExpressMenu)&&(d(),await(async()=>{[t,e,o,r,s,c]=await Promise.all([import(chrome.runtime.getURL("content_scripts/outlook/state.js")).then(t=>t.default),import(chrome.runtime.getURL("content_scripts/utils/fte-utils.js")),import(chrome.runtime.getURL("content_scripts/utils/util.js")),import(chrome.runtime.getURL("content_scripts/outlook/outlook-error-toast-service.js")),import(chrome.runtime.getURL("content_scripts/outlook/outlook-fte-service.js")),import(chrome.runtime.getURL("content_scripts/express/outlook/express-outlook-touchpoint-service.js")).then(t=>t.default)])})(),t.config=n,t.expressConfig=u,i=n?.enableOutlookPDFTouchPoint,l=u?.enableOutlookNVExpressMenu,i&&(o?.sendAnalyticsOncePerMonth("DCBrowserExt:Outlook:TouchPoint:Enabled"),k()),l&&c?.removeExpressTouchpoints(),E(),document.addEventListener("acrobat-outlook-token-intercept-response",e=>{e?.detail?.success?(a=!1,t&&(t.token=e?.detail?.data)):a=!0},{signal:t?.eventControllerSignal}),document.addEventListener("acrobat-outlook-attachment-intercept-response",e=>{if(e?.detail?.success)t?.lastAttachmentURL!==e?.detail?.responseUrl&&k(),t.token=e?.detail?.xToken,t.lastAttachmentURL=e?.detail?.responseUrl,t.lastFileName=e?.detail?.filename,b();else{const t=e?.detail?.error||"Unknown error",n=e?.detail?.status||"No status code",r=e?.detail?.responseUrl||"No URL";o?.sendErrorLog("OutlookTouchPoint",`Attachment API failed - Error: ${t}, Status: ${n}, URL: ${r}`)}},{signal:t?.eventControllerSignal}),r?.removeErrorToast(),o.addFontToDocument(t),g(),b())})})();