/*************************************************************************
* 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 GenAIWebpageEligibilityService{static isReadable=null;static shouldShow=null;static encodeMap=this.getEncodeMap();static isPaidContent(){const e=document?.documentElement?.innerHTML?.includes("isAccessibleForFree");if(!e)return!1;const t=window?.location?.href,i=new URL(t).hostname;try{const e=document.querySelectorAll('script[type="application/ld+json"]');for(const t of e){if(!t.textContent)continue;const e=JSON.parse(t.textContent),a=Array.isArray(e)?e:[e];for(const e of a){if(!1===e.isAccessibleForFree||"False"===e.isAccessibleForFree)return this.trackDomain("Paid content detector (JSON-LD): Found 'isAccessibleForFree: false'",i),!0;if(e.hasPart&&Array.isArray(e.hasPart))for(const t of e.hasPart)if("WebPageElement"===t["@type"]&&(!1===t.isAccessibleForFree||"False"===t.isAccessibleForFree))return this.trackDomain("Paid content detector (JSON-LD): Found 'isAccessibleForFree: false' in hasPart",i),!0}}}catch(e){}try{const e=document.querySelectorAll('[itemprop="isAccessibleForFree"]');for(const t of e){const e=t.getAttribute("content"),a=t.getAttribute("href");if(e&&"false"===e.toLowerCase())return this.trackDomain("Paid content detector (Microdata): Found 'isAccessibleForFree' with content='false'",i),!0;if(a&&a.toLowerCase().includes("schema.org/false"))return this.trackDomain("Paid content detector (Microdata): Found 'isAccessibleForFree' with href schema.org/False",i),!0}}catch(e){}try{const e=document.querySelectorAll('[property="isAccessibleForFree"]');for(const t of e){const e=t.getAttribute("content"),a=t.getAttribute("href");if(e&&"false"===e.toLowerCase())return this.trackDomain("Paid content detector (RDFa): Found 'isAccessibleForFree' with content='false'",i),!0;if(a&&a.toLowerCase().includes("schema.org/false"))return this.trackDomain("Paid content detector (RDFa): Found 'isAccessibleForFree' with href schema.org/False",i),!0}}catch(e){}return this.trackDomain("Paid content detector: All standards-based checks completed, no paid content declared.",i),!1}static isEdgeBrowser(){return navigator.userAgentData?navigator.userAgentData.brands.some(e=>"Microsoft Edge"===e.brand):navigator.userAgent.includes("Edg/")}static async isPopupOrApp(){const e=await chrome.runtime.sendMessage({type:"getWindowType"}),{isPopup:t,isApp:i}=e;return t||i}static reset(){this.isReadable=null,this.shouldShow=null}static trackDomain(e,t,i=!0){i&&chrome.runtime.sendMessage({main_op:"log-info",log:{message:e,domain:t}})}static async getExplicitBlockList(){try{return await chrome.runtime.sendMessage({type:"get_explicit_blocklist"})||[]}catch(e){return[]}}static isSupportedLanguage(e){return["en-US","en-GB"].includes(e)||e.startsWith("en")}static getEncodeMap(){const e="abcdefghijklmnopqrstuvwxyz0123456789.-",t={};for(let i=0;i<38;i++)t[e[i]]="tubg6lxdq8jc1m9-vw.pfhskar0oi5zn372ye4"[i];return t}static encodeDomain(e){return e.toLowerCase().split("").map(e=>this.encodeMap[e]||e).join("")}static isDomainRegexBlocked(e){const t=window.dcLocalStorage.getItem("genaiWebpageRegexBlockList")||[];try{return[...GENAI_WEBPAGE_REGEX_BLOCKLIST,...t].some(({pattern:t,flags:i})=>new RegExp(t,i).test(e))}catch(e){return!1}}static async _shouldShowTouchpoints(){if(this.isEdgeBrowser())return!1;await initDcLocalStorage();if("true"===window.dcLocalStorage.getItem("bypassGenAIWebpageEligibility"))return!0;if(!window.dcLocalStorage.getItem("sidePanelRegistered"))return!1;const e=chrome.runtime.getURL(""),t=window.location.href,i=new URL(t).hostname,a=window.dcLocalStorage.getItem("allDomainTracking"),s=window.dcLocalStorage.getItem("enablePaidContentDetection");if(document.contentType&&document.contentType.includes("application/pdf"))return this.trackDomain("Page Disqualified - Webpage is a PDF",i,a),!1;if(await this.isPopupOrApp())return this.trackDomain("Page Disqualified - Webpage is in a popup or app",i,a),!1;const o="true"===window.dcLocalStorage.getItem("adobeInternal"),n=window.dcLocalStorage.getItem("appLocale")||chrome.i18n.getMessage("@@ui_locale");if(!o&&!this.isSupportedLanguage(n))return this.trackDomain("Page Disqualified - Unsupported language",i,a),!1;if(this.isDomainRegexBlocked(i))return this.trackDomain("Page Disqualified - Webpage is in the regex blocklist",i,a),!1;if(t.startsWith(e)||GENAI_WEBPAGE_BLOCKLIST.find(e=>t.includes(e)))return this.trackDomain("Page Disqualified - Webpage is in the blocklist",i,a),!1;const r=window.dcLocalStorage.getItem("hideFabDomainList")||[];if((window.dcLocalStorage.getItem("genaiWebpageBlockList")||[]).includes(i))return this.trackDomain("Page Disqualified - Webpage is in the floodgate blocklist",i,a),!1;if(r.includes(i))return this.trackDomain("Page Disqualified - Webpage is in the user blocklist",i,a),!1;if(!await this.isCurrentWebPageReadable())return this.trackDomain("Page Disqualified - Webpage is not readable",i,a),!1;return(await this.getExplicitBlockList()).includes(this.encodeDomain(i))?(this.trackDomain("Page Disqualified - Webpage is in the explicit blocklist","re.dac.ted",a),!1):(s&&this.isPaidContent()&&this.trackDomain("Page Disabled - Webpage is paid content",i,a),this.trackDomain("Page Qualified - Webpage is readable",i,a),!0)}static async isCurrentWebPageReadable(){await initDcLocalStorage();if("true"===window.dcLocalStorage.getItem("bypassGenAIWebpageEligibility"))return!0;if(null!==this.isReadable)return this.isReadable;const e=chrome.runtime.getURL("resources/SidePanel/sidePanelUtil.js"),{isProbablyReaderableAsync:t}=await import(e);return this.isReadable=await t(document),this.isReadable}static async shouldShowTouchpoints(){return null!==this.shouldShow||(this.shouldShow=await this._shouldShowTouchpoints()),this.shouldShow}static async shouldDisableTouchpoints(){return!1}}