'use strict';
import { extractEmailsFromHtml } from '../../../../fd-toolbox/html/extract-emails-from-html.js';
import { baseHttpGetText } from '../../fd/fd-toolbox-web/http/base-http-client.js';
import { extractLinks, extractLinksFilteredByText } from '../../../other/scrapping/scrappers.js';
import { pagesPattern, mailtoLink, mailtoPattern, socialMediaSites, urlNormalizationPattern, httpsPrefix, hashPrefix, httpPrefix } from './scan-social-media-and-email-constants.js';

var __defProp=Object['defineProperty'],__name=(_0x5c808c,_0x1aead0)=>__defProp(_0x5c808c,'name',{'value':_0x1aead0,'configurable':!![]});async function scanWebsite(_0x61e949,_0x2de7ea=-0xe*-0x158+0x12e*-0x10+0x3*0x6,_0x4a74f3=0x63*-0x29+0x77d+-0x2ca*-0x3,_0x54f6fc=new Set(),_0x21523d=new Set(),_0xa34c07=new Map()){let _0x50e216;if(_0x4a74f3>_0x2de7ea||_0x54f6fc['has'](_0x61e949))_0x50e216={'emails':Array['from'](_0x21523d),'socialLinks':Array['from'](_0xa34c07['values']())};else {_0x54f6fc['add'](_0x61e949);const _0x4a3819=await fetchPageData(_0x61e949);if(!_0x4a3819)_0x50e216={'emails':Array['from'](_0x21523d),'socialLinks':Array['from'](_0xa34c07['values']())};else {extractEmails(_0x4a3819['html'],_0x4a3819['links'],_0x21523d),findSocialLinks(_0x4a3819['links'],_0xa34c07);const _0x203ca3=new URL(_0x61e949),_0x1b3e9a=getInternalLinks(_0x4a3819['links'],_0x203ca3),_0x15f2c6=filterContactLinks(_0x1b3e9a)['concat'](_0x4a3819['contactLinks']),_0xb42adb=Array['from'](new Set(_0x15f2c6)),_0x23597a=_0xb42adb['map'](_0x5d3fd2=>{if(!_0x54f6fc['has'](_0x5d3fd2))return scanWebsite(_0x5d3fd2,_0x2de7ea,_0x4a74f3+(-0x18ae+-0x1f32+0x37e1*0x1),_0x54f6fc,_0x21523d,_0xa34c07);return void(-0xfd+0x18cd*0x1+0x10*-0x17d);})['filter'](Boolean);await Promise['all'](_0x23597a),_0x50e216={'emails':Array['from'](_0x21523d),'socialLinks':Array['from'](_0xa34c07['values']())};}}return _0x50e216;}__name(scanWebsite,'scanWebsite');async function scanWebsiteWrapper(_0x2932f6){try{const _0x4becfa=normalizeUrl(_0x2932f6);if(!_0x4becfa)return {'emails':[],'socialLinks':[]};return await scanWebsite(_0x4becfa);}catch{return {'emails':[],'socialLinks':[]};}}__name(scanWebsiteWrapper,'scanWebsiteWrapper');async function fetchPageData(_0x3e8c88){const _0x3bd800=await baseHttpGetText(_0x3e8c88);if(!_0x3bd800)return void(0x6*-0x145+0xe34+-0x696);const _0x22cf58=await extractLinks(_0x3bd800),_0x3f14e3=await extractLinksFilteredByText(_0x3bd800,pagesPattern);return {'html':_0x3bd800,'links':_0x22cf58,'contactLinks':_0x3f14e3};}__name(fetchPageData,'fetchPageData');function extractEmails(_0x2e09db,_0x32480c,_0x399fc4){const _0x1a00c4=extractEmailsFromHtml(_0x2e09db);_0x1a00c4?.['forEach'](_0x399fc4['add']['bind'](_0x399fc4)),_0x32480c['forEach'](_0x220536=>{_0x220536['startsWith'](mailtoLink)&&_0x399fc4['add'](_0x220536['replace'](mailtoPattern,''));});}__name(extractEmails,'extractEmails');function findSocialLinks(_0x1511b5,_0x3fd85d){_0x1511b5['forEach'](_0x2917b4=>{const _0x37dfeb=socialMediaSites['find'](_0x2917b4['includes']['bind'](_0x2917b4));if(_0x37dfeb&&!_0x3fd85d['has'](_0x37dfeb)){const _0x3303f2=_0x2917b4['replace'](urlNormalizationPattern,httpsPrefix);_0x3fd85d['set'](_0x37dfeb,_0x3303f2);}});}__name(findSocialLinks,'findSocialLinks');function isValidUrl(_0x3ada4f){try{return new URL(_0x3ada4f),!![];}catch{return ![];}}__name(isValidUrl,'isValidUrl');function getInternalLinks(_0x2d17fe,_0x409b86){const _0x2a3949=_0x409b86['hostname'],_0x1cefff=[];for(const _0x201449 of _0x2d17fe){if(!_0x201449['startsWith'](mailtoLink)&&!_0x201449['startsWith'](hashPrefix)&&isValidUrl(_0x201449)){const _0x745926=new URL(_0x201449,_0x409b86);_0x745926['hostname']===_0x2a3949&&_0x1cefff['push'](_0x745926['href']);}}return _0x1cefff;}__name(getInternalLinks,'getInternalLinks');function filterContactLinks(_0x37892f){return _0x37892f['filter'](pagesPattern['test']['bind'](pagesPattern));}__name(filterContactLinks,'filterContactLinks');function normalizeUrl(_0x1266eb){try{return new URL(_0x1266eb)['toString']();}catch{if(!_0x1266eb['startsWith'](httpPrefix))try{return new URL(''+httpsPrefix+_0x1266eb)['toString']();}catch{return void(-0x26f0+0x1*0x803+0x179*0x15);}return void(-0x5*0x705+0x16f9+0x8*0x184);}}__name(normalizeUrl,'normalizeUrl');

export { scanWebsite, scanWebsiteWrapper };
