'use strict';
import * as _0x31c1f9 from 'cheerio';
import { apiBaseGet } from '../../../fd-toolbox/api/base-api.js';
import { createError } from '../../../fd-toolbox/errors/errors.js';
import { enricherErrorMessages } from '../../enricher/constants/enricher-error-message-constants.js';
import { htmlTags, htmlAtributes } from '../../../base-repo/constants/html-element-names.js';

var __defProp=Object['defineProperty'],__name=(_0x493953,_0x30c708)=>__defProp(_0x493953,'name',{'value':_0x30c708,'configurable':!![]});async function getHtml(_0x52fbb9){const _0x31d9a1=await apiBaseGet(_0x52fbb9);return String(_0x31d9a1['data']);}__name(getHtml,'getHtml');function extractText(_0x164e9e,_0x5844d1){const _0x14fc2a=_0x31c1f9['load'](_0x164e9e),_0x1d3cb2=[];_0x14fc2a('p,\x20h1,\x20h2,\x20h3,\x20h4,\x20h5,\x20h6,\x20li,\x20td,\x20th,\x20article')['each']((_0x38d09c,_0x338d62)=>{_0x1d3cb2['push'](_0x14fc2a(_0x338d62)['text']()['trim']());});const _0x1ae67d=_0x1d3cb2['join']('\x0a')['trim']();return _0x1ae67d['slice'](0xc3e+0x26*0xc1+-0x28e4,_0x5844d1);}__name(extractText,'extractText');async function fetchHtml(_0x336ec){const _0x1d0b69=await fetch(_0x336ec),_0x4dd1de=await _0x1d0b69['text']();if(!_0x1d0b69['ok'])throw createError(enricherErrorMessages['errorFetching']['replace']('{0}',_0x1d0b69['status']+':\x20'+_0x4dd1de));return _0x4dd1de;}__name(fetchHtml,'fetchHtml');async function extractLinks(_0x161d24){const _0x36038d=_0x31c1f9['load'](_0x161d24),_0x3b9ac0=[];return _0x36038d(htmlTags['a'])['each']((_0x2b194a,_0xf2fce7)=>{const _0x2c5199=_0x36038d(_0xf2fce7)['attr'](htmlAtributes['href']);_0x2c5199&&_0x3b9ac0['push'](_0x2c5199);}),_0x3b9ac0;}__name(extractLinks,'extractLinks');async function extractLinksFilteredByText(_0x3aa734,_0x2d0dde){const _0x3d0f94=_0x31c1f9['load'](_0x3aa734),_0x414504=[];return _0x3d0f94(htmlTags['a'])['each']((_0x56cb0e,_0x5be44e)=>{const _0x33f9ee=_0x3d0f94(_0x5be44e)['attr'](htmlAtributes['href']),_0x45269e=_0x3d0f94(_0x5be44e)['text']();_0x33f9ee&&_0x2d0dde['test'](_0x45269e)&&_0x414504['push'](_0x33f9ee);}),_0x414504;}__name(extractLinksFilteredByText,'extractLinksFilteredByText');

export { extractLinks, extractLinksFilteredByText, extractText, fetchHtml, getHtml };
