import*as Common from"../common/common.js";import*as Platform from"../platform/platform.js";export class ListModel extends Common.ObjectWrapper.ObjectWrapper{constructor(e){super(),this._items=e||[]}[Symbol.iterator](){return this._items[Symbol.iterator]()}get length(){return this._items.length}at(e){return this._items[e]}every(e){return this._items.every(e)}filter(e){return this._items.filter(e)}find(e){return this._items.find(e)}findIndex(e){return this._items.findIndex(e)}indexOf(e,t){return this._items.indexOf(e,t)}insert(e,t){this._items.splice(e,0,t),this._replaced(e,[],1)}insertWithComparator(e,t){this.insert(Platform.ArrayUtilities.lowerBound(this._items,e,t),e)}join(e){return this._items.join(e)}remove(e){const t=this._items[e];return this._items.splice(e,1),this._replaced(e,[t],0),t}replace(e,t,s){const i=this._items[e];return this._items[e]=t,this._replaced(e,[i],1,s),i}replaceRange(e,t,s){let i;if(s.length<1e4)i=this._items.splice(e,t-e,...s);else{i=this._items.slice(e,t);const r=this._items.slice(0,e),n=this._items.slice(t);this._items=[...r,...s,...n]}return this._replaced(e,i,s.length),i}replaceAll(e){const t=this._items.slice();return this._items=e,this._replaced(0,t,e.length),t}slice(e,t){return this._items.slice(e,t)}some(e){return this._items.some(e)}_replaced(e,t,s,i){this.dispatchEventToListeners(Events.ItemsReplaced,{index:e,removed:t,inserted:s,keepSelectedIndex:i})}}export const Events={ItemsReplaced:Symbol("ItemsReplaced")};