import*as Platform from"../platform/platform.js";export class SearchConfig{constructor(e,r,t){this._query=e,this._ignoreCase=r,this._isRegex=t,this._parse()}static fromPlainObject(e){return new SearchConfig(e.query,e.ignoreCase,e.isRegex)}query(){return this._query}ignoreCase(){return this._ignoreCase}isRegex(){return this._isRegex}toPlainObject(){return{query:this.query(),ignoreCase:this.ignoreCase(),isRegex:this.isRegex()}}_parse(){const e=/(\s*(?!-?f(ile)?:)[^\\ ]|\\.)+/,r=e.source+"(\\s+"+e.source+")*",t=["(\\s*"+FilePatternRegex.source+"\\s*)","("+/"([^\\"]|\\.)+"/.source+")","("+r+")"].join("|"),i=new RegExp(t,"g"),s=this._query.match(i)||[];this._fileQueries=[],this._queries=[];for(let n=0;n<s.length;++n){const e=s[n];if(!e)continue;const r=this._parseFileQuery(e);if(r)this._fileQueries.push(r),this._fileRegexQueries=this._fileRegexQueries||[],this._fileRegexQueries.push({regex:new RegExp(r.text,this.ignoreCase()?"i":""),isNegative:r.isNegative});else if(this._isRegex)this._queries.push(e);else if(e.startsWith('"')){if(!e.endsWith('"'))continue;this._queries.push(this._parseQuotedQuery(e))}else this._queries.push(this._parseUnquotedQuery(e))}}filePathMatchesFileQuery(e){if(!this._fileRegexQueries)return!0;for(let r=0;r<this._fileRegexQueries.length;++r)if(Boolean(e.match(this._fileRegexQueries[r].regex))===this._fileRegexQueries[r].isNegative)return!1;return!0}queries(){return this._queries||[]}_parseUnquotedQuery(e){return e.replace(/\\(.)/g,"$1")}_parseQuotedQuery(e){return e.substring(1,e.length-1).replace(/\\(.)/g,"$1")}_parseFileQuery(e){const r=e.match(FilePatternRegex);if(!r)return null;const t=Boolean(r[1]);e=r[3];let i="";for(let s=0;s<e.length;++s){const r=e[s];if("*"===r)i+=".*";else if("\\"===r){++s;" "===e[s]&&(i+=" ")}else-1!==Platform.StringUtilities.regexSpecialCharacters().indexOf(e.charAt(s))&&(i+="\\"),i+=e.charAt(s)}return new QueryTerm(i,t)}}export const FilePatternRegex=/(-)?f(ile)?:((?:[^\\ ]|\\.)+)/;export class QueryTerm{constructor(e,r){this.text=e,this.isNegative=r}}export class SearchResult{label(){throw new Error("not implemented here")}description(){throw new Error("not implemented here")}matchesCount(){throw new Error("not implemented here")}matchLabel(e){throw new Error("not implemented here")}matchLineContent(e){throw new Error("not implemented here")}matchRevealable(e){throw new Error("not implemented here")}}export class SearchScope{performSearch(e,r,t,i){}performIndexing(e){}stopSearch(){}}export let RegexQuery;