/*************************************************************************
* 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.
**************************************************************************/
class OutlookExpressFte{id="OutlookExpressFte";timeout=3e3;maxFteCount=3;fteGapBetweenIterations=6048e5;outlookExpressStateKey="outlookExpressState";outlookExpressInitialState={previewTouchpointUsed:!1,attachmentHoverMenuTouchpointUsed:!1,fte:{shown:0,lastShown:null}};rendered=!1;ONE_DAY_IN_MILLISECONDS=864e5;static OUTLOOK_DOMAINS=["outlook.office365.com","outlook.office.com","outlook.live.com"];constructor(){this.initPromise=this.init()}isEligible=async()=>{if(await this.initPromise,!this.config?.enableOutlookExpressFte)return!1;if(this.rendered)return!1;let t=await chrome.storage.local.get(this.outlookExpressStateKey);if(t?.outlookExpressState?t=t.outlookExpressState:(t=this.outlookExpressInitialState,chrome.storage.local.set({[this.outlookExpressStateKey]:t})),t.previewTouchpointUsed||t.attachmentHoverMenuTouchpointUsed)return!1;if(t.fte?.shown>=this.maxFteCount)return!1;if(t.fte?.lastShown&&t.fte?.lastShown+this.fteGapBetweenIterations>Date.now())return!1;return!!await this.getCtaElement()};_renderFte=t=>{"outlookAttachmentView"===this.touchpoint?(document.body.appendChild(t),this._positionFte(this.expressContextualFTE.getFteElement(),this.ctaButtonWrapper)):document.body.appendChild(t)};_positionFte=(t,e)=>{const o=e.getBoundingClientRect(),s=t.getElementsByClassName("ae1eed7c-express-contextual-fte")?.[0];s&&("outlookAttachmentView"===this.touchpoint?(s.style.top=o.top-s.offsetHeight/2+window.scrollY+3+"px",s.style.left=o.right+window.scrollX+"px",s.style.transform="translate(0%, 0%)"):(s.style.top=o.top+e.offsetHeight+"px",s.style.left=o.left+e.offsetWidth/2+"px",s.style.transform="translate(-50%, 0%)"))};render=async()=>{if(this.rendered)return;if(this.ctaButtonWrapper=await this.getCtaElement(),!this.ctaButtonWrapper)return;const t=this.ctaButtonWrapper?.getElementsByClassName("cc440d50ba-express-entrypoint-button")[0];t&&(this.rendered=!0,this.expressContextualFTE=new this.expressContextualFteClass({touchpoint:this.touchpoint,ctaButtonElement:this.ctaButtonWrapper,fteStrings:{fteTitle:this.config.fteStrings?.title||"Edit images with Adobe Express",fteDescription:this.config.fteStrings?.description||"Click to enhance your images with professional editing tools",fteCtaLabel:this.config.fteStrings?.ctaLabel||"Got it"},updateFteStateCallback:this.updateOutlookExpressState,positionFteCallback:this._positionFte,renderCallback:this._renderFte}),await this.expressContextualFTE.render())};getCtaElement=async()=>{const t=["express-outlook-native-viewer-entry-point","express-outlook-attachment-hover-menu-entry-point"];for(let e=0;e<10;e++){for(let e of t){const t=document.getElementById(e);if(t){if("express-outlook-attachment-hover-menu-entry-point"===e){this.touchpoint="outlookAttachmentView";const e=t.getBoundingClientRect();if(window.innerWidth-e.right<260||window.innerHeight-e.bottom<60)continue}else this.touchpoint="outlookNativeViewer";return t}}await new Promise(t=>setTimeout(t,100))}return null};updateOutlookExpressState=async()=>{let t=await chrome.storage.local.get(this.outlookExpressStateKey);t=t?.outlookExpressState?t.outlookExpressState:this.outlookExpressInitialState;let e={...this.outlookExpressInitialState,...t};e.fte||(e.fte={shown:0,lastShown:null}),e.fte.shown=(e.fte.shown||0)+1,e.fte.lastShown=Date.now(),chrome.storage.local.set({[this.outlookExpressStateKey]:e})};loadContentScripts=async()=>{const t=chrome.runtime.getURL("content_scripts/express/fte/express-contextual-fte.js");return Promise.all([import(t)]).then(t=>{this.expressContextualFteClass=t[0].default})};isOutlookDomain=()=>{const t=window.location.hostname;return OutlookExpressFte.OUTLOOK_DOMAINS.some(e=>t.includes(e))};init=async()=>{if(!this.isOutlookDomain())return this.isEligible=async()=>!1,void(this.render=async()=>{});const t=await chrome.runtime.sendMessage({main_op:"outlook-express-init"});this.config=t,await this.loadContentScripts()};remove=()=>{this.expressContextualFTE&&(this.expressContextualFTE.remove(),this.rendered=!1)}}