/*************************************************************************
* 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.
**************************************************************************/
import state from"./state.js";import{createFteTooltip,updateOneTimeFteToolTipCoolDown,removeFteTooltip as removeFteTooltipUtil}from"../utils/fte-utils.js";import{sendAnalytics,sendErrorLog,getClosestElementBySelectors}from"../utils/util.js";const LINKEDIN_FTE_TOOLTIP_CONTAINER_CLASS="acrobat-fte-tooltip-container",LINKEDIN_FTE_TOOLTIP_BUTTON_CLASS="acrobat-fte-tooltip-button",LINKEDIN_TOUCH_POINT_CONTAINER_CLASS="linkedin-acrobat-touch-point-container",LINKEDIN_FTE_STATE_STORAGE_KEY="acrobat-linkedin-fte-state",LINKEDIN_CHAT_TOUCH_POINT_CONTAINER_CLASS="linkedin-acrobat-touch-point-chat-panel",LINKEDIN_CHAT_FTE_TOOLTIP_CONTAINER_CLASS="acrobat-chat-fte-tooltip-container",LINKEDIN_CHAT_FTE_STATE_STORAGE_KEY="acrobat-linkedin-chat-fte-state",documentListenerOptions={signal:state?.eventControllerSignal};let currentClickOutsideHandler=null;const removeFteTooltip=()=>{removeFteTooltipUtil("acrobat-fte-tooltip-container"),currentClickOutsideHandler&&(document.removeEventListener("click",currentClickOutsideHandler,documentListenerOptions),currentClickOutsideHandler=null)},handleFteClickOutside=(t,e)=>{const o=document.getElementsByClassName("acrobat-fte-tooltip-container");o.length>0&&(o[0]?.contains(t?.target)||(removeFteTooltip(),sendAnalytics([["DCBrowserExt:linkedIn:FTE:Dismissed",{source:e}]])))},handleFteButtonClick=t=>{removeFteTooltip(),sendAnalytics([["DCBrowserExt:linkedIn:FTE:Closed",{source:t}]])},addFTETooltipEventListeners=(t,e)=>{const o=t?.querySelector(".acrobat-fte-tooltip-button");o?.addEventListener("click",()=>handleFteButtonClick(e)),currentClickOutsideHandler=t=>handleFteClickOutside(t,e),document.addEventListener("click",currentClickOutsideHandler,documentListenerOptions)},addFTE=async()=>{try{const t=document.getElementsByClassName(LINKEDIN_TOUCH_POINT_CONTAINER_CLASS),e=document.getElementsByClassName("acrobat-fte-tooltip-container");if(t?.length>0&&t[0]&&0===e?.length){const e=state?.config,o=createFteTooltip(e?.fteToolTipStrings,"linkedInPDF");addFTETooltipEventListeners(o,"post_view"),t[0].appendChild(o),sendAnalytics([["DCBrowserExt:linkedIn:FTE:Shown",{source:"post_view"}]]),await updateOneTimeFteToolTipCoolDown("acrobat-linkedin-fte-state",e?.feedFteConfig,"acrobat-linkedin-chat-fte-state")}}catch(t){sendErrorLog("LinkedInTouchPoint","Failure in addFTE")}},getTouchPointSource=t=>{const e=state?.config?.selectors?.linkedInChatTouchPoint?.selectors,o=e?.conversationWrapper?.map(t=>t.startsWith(".")?t:`.${t}`),n=getClosestElementBySelectors(t,o),i=e?.messageThreadPillar?.some(t=>n?.classList.contains(t));return i?"message_view":"chat_view"},addChatFTE=async()=>{try{const t=document.getElementsByClassName("linkedin-acrobat-touch-point-chat-panel"),e=Array.from(t).filter(t=>"inline-flex"===t.style.display),o=e.length>0?e[e.length-1]:null,n=document.getElementsByClassName("acrobat-chat-fte-tooltip-container");if(o&&0===n?.length){const t=getTouchPointSource(o),e=state?.config,n=createFteTooltip(e?.chatFteToolTipStrings,"linkedInChatPDF");addFTETooltipEventListeners(n,t),o.appendChild(n),sendAnalytics([["DCBrowserExt:linkedIn:FTE:Shown",{source:t}]]),await updateOneTimeFteToolTipCoolDown("acrobat-linkedin-chat-fte-state",e?.chatFteConfig,"acrobat-linkedin-fte-state")}}catch(t){sendErrorLog("LinkedInTouchPoint","Failure in addChatFTE")}};export{addFTE,addChatFTE,removeFteTooltip};