import*as Diff from"../diff/diff.js";import*as UI from"../ui/ui.js";import{FilteredListWidget,Provider}from"./FilteredListWidget.js";export class QuickPick{constructor(){throw new ReferenceError("Instance type not implemented.")}static show(e,t){let i=new Promise((e=>{}));const r=new Promise((r=>{const s=new QuickPickProvider(e,r,t.matchOnDescription?.5:0,t.matchOnDetail?.25:0),o=new FilteredListWidget(s);o.setPlaceholder(t.placeHolder),o.setPromptTitle(t.placeHolder),o.showAsDialog(t.placeHolder),i=o.once("hidden"),o.setQuery("")}));return Promise.race([r,i]).then((e=>e))}}class QuickPickProvider extends Provider{constructor(e,t,i=.5,r=.25){super(),this._resolve=t,this._items=e,this._matchOnDescription=i,this._matchOnDetail=r}itemCount(){return this._items.length}itemKeyAt(e){const t=this._items[e];let i=t.label;return this._matchOnDescription&&(i+=" "+t.description),this._matchOnDetail&&(i+=" "+t.detail),i}itemScoreAt(e,t){const i=this._items[e],r=t.toLowerCase();let s=Diff.Diff.DiffWrapper.characterScore(r,i.label.toLowerCase());if(this._matchOnDescription&&i.description){s+=Diff.Diff.DiffWrapper.characterScore(r,i.description.toLowerCase())*this._matchOnDescription}if(this._matchOnDetail&&i.detail){s+=Diff.Diff.DiffWrapper.characterScore(r,i.detail.toLowerCase())*this._matchOnDetail}return s}renderItem(e,t,i,r){const s=this._items[e];i.removeChildren();const o=i.createChild("span");if(UI.UIUtils.createTextChild(o,s.label),FilteredListWidget.highlightRanges(i,t,!0),s.description){const e=i.createChild("span","quickpick-description");UI.UIUtils.createTextChild(e,s.description),this._matchOnDescription&&FilteredListWidget.highlightRanges(e,t,!0)}s.detail&&(UI.UIUtils.createTextChild(r,s.detail),this._matchOnDetail&&FilteredListWidget.highlightRanges(r,t,!0))}renderAsTwoRows(){return this._items.some((e=>Boolean(e.detail)))}selectItem(e,t){"number"!==typeof e?this._resolve(void 0):this._resolve(this._items[e])}}