/*************************************************************************
* 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.
**************************************************************************/
(()=>{let t,e,n,o,i,s;const c="linkedin-acrobat-touch-point",r="linkedin-acrobat-touch-point-fullscreen",a="linkedin-acrobat-touch-point-accessibility",l="linkedin-acrobat-touch-point-container",d="linkedin-acrobat-touch-point-icon",m="linkedin-acrobat-touch-point-chat",u="linkedin-acrobat-touch-point-chat-panel",h="acrobat-processed",f="acrobat-processed-chat",g="Y",p="post_view",L="chat_view",C="message_view",E="accessibility_view";let b;const k=async(t,o,i,s,c=!1)=>{try{const r=new URL(o);i&&i.classList.contains(a)&&(s=E);const l=e?.buildAcrobatPromotionSource("linkedin_chrome",s);r.searchParams.set("acrobatPromotionSource",l);const d=r.toString();let m=chrome.runtime.getURL("viewer.html")+"?pdfurl="+encodeURIComponent(d);t&&(m+="&pdffilename="+encodeURIComponent(t)),c?(chrome.runtime.sendMessage({main_op:"set-pdf-marker-action"},t=>{t&&t.success&&window.open(m,"_blank")}),n?.acrobatTouchPointClicked(LINKEDIN_CHAT_FTE_STATE_STORAGE_KEY)):(window.open(m,"_blank"),n?.acrobatTouchPointClicked(s===p||s===E?"acrobat-linkedin-fte-state":LINKEDIN_CHAT_FTE_STATE_STORAGE_KEY));const u=c?"SummarizeCTA:Clicked":"TouchPoint:Clicked";e?.sendAnalytics([[`DCBrowserExt:LinkedIn:${u}`,{source:s}]]),chrome.runtime.sendMessage({main_op:"akamai-ping"})}catch(t){const n=c?"summarize":"acrobat";e?.sendErrorLog("LinkedInTouchPoint",`Failure in ${n}TouchPointEventHandler ${s}`)}},P=(e=!1)=>{const n=document.createElement("span");return n.setAttribute("class","linkedin-acrobat-touch-point-text"),n.textContent=e?t?.config?.summariseTouchPointString:t?.config?.openInAcrobatString,n},A=(t,n,o)=>{const i=document.createElement("div"),s=e?.createAcrobatIconElement(d,"browser/images/acrobat_dc_appicon_128.png"),r=P();o===L||o===C?i.classList.add(m):o===p&&i.classList.add(c),i.appendChild(s),i.appendChild(r);const a=document.createElement("div");return o===p&&a.classList.add(l),a.appendChild(i),a.addEventListener("click",()=>k(t,n,i,o,!1)),a},w=()=>{Array.from(document.getElementsByClassName(c)).forEach(t=>{t.remove(),o?.removeFteTooltip()})},y=()=>{chrome.runtime.onMessage.addListener(t=>{"add-fte-for-linkedin-touch-point"===t?.type?o?.addFTE(t?.frameId):"add-fte-for-linkedin-chat-touch-point"===t?.type?o?.addChatFTE():"acrobatTouchPointsDisabled"===t?.content_op&&(t.acrobatShortcutSurfaceId&&"linkedin"!==t.acrobatShortcutSurfaceId||(s?.disconnect(),w()))})},T=()=>{const n=e?.getFirstElementBasedOnSelectors(t?.config?.selectors?.pdfAttachmentWithoutAcrobatIcon,document);if(!n)return;const o=n?.getAttribute("href");if(!o)return;const i=e?.getClosestElementBySelectors(n,t?.config?.selectors?.pdfAttachmentContainer);if(!i)return;const s=e?.getElementFromParent(t?.config?.selectors?.pdfAttachmentTitle,i);if(!s)return;const d=e?.getElementFromParent([l],i);if(!d)return;const m=e?.getElementFromParent([c],d);m&&(((e,n)=>{const o=t?.config?.selectors?.pdfInFullscreen?.some(t=>e?.classList.contains(t));o?n.classList.contains(r)||n.classList.add(r):(n.classList.contains(r)&&n.classList.remove(r),n.classList.contains(a)&&n.classList.remove(a))})(i,m),(n=>{const o=e?.getElementFromParent(t?.config?.selectors?.accessibilityButton,document);if(!o)return;const i=t?.config?.selectors?.isAccessibilityButtonPressed?.some(t=>o?.classList.contains(t));i&&!n.classList.contains(a)?(n.classList.add(a),e?.sendAnalytics([["DCBrowserExt:LinkedIn:TouchPoint:Shown",{source:E}]])):!i&&n.classList.contains(a)&&n.classList.remove(a)})(m),((t,e)=>{e.style.display=(t?.getBoundingClientRect()?.width||0)<400?"none":""})(s,d))},S=(t=[],n=document,o,i)=>{if(!Array.isArray(t)||0===t.length)return[];const s=t.map(t=>`${t}:not([${o}="${i}"])`);return e?.getElementsListBasedOnSelectors(s,n)||[]},I=()=>{const n=S(t?.config?.selectors?.pdfAttachmentWithoutAcrobatIcon,document,h,g);n?.length&&n?.forEach(n=>{const o=n?.getAttribute("href");if("string"!=typeof(i=o)||!i.includes("document-pdf-analyzed"))return;var i;const s=(()=>{const n=e?.getElementFromParent(t?.config?.selectors?.pdfAttachmentTitle,document);if(n&&n.innerText)return n.innerText.split("\n")[0];return""})(),c=A(s,o,p),r=e?.getClosestElementBySelectors(n,t?.config?.selectors?.pdfAttachmentContainer);if(!r)return;const a=e?.getElementFromParent(t?.config?.selectors?.pdfAttachmentTitle,r);if(!a)return;if((a?.getBoundingClientRect()?.width||0)<400)return;a.append(c);const l=c?.getBoundingClientRect();chrome.runtime.sendMessage({main_op:"linkedin-touch-point-added",frameId:t?.config?.frameId,position:{top:l.top,left:l.left,right:l.right,bottom:l.bottom}}),n.setAttribute(h,g),e?.sendAnalytics([["DCBrowserExt:LinkedIn:TouchPoint:Shown",{source:p}]])})},F=(t,e,n)=>!t&&(!!e||n>=450),_=(t,n,o)=>{const i=document.createElement("div");i.classList.add(u);const s=A(t,n,o),c=((t,n,o)=>{const i=document.createElement("div"),s=e?.createAcrobatIconElement(d,"browser/images/SDC_AISummary_16_N.svg"),c=P(!0);return i.classList.add(m),i.appendChild(s),i.appendChild(c),i.addEventListener("click",()=>k(t,n,null,o,!0)),i})(t,n,o);return i.appendChild(s),i.appendChild(c),i},v=(t,n,o,s,c,r)=>{const a=b?.chatMessageWithPdfAttachment?.map(t=>t.startsWith(".")?t:`.${t}`),l=e?.getFirstElementBasedOnSelectors(a,n);if(!l)return;const d=(t=>{const n=e?.getFirstElementBasedOnSelectors(b?.attachmentName,t);return n?.textContent.trim()||null})(l);if(!d)return;const m=i?.getFileUrlFromState(s,d,c);if(!m)return;const u=d.replace(/\.pdf$/i,"").trimEnd(),f=_(u,m,r);n.firstElementChild.insertAdjacentElement("afterend",f);const p=t?.getBoundingClientRect(),L=f?.getBoundingClientRect();L.top-p.top>135&&chrome.runtime.sendMessage({main_op:"fte-eligible-linkedin-chat-touch-point-added"}),o.setAttribute(h,g),e?.sendAnalytics([["DCBrowserExt:LinkedIn:TouchPoint:Shown",{source:r}]]),e?.sendAnalytics([["DCBrowserExt:LinkedIn:SummarizeCTA:Shown",{source:r}]])},B=t=>{let n=L;const o=b?.conversationWrapper?.map(t=>t.startsWith(".")?t:`.${t}`),i=e?.getClosestElementBySelectors(t,o),s=b?.messageThreadPillar?.some(t=>i?.classList.contains(t));s&&(n=C);const c=t.getAttribute("data-event-urn");if(!c)return;const r=e?.getElementListForSelectors(b?.chatMessageContainer,t);if(!r?.length)return;const a=[];for(const e of r)e.firstElementChild&&v(i,e,t,c,a,n)},D=()=>{const t=S(b?.chatMessageElementsList,document,h,g);if(t.length)for(const e of t)B(e)},M=()=>{const n=e?.isAnalyticsSentInTheMonthOrSession("DCBrowserExt:LinkedIn:ChatPdf:Shown"),o=e?.isAnalyticsSentInTheMonthOrSession("DCBrowserExt:LinkedIn:ChatPdf:Clicked");n&&o||(()=>{const n=S(t?.config?.selectors?.linkedInChat?.chatMessageContainer,document,f,g);if(n?.length)for(const o of n){o.setAttribute(f,g);const n=e?.getFirstElementBasedOnSelectors(t?.config?.selectors?.linkedInChat?.chatMessageElement,o);if(!n)continue;const i=t?.config?.selectors?.linkedInChat?.chatMessageWithPdfAttachment?.some(t=>n?.classList.contains(t));if(i){e?.sendAnalyticsOncePerMonth("DCBrowserExt:LinkedIn:ChatPdf:Shown");const n=e?.getFirstElementBasedOnSelectors(t?.config?.selectors?.linkedInChat?.chatMessageDownloadButton,o);n&&n.addEventListener("click",()=>{e?.sendAnalyticsOncePerMonth("DCBrowserExt:LinkedIn:ChatPdf:Clicked")})}}})()},R=()=>{D(),(()=>{const t=e?.getElementListForSelectors([u],document);if(!t?.length)return;const n=e?.getElementListForSelectors(b?.conversationWrapper,document);if(n?.length)for(const t of n){const n=e?.getElementListForSelectors([u],t);if(!n)continue;const o=t.getBoundingClientRect().width,i=b?.petiteMessageContainer?.some(e=>t?.classList.contains(e)),s=b?.jumboMessageContainer?.some(e=>t?.classList.contains(e)),c=F(i,s,o);for(const t of n)c?t.style.setProperty("display","inline-flex","important"):t.style.setProperty("display","none","important")}})()},x=()=>{const n=window.location.host;"media.licdn.com"===n&&t?.config?.enableLinkedinPDFTouchPoint&&(I(),T()),"www.linkedin.com"===n&&window.top===window.self&&(t?.config?.enableLinkedinChatPDFTouchPoint&&R(),t?.config?.enableLinkedinPDFTouchPoint&&e?.sendAnalyticsOncePerMonth("DCBrowserExt:LinkedIn:TouchPoint:Enabled"),t?.config?.enableLinkedinChatPDFAnalytics&&M())},O=()=>{if(document?.body)try{const e={attributes:!0,attributeFilter:["class"],childList:!0,subtree:!0};s=new MutationObserver(function(){s.takeRecords(),chrome?.runtime?.id?x():(s?.disconnect(),w(),t?.disconnectEventListeners())}),s.observe(document.body,e)}catch(t){}else setTimeout(O,500)};chrome.runtime.sendMessage({main_op:"linkedin-init"},async s=>{(s?.enableLinkedinPDFTouchPoint||s?.enableLinkedinChatPDFAnalytics||s?.enableLinkedinChatPDFTouchPoint)&&(async()=>{[t,e,n,o,i]=await Promise.all([import(chrome.runtime.getURL("content_scripts/linkedin/state.js")).then(t=>t.default),import(chrome.runtime.getURL("content_scripts/utils/util.js")),import(chrome.runtime.getURL("content_scripts/utils/fte-utils.js")),import(chrome.runtime.getURL("content_scripts/linkedin/linkedin-fte-service.js")),import(chrome.runtime.getURL("content_scripts/linkedin/linkedin-response-service.js"))])})().then(()=>{t.config=s,y(),s?.enableLinkedinChatPDFTouchPoint&&(b=t?.config?.selectors?.linkedInChatTouchPoint?.selectors,i?.injectResponseListenerScript(),i?.addLinkedinDataEventListener(D)),e.addFontToDocument(t),O(),x()})})})();