/*************************************************************************
* 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 GmailImageToolsDropdownFte{id="GmailImageToolsDropdownFte";timeout=3e3;shortCoolDown=7;longCoolDown=60;ONE_DAY_IN_MILLISECONDS=864e5;gmailImageEditDropdownStateKey="gmailImageEditDropdownState";gmailImageEditDropdownInitialState={previewTouchpointUsed:!1,fte:{count:0,nextDate:null}};rendered=!1;constructor(){this.initPromise=this.init()}isEligible=async()=>{if(await this.initPromise,!this.config?.enableGmailConvertToPdfInImages)return!1;const t=await this.getState();if(t.previewTouchpointUsed)return!1;const e=Date.now(),{nextDate:i}=t.fte;return!(i&&e<=i)&&!!await this.getCtaElement()};render=async()=>{if(this.rendered)return;const t=await this.getState();if(t.previewTouchpointUsed)return;const{lastShown:e}=t.fte;if(e&&e+this.ONE_DAY_IN_MILLISECONDS>Date.now())return;const i=await this.getCtaElement(),a=i?.getElementsByClassName("cc440d50ba-express-entrypoint-button")[0];if(!a)return;this.rendered=!0;this.expressContextualFTE=new this.ExpressContextualFteClass({touchpoint:"gmailNativeViewer_edit_tools",ctaButtonElement:i,fteStrings:{fteTitle:this.config.imageToolsDropdownFteStrings.title,fteDescription:this.config.imageToolsDropdownFteStrings.description,fteCtaLabel:this.config.imageToolsDropdownFteStrings.ctaLabel},updateFteStateCallback:this.updateImageEditDropdownState,positionFteCallback:()=>{"none"===getComputedStyle(a).display&&this.expressContextualFTE.remove()},renderCallback:t=>i.appendChild(t)}),await this.expressContextualFTE.render()};getCtaElement=async()=>{for(let t=0;t<10;t+=1){const t=document.getElementById("edit-tools-dropdown-gmail-native-viewer-entry-point");if(t)return t;await new Promise(t=>setTimeout(t,100))}return null};updateImageEditDropdownState=async()=>{const t=await this.getState(),e=(t.fte.count||0)+1,i=e%3==0,a=new Date;a.setDate(a.getDate()+(i?this.longCoolDown:this.shortCoolDown)),t.fte.count=e,t.fte.nextDate=a.getTime(),t.fte.lastShown=Date.now(),await this.setState(t)};getState=async()=>{const t=(await chrome.storage.local.get(this.gmailImageEditDropdownStateKey))[this.gmailImageEditDropdownStateKey];return t||(await this.setState(this.gmailImageEditDropdownInitialState),this.gmailImageEditDropdownInitialState)};setState=async t=>{await chrome.storage.local.set({[this.gmailImageEditDropdownStateKey]:t})};loadContentScripts=async()=>{const t=chrome.runtime.getURL("content_scripts/express/fte/express-contextual-fte.js"),[e]=await Promise.all([import(t)]);this.ExpressContextualFteClass=e.default};init=async()=>{if("mail.google.com"!==window.location.hostname)return this.isEligible=async()=>!1,void(this.render=async()=>{});const t=await chrome.runtime.sendMessage({main_op:"gmail-express-init"});this.config=t,await this.loadContentScripts()}}