import{concat}from"../common.js";import{IntermediateSearchResults,SearchResults,EnrichedSearchResults}from"../type.js";import{apply_enrich}from"../document/search.js";import Document from"../document.js";import Index from"../index.js";import WorkerIndex from"../worker.js";export default function(a,b,c,d){if(!a.length)return a;if(1===a.length){let e=a[0];return e=c||e.length>b?e.slice(c,c+b):e,d?apply_enrich.call(this,e):e}let e=[];for(let f,g,h=0;h<a.length;h++)if((f=a[h])&&(g=f.length)){if(c){if(c>=g){c-=g;continue}f=f.slice(c,c+b),g=f.length,c=0}if(g>b&&(f=f.slice(0,b),g=b),!e.length&&g>=b)return d?apply_enrich.call(this,f):f;if(e.push(f),b-=g,!b)break}return e=1<e.length?concat(e):e[0],d?apply_enrich.call(this,e):e}