/*************************************************************************
* 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 GoogleImagePreviewExpressFte{id="GoogleImagePreviewExpressFte";timeout=3e3;maxFteCount=3;fteGapBetweenIterations=6048e5;googleImageExpressStateKey="googleImageExpressState";googleImageExpressInitialState={previewTouchpointUsed:!1,fte:{shown:0,lastShown:null}};rendered=!1;constructor(){this.initPromise=this.init(),this.ctaButton=null}isEligible=async()=>{if(await this.initPromise,this.rendered)return!1;if(!this.config?.enableGoogleImagePreviewExpressFte)return!1;let e=await chrome.storage.local.get(this.googleImageExpressStateKey);return e?.[this.googleImageExpressStateKey]?e=e[this.googleImageExpressStateKey]:(e=this.googleImageExpressInitialState,chrome.storage.local.set({[this.googleImageExpressStateKey]:e})),!e.previewTouchpointUsed&&(!(e.fte?.shown>=this.maxFteCount)&&(!(e.fte?.lastShown&&e.fte?.lastShown+this.fteGapBetweenIterations>Date.now())&&(this.ctaButton=await this.getCtaElement(),!!this.ctaButton)))};_renderFte=e=>{this.ctaButton?.appendChild(e)};_positionFte=(e,t)=>{const s=e.getElementsByClassName("ae1eed7c-express-contextual-fte")?.[0];s&&(s.style.position="absolute",s.style.left=(t.offsetWidth-224)/2+"px",s.style.top="90%")};render=async(e=!1)=>{if(this.rendered)return;if(!e){let e=await chrome.storage.local.get(this.googleImageExpressStateKey);if(e?.[this.googleImageExpressStateKey]?.previewTouchpointUsed)return}const t=e?30:10;this.ctaButton=await this.getCtaElement(t),this.ctaButton&&(this.rendered=!0,this.expressContextualFTE=new this.expressContextualFteClass({touchpoint:"googleImagePreview",ctaButtonElement:this.ctaButton,fteStrings:{fteTitle:this.config.fteStrings.title,fteDescription:this.config.fteStrings.description,fteCtaLabel:this.config.fteStrings.ctaLabel},updateFteStateCallback:()=>this.updateGoogleImagePreviewExpressState(e),renderCallback:this._renderFte,positionFteCallback:this._positionFte}),await this.expressContextualFTE.render())};getCtaElement=async(e=10)=>{for(let t=0;t<e;t++){const e=document.getElementById("google-image-preview-adobe-express-entry-point");if(e)return e;await new Promise(e=>setTimeout(e,100))}return null};updateGoogleImagePreviewExpressState=async(e=!1)=>{if(e)return;let t=await chrome.storage.local.get(this.googleImageExpressStateKey);t=t?.[this.googleImageExpressStateKey]?t[this.googleImageExpressStateKey]:this.googleImageExpressInitialState;let s={...this.googleImageExpressInitialState,...t};s.fte.shown+=1,s.fte.lastShown=Date.now(),chrome.storage.local.set({[this.googleImageExpressStateKey]:s})};loadContentScripts=async()=>{const e=chrome.runtime.getURL("content_scripts/express/fte/express-contextual-fte.js");return Promise.all([import(e)]).then(e=>{this.expressContextualFteClass=e[0].default})};isGoogleDomain=()=>"www.google.com"===window.location.hostname;init=async()=>{if(!this.isGoogleDomain())return this.isEligible=async()=>!1,void(this.render=async()=>{});const e=await chrome.runtime.sendMessage({main_op:"google-image-preview-express-init"});this.config=e,await this.loadContentScripts();const t=(await chrome.storage.local.get("editGImageFteTab"))?.editGImageFteTab;if(t?.value&&t?.expiry){(new Date).getTime()<=t.expiry&&(await this.render(!0),this.rendered=!0),chrome.storage.local.remove("editGImageFteTab")}}}