(()=>{"use strict";functione(t){returne="function"==typeofSymbol&&"symbol"==typeofSymbol.iterator?function(e){returntypeofe}:function(e){returne&&"function"==typeofSymbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeofe},e(t)}functiont(t,i){for(vara=0;a<i.length;a++){varr=i[a];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"inr&&(r.writable=!0),Object.defineProperty(t,(void0,n=function(t,i){if("object"!==e(t)||null===t)returnt;vara=t[Symbol.toPrimitive];if(void0!==a){varr=a.call(t,"string");if("object"!==e(r))returnr;thrownewTypeError("@@toPrimitive must return a primitive value.")}returnString(t)}(r.key),"symbol"===e(n)?n:String(n)),r)}varn}!function(e,t){vari="ui.CreatePageWidget".split(".");"isekai"inwindow||(window.isekai={});for(vara=window.isekai,r=0;r<i.length-1;r++){varn=i[r];nina||(a[n]={}),a=a[n]}a[i[r]]=t}(0,function(){functione(t){!function(e,t){if(!(einstanceoft))thrownewTypeError("Cannot call a class as a function")}(this,e),this.baseDom=t,this.pageUrl=null,this.api=newmw.Api,this.hasError=!1,this.initDom()}vari,a;returni=e,(a=[{key:"initDom",value:function(){vare=mw.config.get("wgIsekaiCreatePageNamespaces");Array.isArray(e)&&0!==e.length||(e=[{name:"Main",prefix:""}]),this.selectNamespaceDropdown=newOO.ui.DropdownInputWidget({options:e.map((function(e){return{data:e.prefix,label:e.name}}))}),this.selectNamespaceDropdown.on("change",this.onNamespaceChange.bind(this)),this.pageNameInput=newisekai.ui.CreatePageInputWidget({placeholder:mw.message("isekai-createpage-page-title").parse()}),this.pageNameInput.on("enter",this.createPage.bind(this)),this.pageNameInput.on("change",this.onPageNameChange.bind(this)),this.createButton=newOO.ui.ButtonWidget({label:mw.message("isekai-createpage-create-page-button").parse(),flags:["primary","progressive"]}),this.createButton.on("click",this.createPage.bind(this)),this.inputGroup=newOO.ui.ActionFieldLayout(this.pageNameInput,this.createButton,{align:"top"}),this.formGroup=newOO.ui.HorizontalLayout({items:[this.selectNamespaceDropdown,this.inputGroup]}),this.baseDom.find(".card-body .card-content").append(this.formGroup.$element)}},{key:"createPage",value:function(){vare=this,t=this.selectNamespaceDropdown.getValue()+this.pageNameInput.getValue();console.log(t),this.hasError&&this.clearError(),t.trim().length>0?(this.createButton.setDisabled(!0),this.pageExists(t).then((function(i){if(i)e.createButton.setDisabled(!1),e.setError(mw.message("isekai-createpage-page-exists").parse());else{vara=mw.util.getUrl(t,{veaction:"edit"});e.inputGroup.setSuccess([mw.message("isekai-createpage-redirecting").parse()]),location.href=a}}))):this.setError(mw.message("isekai-createpage-title-empty").parse())}},{key:"onPageNameChange",value:function(){this.hasError&&this.clearError();vare=this.pageNameInput.getValue();if(-1!==e.indexOf(":")||-1!==e.indexOf("`")){vart=this.pageNameInput.getRange();e=e.replace(/:/g,":").replace(/`/g,"·"),this.pageNameInput.setValue(e),this.pageNameInput.selectRange(t.from,t.to)}}},{key:"onNamespaceChange",value:function(){this.pageNameInput.setPagePrefix(this.selectNamespaceDropdown.getValue())}},{key:"setError",value:function(e){this.inputGroup.setErrors([e]),this.hasError=!0}},{key:"clearError",value:function(){this.inputGroup.setErrors([]),this.hasError=!1}},{key:"pageExists",value:function(e){vart=this;returnnewPromise((function(i,a){t.api.get({action:"query",titles:e}).done((function(e){e.query&&e.query.pages?e.query.pages[-1]?i(!1):i(!0):i(!1)})).fail(a)}))}},{key:"setTitle",value:function(e){this.title.text(e)}}])&&t(i.prototype,a),Object.defineProperty(i,"prototype",{writable:!1}),e}())})();