/*************************************************************************
* 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{util as e}from"../js/content-util.js";import{events as n}from"../../common/analytics.js";import{dcSessionStorage as t,dcLocalStorage as o}from"../../common/local-storage.js";import{OptionPageActions as r,OptionsPageSource as i}from"../../common/constant.js";import{sendPingEventHandler as a}from"../../common/util.js";await t.init(),chrome.runtime.sendMessage({main_op:"getFloodgateFlag",flag:"dc-cv-genai-markers-impression-analytics",cachePurge:"NO_CALL"},t=>{t&&e.sendAnalytics(n.AI_ASSISTANT_SUMMARY_PILL_SHOWN)});let s=!1;const c=decodeURIComponent(e.getSearchParamFromURL("pdfMarkerLink",window.location.href));function m(){const e=$("#menuToggle"),n=$("#dropdownMenu"),t=$(".assistant-container");s=!s,s?($("#menu").attr("src","../images/SDC_Close_18_N.svg"),$("#menu").addClass("active"),e.attr("aria-expanded","true"),n.show(),t.addClass("menu-open"),"undefined"!=typeof chrome&&chrome.runtime&&chrome.runtime.sendMessage({main_op:"analytics",analytics:[["DCBrowserExt:AI:MenuDropdownShown"]]})):($("#menu").attr("src","../images/SDC_ShowMenu_18_N.svg"),$("#menu").removeClass("active"),e.attr("aria-expanded","false"),n.hide(),t.removeClass("menu-open")),"undefined"!=typeof chrome&&chrome.runtime&&chrome.runtime.sendMessage({main_op:"updateIframeHeight",href:c,menuOpen:s})}function d(){s&&m()}function u(e){return function(n){"click"!==n.type&&("keydown"!==n.type||"Enter"!==n.key&&" "!==n.key)||(n.preventDefault(),e(),d())}}async function l(){try{"undefined"!=typeof chrome&&chrome.runtime&&chrome.runtime.sendMessage({main_op:"analytics",analytics:[["DCBrowserExt:AI:SummaryCTAClicked"]]}),c&&(a(),t.setWithTTL("pdfMarkerAction",!0,5e3),"undefined"!=typeof chrome&&chrome.runtime&&chrome.runtime.sendMessage({main_op:"openPDFInNewTab",url:c}))}catch(e){console.error("Error handling primary action:",e)}}function p(){try{"undefined"!=typeof chrome&&chrome.runtime&&(chrome.runtime.sendMessage({main_op:"analytics",analytics:[["DCBrowserExt:AI:MenuHideClicked"]]}),chrome.runtime.sendMessage({main_op:"hideAIMarkerPopup",href:c}))}catch(e){console.error("Error hiding popup:",e)}}function g(){try{e.sendAnalytics(n.AI_ASSISTANT_MENU_SETTINGS_CLICKED),o.setItem("optionsPageSource",i.AI_CONTEXTUAL_MENU).then(()=>{chrome.runtime.sendMessage({type:"open_options_page",preferenceTabId:"generative-ai",controlId:"genai-markers-section",highlightSection:["ai-contextual-menu-section","ai-contextual-menu-toggle"]})})}catch(e){console.error("Error opening settings:",e)}}function h(){document.getElementById("menuToggle").addEventListener("click",m);document.getElementById("primaryAction").addEventListener("click",l);const e=document.getElementById("hideForSession"),n=document.getElementById("openSettings"),t=u(p),o=u(g);e.addEventListener("click",t),e.addEventListener("keydown",t),n.addEventListener("click",o),n.addEventListener("keydown",o),window.addEventListener("message",e=>{"exit"===e.data.action&&document.querySelector(".assistant-container").classList.add("exit")}),document.addEventListener("visibilitychange",()=>{document.hidden&&s&&d()})}$(document).ready(()=>{e.translateElements(".translate"),async function(e){try{"false"===(await chrome.storage.local.get("pdfViewer"))?.pdfViewer&&chrome.runtime.sendMessage({main_op:"hideAIMarkerPopup",href:e})}catch(e){console.error("Error checking default viewer ownership:",e)}}(c),function(e){try{const n=document.querySelector(".assistant-container");n&&chrome.runtime.sendMessage({main_op:"validateOverlappingElements",elementRect:n.getBoundingClientRect(),link:e})}catch(e){console.error("Error logging overlapping elements:",e)}}(c),h()});