/*************************************************************************
* 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.
**************************************************************************/
const GOOGLE_DOCS_FTE_STATE_STORAGE_KEY="acrobat-gdocs-fte-state",GOOGLE_DOCS_FTE_TOOLTIP_CONTAINER_CLASS="acrobat-fte-tooltip-container";let gdocsTouchPointAddedPromiseResolve;const gdocsTouchPointAddedPromise=new Promise(e=>{gdocsTouchPointAddedPromiseResolve=e});class GoogleDocsFte{id=`gdocsfte-${GoogleDocsFte.getDocType()}`;timeout=2e3;static GOOGLE_DOCS_DOMAINS=["docs.google.com"];static docTypeSurfaceNameAndFTEStateKey={document:{surfaceNameTranslationKey:"surfaceNameGoogleDocs",fteStateKey:"acrobat-gdocs-fte-state-document"},spreadsheets:{surfaceNameTranslationKey:"surfaceNameGoogleSheets",fteStateKey:"acrobat-gdocs-fte-state-sheets"},presentation:{surfaceNameTranslationKey:"surfaceNameGoogleSlides",fteStateKey:"acrobat-gdocs-fte-state-slides"}};constructor(){const e=window.location.hostname;GoogleDocsFte.GOOGLE_DOCS_DOMAINS.some(t=>e.includes(t))||(this.isEligible=async()=>!1,this.render=async()=>null),this.initPromise=this.loadServices()}async loadServices(){this.utils=await import(chrome.runtime.getURL("content_scripts/utils/util.js")),this.fteUtils=await import(chrome.runtime.getURL("content_scripts/utils/fte-utils.js"))}static async isTouchPointPresent(){return gdocsTouchPointAddedPromise}static getDocType(){return window.location.pathname.split("/")?.length>1?window.location.pathname.split("/")[1]:null}static getFteStateKey(e){return GoogleDocsFte.docTypeSurfaceNameAndFTEStateKey[e]?.fteStateKey}async isEligible(){await this.initPromise;const e=await chrome.runtime.sendMessage({main_op:"google_docs_init"}),t=GoogleDocsFte.getDocType();if(e?.validPaths?.includes(t)){const e=GoogleDocsFte.getFteStateKey(t),o=await chrome.storage.local.get([e]);if(o[e]||o[e]?.touchPointClicked)return!1;const{isTouchPointPresent:s}=await GoogleDocsFte.isTouchPointPresent();return s}return!1}createFTE(e,t,o){const s=GoogleDocsFte.getFteStateKey(e);chrome.storage.local.set({[s]:{count:1}});const c=this.fteUtils.createFteTooltip(t?.text?.touchPointFTE,"google-docs-convert-to-pdf");this.utils?.sendAnalytics([["DCBrowserExt:DirectVerb:Fte:Shown",{source:`GoogleDocs-${e}`,workflow:"ConvertToPdf"}]]);const i=this.addDocumentClickEventListenerForRemovingTheFTE(e);this.addFTECloseButtonListener(c,e,i),o.appendChild(c)}async render(){const e=document.getElementsByClassName("acrobat-convert-to-pdf-touch-point");if(0===e?.length)return;if(e[0].getElementsByClassName("acrobat-fte-tooltip-container")?.length>0)return;const t=GoogleDocsFte.getDocType(),o=await chrome.runtime.sendMessage({main_op:"google_docs_init",surfaceNameTranslationKey:GoogleDocsFte.docTypeSurfaceNameAndFTEStateKey[t]?.surfaceNameTranslationKey});o?.validPaths?.includes(t)&&this.createFTE(t,o,e[0])}addFTECloseButtonListener(e,t,o){e.querySelector(".acrobat-fte-tooltip-button")?.addEventListener("click",()=>{this.utils?.sendAnalytics([["DCBrowserExt:DirectVerb:Fte:Closed",{source:`GoogleDocs-${t}`,workflow:"ConvertToPdf"}]]),this.fteUtils.removeFteTooltip(),document.removeEventListener("click",o)})}addDocumentClickEventListenerForRemovingTheFTE(e){const t=()=>{this.utils?.sendAnalytics([["DCBrowserExt:DirectVerb:Fte:Dismissed",{source:`GoogleDocs-${e}`,workflow:"ConvertToPdf"}]]),this.fteUtils.removeFteTooltip(),document.removeEventListener("click",t)};return document.addEventListener("click",t),t}}window.updateFTEStateWhenGoogleDocsTouchPointClicked=()=>{const e=GoogleDocsFte.getDocType(),t=GoogleDocsFte.getFteStateKey(e);chrome.storage.local.set({[t]:{touchPointClicked:!0}})},chrome.runtime.onMessage.addListener(e=>{"acrobat-gdocs-touch-point-added"===e?.type&&gdocsTouchPointAddedPromiseResolve&&gdocsTouchPointAddedPromiseResolve({isTouchPointPresent:!0})});