"use strict";var __defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropNames=Object.getOwnPropertyNames,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value:value}):obj[key]=value,__spreadValues=(a,b)=>{for(var prop in b||(b={}))__hasOwnProp.call(b,prop)&&__defNormalProp(a,prop,b[prop]);if(__getOwnPropSymbols)for(var prop of __getOwnPropSymbols(b))__propIsEnum.call(b,prop)&&__defNormalProp(a,prop,b[prop]);return a},__spreadProps=(a,b)=>__defProps(a,__getOwnPropDescs(b)),__name=(target,value)=>__defProp(target,"name",{value:value,configurable:!0}),__export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&"object"==typeof from||"function"==typeof from)for(let key of __getOwnPropNames(from))__hasOwnProp.call(to,key)||key===except||__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to},__toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod),__async=(__this,__arguments,generator)=>new Promise((resolve,reject)=>{var fulfilled=value=>{try{step(generator.next(value))}catch(e){reject(e)}},rejected=value=>{try{step(generator.throw(value))}catch(e){reject(e)}},step=x=>x.done?resolve(x.value):Promise.resolve(x.value).then(fulfilled,rejected);step((generator=generator.apply(__this,__arguments)).next())}),posts_exports={};__export(posts_exports,{getPosts:()=>getPosts,getSearchPosts:()=>getSearchPosts});var getPosts=__name(function(_0){return __async(this,arguments,function*({filter:filter,page:page,signal:signal,providerContext:providerContext}){if(page>1)return[];const{axios:axios,commonHeaders:commonHeaders}=providerContext;return posts({url:"https://animetsu.net/v2/api/anime/home",filter:filter,signal:signal,axios:axios,providerContext:providerContext,headers:commonHeaders})})},"getPosts"),getSearchPosts=__name(function(_0){return __async(this,arguments,function*({searchQuery:searchQuery,page:page,signal:signal,providerContext:providerContext}){const{axios:axios,commonHeaders:commonHeaders}=providerContext;return posts({url:`https://animetsu.net/v2/api/anime/search/?query=${encodeURIComponent(searchQuery)}`,signal:signal,axios:axios,providerContext:providerContext,headers:commonHeaders})})},"getSearchPosts");function posts(_0){return __async(this,arguments,function*({url:url,filter:filter,signal:signal,axios:axios,providerContext:providerContext,headers:headers}){var _a,_b,_c;const baseUrl="https://animetsu.net",{openWebView:openWebView}=providerContext;try{let cookies,res;try{res=yield axios.get(url,{signal:signal,headers:__spreadProps(__spreadValues({},headers),{Referer:baseUrl})})}catch(error){if(403!==(null==(_a=error.response)?void 0:_a.status))throw error;cookies=(yield openWebView(baseUrl,{title:"Solve the captcha below and click done",description:"Required to bypass Animetsu anti-bot protection.",headers:__spreadProps(__spreadValues({},headers),{Referer:baseUrl}),force:!0,waitForCookie:"cf_clearance"})).cookies,res=yield axios.get(url,{signal:signal,headers:__spreadProps(__spreadValues({},headers),{Referer:baseUrl,Cookie:cookies})})}const data=filter?null==(_b=res.data)?void 0:_b[filter]:(null==(_c=res.data)?void 0:_c.results)||res.data,catalog=[];return null==data||data.map(element=>{var _a2,_b2,_c2,_d,_e,_f,_g,_h,_i,_j,_k;const title=(null==(_a2=element.title)?void 0:_a2.english)||(null==(_b2=element.title)?void 0:_b2.romaji)||(null==(_c2=element.title)?void 0:_c2.native),link=null==(_d=element.id)?void 0:_d.toString(),image=(null==(_e=element.cover_image)?void 0:_e.large)||(null==(_f=element.cover_image)?void 0:_f.extraLarge)||(null==(_g=element.cover_image)?void 0:_g.medium)||(null==(_h=element.cover_image)?void 0:_h.small)||(null==(_i=element.coverImage)?void 0:_i.large)||(null==(_j=element.coverImage)?void 0:_j.extraLarge)||(null==(_k=element.coverImage)?void 0:_k.medium);title&&link&&image&&catalog.push({title:title,link:link,image:image})}),catalog}catch(err){return console.error("animetsu error ",err),[]}})}__name(posts,"posts"),exports.getPosts=getPosts,exports.getSearchPosts=getSearchPosts;