/*************************************************************************
* 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 GoogleImagePreviewExpressIntegration{previewEntryPointId="google-image-preview-adobe-express-entry-point";googleImageExpressStateKey="googleImageExpressState";previewContainerQuerySelector="div.BIB1wf.EIehLd.fHE6De.Emjfjd,div.Fp3I9:not([class*=' '])";previewedImageClassname=["sFlh5c FyHeAf"];previewHeaderClassname=["HJRshd"];touchpoint="googleImagePreview";launchExpress=(e,t)=>{chrome.runtime.sendMessage({main_op:"launch-express",imgUrl:e,intent:t,touchpoint:this.touchpoint})};sendErrorLog=(e,t)=>{chrome.runtime.sendMessage({main_op:"log-error",log:{message:e,error:t}})};async loadContentScripts(){const e=chrome.runtime.getURL("content_scripts/express/single-click-cta.js"),t=chrome.runtime.getURL("content_scripts/express/express-utils.js"),i=await Promise.all([import(e),import(t)]);this.expressCTA=new i[0].default,this.expressUtils=i[1].default}addThumbnailAndImagePreviewerObserver=()=>{new MutationObserver(()=>{this.imagePreviewerObserverHandler()}).observe(document.body,{childList:!0,subtree:!0})};previewEntryPointClickHandler=e=>{if(!chrome?.runtime?.id)return void this.cleanup();if(!this.currentPreviewContainer)return void this.sendErrorLog("Error executing express in google image preview","preview container not found");if(!this.currentPreviewImage||"IMG"!==this.currentPreviewImage.tagName)return void this.sendErrorLog("Error executing express in google image preview","image element not found");const t=this.currentPreviewImage.src;t?(this.setTouchpointClickedForFteState(this.touchpoint),this.launchExpress(t,e)):this.sendErrorLog("Error executing express in google image preview","image URL not found")};imagePreviewerObserverHandler=()=>{const e=document.querySelectorAll(this.previewContainerQuerySelector);if(!e.length)return;const t=e[e.length-1];if(!t)return;this.currentPreviewContainer=t,this.removeTooltipIfFteRendered();const i=this.expressUtils.getElementsFromClassNames(this.currentPreviewContainer,this.previewedImageClassname)[0];if(!i||"IMG"!==i.tagName||this.currentPreviewImage===i)return;this.currentPreviewImage=i;const r=this.expressUtils.getElementsFromClassNames(this.currentPreviewContainer,this.previewHeaderClassname)[0];if(!r)return;const s=document.getElementById(this.previewEntryPointId);s&&this.currentPreviewContainer.contains(s)||(chrome?.runtime?.id?(this.removePreviewEntryPoint(this.previewEntryPointId),this.addPreviewEntryPoint(r,this.previewEntryPointId,this.previewEntryPointClickHandler),this.expressUtils.sendAnalyticsEventOncePerDay([["DCBrowserExt:Express:GoogleImagePreview:PreviewEntryPoint:Shown"]])):this.cleanup())};toggleButtonSize=e=>{const t=document.getElementById("expressEditImageParentContextMenu");t&&(t.style.display=e?"none":"block");const i=document.getElementsByClassName("cc440d50ba-express-entrypoint-button-icon")[0];if(!i)return;let r="40px",s="7px 8px 7px 14px";e&&(r="32px",s="7px"),i.style.width=r,i.style.padding=s};cleanup=()=>{this.removePreviewEntryPoint(this.previewEntryPointId),this.tooltip?.tooltip?.remove(),this.tooltip=null,this.removeContextualFte()};addPreviewEntryPoint=async(e,t,i)=>{if(document.getElementById(t))return;const r=await this.expressCTA.renderMenuButton(i,this.touchpoint);r.id=t,r.style.display="flex",r.style.alignItems="center",r.style.visibility="hidden",e.insertBefore(r,e.firstChild);new ResizeObserver(e=>{r.style.visibility="hidden",this.toggleButtonSize(!1),0!==e[0].contentRect.width&&(e[0].contentRect.width-285<r.offsetWidth?(this.toggleButtonSize(!0),r.style.visibility="visible"):(this.toggleButtonSize(!1),r.style.visibility="visible"))}).observe(e.parentElement),chrome.runtime.sendMessage({main_op:"reRenderShowOneChild"}),this.tooltip=this.expressCTA.attachTooltip("top")};removePreviewEntryPoint=e=>{const t=document.getElementById(e);t&&t.remove()};setTouchpointClickedForFteState=async e=>{this.removeContextualFte();let t=await chrome.storage.local.get(this.googleImageExpressStateKey);if(t=t?.[this.googleImageExpressStateKey]?t[this.googleImageExpressStateKey]:{},e===this.touchpoint)t.previewTouchpointUsed=!0;chrome.storage.local.set({[this.googleImageExpressStateKey]:t})};removeContextualFte=()=>{const e=document.getElementById("express-contextual-fte");e&&e.remove()};removeTooltipIfFteRendered=()=>{document.getElementById("express-contextual-fte")&&this.tooltip&&(this.tooltip.tooltip.remove(),this.tooltip=null)};runOnceOnStartup=()=>{this.imagePreviewerObserverHandler()};init=async()=>{this.config=await chrome.runtime.sendMessage({main_op:"google-image-preview-express-init"}),this.config.enableGoogleImagePreviewExpressMenu&&(this.previewContainerQuerySelector=this.config.selectors?.previewContainerQuerySelector||this.previewContainerQuerySelector,this.previewedImageClassname=this.config.selectors?.previewedImageClassname||this.previewedImageClassname,this.previewHeaderClassname=this.config.selectors?.previewHeaderClassname||this.previewHeaderClassname,await this.loadContentScripts(),this.addThumbnailAndImagePreviewerObserver(),this.runOnceOnStartup())}}const googleImagePreviewExpressIntegration=new GoogleImagePreviewExpressIntegration;googleImagePreviewExpressIntegration.init();