import*as i18n from"../i18n/i18n.js";import{FilteredListWidget,getRegisteredProviders}from"./FilteredListWidget.js";const UIStrings={typeToSeeAvailableCommands:"Type '?' to see available commands",typeQuestionMarkToSeeAvailable:"Type question mark to see available commands"},str_=i18n.i18n.registerUIStrings("quick_open/QuickOpen.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);export const history=[];export class QuickOpenImpl{constructor(){this._prefix=null,this._query="",this._providers=new Map,this._prefixes=[],this._filteredListWidget=null,getRegisteredProviders().forEach(this._addProvider.bind(this)),this._prefixes.sort(((e,t)=>t.length-e.length))}static show(e){const t=new this,i=new FilteredListWidget(null,history,t._queryChanged.bind(t));t._filteredListWidget=i,i.setPlaceholder(i18nString(UIStrings.typeToSeeAvailableCommands),i18nString(UIStrings.typeQuestionMarkToSeeAvailable)),i.showAsDialog(),i.setQuery(e)}_addProvider(e){const t=e.prefix;null!==t&&(this._prefixes.push(t),this._providers.set(t,e.provider))}_queryChanged(e){const t=this._prefixes.find((t=>e.startsWith(t)));if("string"!==typeof t||this._prefix===t)return;if(this._prefix=t,!this._filteredListWidget)return;this._filteredListWidget.setPrefix(t),this._filteredListWidget.setProvider(null);const i=this._providers.get(t);if(!i)return;const s=i();this._prefix===t&&this._filteredListWidget&&(this._filteredListWidget.setProvider(s),this._providerLoadedForTest(s))}_providerLoadedForTest(e){}}let showActionDelegateInstance;export class ShowActionDelegate{static instance(e={forceNew:null}){const{forceNew:t}=e;return showActionDelegateInstance&&!t||(showActionDelegateInstance=new ShowActionDelegate),showActionDelegateInstance}handleAction(e,t){switch(t){case"quickOpen.show":return QuickOpenImpl.show(""),!0}return!1}}