(()=>{var e={n:n=>{var t=n&&n.__esModule?()=>n.default:()=>n;return e.d(t,{a:t}),t},d:(n,t)=>{for(var a in t)e.o(t,a)&&!e.o(n,a)&&Object.defineProperty(n,a,{enumerable:!0,get:t[a]})},o:(e,n)=>Object.prototype.hasOwnProperty.call(e,n),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},n={};(()=>{"use strict";e.r(n),e.d(n,{extend:()=>y});const t=flarum.reg.get("core","forum/app");var a=e.n(t);const r=flarum.reg.get("core","common/extend"),i=flarum.reg.get("core","common/components/Button");var o=e.n(i);const s=flarum.reg.get("core","common/utils/extractText");var c=e.n(s);const u=flarum.reg.get("core","common/utils/Stream");var l=e.n(u);const d=flarum.reg.get("core","common/components/FormModal");var f=e.n(d);const p=flarum.reg.get("core","common/components/Form");var g=e.n(p);class k extends(f()){oninit(e){super.oninit(e),this.nickname=l()(a().session.user.displayName())}className(){return"NickameModal Modal--small"}title(){return a().translator.trans("flarum-nicknames.forum.change_nickname.title")}content(){return m("div",{className:"Modal-body"},m(g(),{className:"Form--centered"},m("div",{className:"Form-group"},m("input",{type:"text",autocomplete:"off",name:"nickname",className:"FormControl",bidi:this.nickname,disabled:this.loading})),m("div",{className:"Form-group Form-controls"},m(o(),{className:"Button Button--primary Button--block",type:"submit",loading:this.loading},a().translator.trans("flarum-nicknames.forum.change_nickname.submit_button")))))}onsubmit(e){e.preventDefault(),this.nickname()!==a().session.user.displayName()?(this.loading=!0,a().session.user.save({nickname:this.nickname()},{errorHandler:this.onerror.bind(this)}).then(this.hide.bind(this)).catch((()=>{this.loading=!1,m.redraw()}))):this.hide()}}flarum.reg.add("flarum-nicknames","forum/components/NicknameModal",k);const h=flarum.reg.get("core","common/extenders");var b=e.n(h);const N=flarum.reg.get("core","common/models/User");var v=e.n(N);const y=[new(b().Model)(v()).attribute("canEditNickname")];a().initializers.add("flarum-nicknames",(()=>{(0,r.extend)("flarum/forum/components/SettingsPage","accountItems",(function(e){"nickname"===a().forum.attribute("displayNameDriver")&&this.user.canEditNickname()&&e.add("changeNickname",m(o(),{className:"Button",onclick:()=>a().modal.show(k)},a().translator.trans("flarum-nicknames.forum.settings.change_nickname_button")))})),(0,r.extend)("flarum/common/components/EditUserModal","oninit",(function(){this.nickname=l()(this.attrs.user.displayName())})),(0,r.extend)("flarum/common/components/EditUserModal","fields",(function(e){"nickname"===a().forum.attribute("displayNameDriver")&&this.attrs.user.canEditNickname()&&e.add("nickname",m("div",{className:"Form-group"},m("label",null,a().translator.trans("flarum-nicknames.forum.edit_user.nicknames_heading")),m("input",{className:"FormControl",placeholder:c()(a().translator.trans("flarum-nicknames.forum.edit_user.nicknames_text")),bidi:this.nickname})),100)})),(0,r.extend)("flarum/common/components/EditUserModal","data",(function(e){"nickname"===a().forum.attribute("displayNameDriver")&&this.attrs.user.canEditNickname()&&this.nickname()!==this.attrs.user.displayName()&&(e.nickname=this.nickname())})),(0,r.extend)("flarum/forum/components/SignUpModal","oninit",(function(){"nickname"===a().forum.attribute("displayNameDriver")&&(this.nickname=l()(this.attrs.nickname||this.attrs.username||""))})),(0,r.extend)("flarum/forum/components/SignUpModal","onready",(function(){"nickname"===a().forum.attribute("displayNameDriver")&&a().forum.attribute("setNicknameOnRegistration")&&a().forum.attribute("randomizeUsernameOnRegistration")&&this.$("[name=nickname]").select()})),(0,r.extend)("flarum/forum/components/SignUpModal","fields",(function(e){"nickname"===a().forum.attribute("displayNameDriver")&&a().forum.attribute("setNicknameOnRegistration")&&(e.add("nickname",m("div",{className:"Form-group"},m("input",{className:"FormControl",name:"nickname",type:"text",placeholder:c()(a().translator.trans("flarum-nicknames.forum.sign_up.nickname_placeholder")),bidi:this.nickname,disabled:this.loading||this.isProvided("nickname"),required:a().forum.attribute("randomizeUsernameOnRegistration")})),25),a().forum.attribute("randomizeUsernameOnRegistration")&&e.remove("username"))})),(0,r.extend)("flarum/forum/components/SignUpModal","submitData",(function(e){if("nickname"===a().forum.attribute("displayNameDriver")&&a().forum.attribute("setNicknameOnRegistration")&&(e.nickname=this.nickname(),a().forum.attribute("randomizeUsernameOnRegistration"))){const n=new Uint32Array(2);crypto.getRandomValues(n),e.username=n.join("")}}))}))})(),module.exports=n})();
//# sourceMappingURL=forum.js.map