文件
catch-the-fish/js/dist/forum.js
T
2026-07-31 00:13:44 +08:00

2 行
26 KiB
JavaScript

(()=>{var t={715(t){t.exports=function(){"use strict";return function(t,e,a){var s="h:mm A",r={lastDay:"[Yesterday at] "+s,sameDay:"[Today at] "+s,nextDay:"[Tomorrow at] "+s,nextWeek:"dddd [at] "+s,lastWeek:"[Last] dddd [at] "+s,sameElse:"MM/DD/YYYY"};e.prototype.calendar=function(t,e){var s=e||this.$locale().calendar||r,n=a(t||void 0).startOf("d"),o=this.diff(n,"d",!0),i="sameElse",h=o<-6?i:o<-1?"lastWeek":o<0?"lastDay":o<1?"sameDay":o<2?"nextDay":o<7?"nextWeek":i,c=s[h]||r[h];return"function"==typeof c?c.call(this,a()):this.format(c)}}}()}};const e={};function a(s){flarum.reg._webpack_runtimes["xxb-catch-the-fish"]||=a;const r=e[s];if(void 0!==r)return r.exports;const n=e[s]={exports:{}};return t[s].call(n.exports,n,n.exports,a),n.exports}a.n=t=>{const e=t&&t.__esModule?()=>t.default:()=>t;return a.d(e,{a:e}),e},a.d=(t,e)=>{if(Array.isArray(e))for(var s=0;s<e.length;){var r=e[s++],n=e[s++];a.o(t,r)?0===n&&s++:0===n?Object.defineProperty(t,r,{enumerable:!0,value:e[s++]}):Object.defineProperty(t,r,{enumerable:!0,get:n})}else for(var r in e)a.o(e,r)&&!a.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},a.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),(()=>{"use strict";const t=flarum.reg.get("core","forum/app");var e=a.n(t);const s=flarum.reg.get("core","common/Model");var r=a.n(s);const n=flarum.reg.get("core","common/models/Discussion");var o=a.n(n);const i=flarum.reg.get("core","common/models/Post");var h=a.n(i);const c=flarum.reg.get("core","common/models/User");var u=a.n(c);const d=flarum.reg.get("core","common/models/Forum");var l=a.n(d);function f(t){return f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},f(t)}function p(t,e,a){return(e=function(t){var e=function(t){if("object"!=f(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var a=e.call(t,"string");if("object"!=f(a))return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==f(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[e]=a,t}class g extends(r()){constructor(){super(...arguments),p(this,"round_id",r().attribute("round_id")),p(this,"placement",r().attribute("placement")),p(this,"name",r().attribute("name")),p(this,"image_url",r().attribute("image_url")),p(this,"canSee",r().attribute("canSee")),p(this,"canCatch",r().attribute("canCatch")),p(this,"canName",r().attribute("canName")),p(this,"canPlace",r().attribute("canPlace")),p(this,"placeUntil",r().attribute("placeUntil")),p(this,"namedBy",r().hasOne("lastUserNaming")),p(this,"placedBy",r().hasOne("lastUserPlacement")),p(this,"round",r().hasOne("round")),p(this,"placementModel",r().hasOne("placement"))}apiEndpoint(){return"/catch-the-fish/"+(this.exists?"fishes/"+this.data.id:"rounds/"+this.data.attributes.round_id+"/fishes")}}flarum.reg.add("xxb-catch-the-fish","forum/models/Fish",g);class b extends(r()){constructor(){super(...arguments),p(this,"catch_count",r().attribute("catch_count")),p(this,"user",r().hasOne("user"))}}flarum.reg.add("xxb-catch-the-fish","forum/models/Ranking",b);class v extends(r()){constructor(){super(...arguments),p(this,"name",r().attribute("name")),p(this,"starts_at",r().attribute("starts_at")),p(this,"ends_at",r().attribute("ends_at")),p(this,"include_starting_pack",r().attribute("include_starting_pack")),p(this,"my_catch_count",r().attribute("my_catch_count")),p(this,"myRanking",r().hasOne("myRanking"))}apiEndpoint(){return"/catch-the-fish/rounds"+(this.exists?"/"+this.data.id:"")}}flarum.reg.add("xxb-catch-the-fish","forum/models/Round",v);const y=flarum.reg.get("core","common/extend"),x=flarum.reg.get("core","forum/components/HeaderPrimary");var F=a.n(x);const w=flarum.reg.get("core","common/utils/extractText");var k=a.n(w);const T="xxb-catch-the-fish.forum.fish-image.";class R{view(t){const a=t.attrs.fish.image_url();return a?m("img.catchthefish-image",{alt:k()(e().translator.trans(T+"alt",{name:t.attrs.fish.name()})),src:a,style:{animationDuration:t.attrs.animationDuration||"10s"},draggable:!1}):m(".catchthefish-no-image",e().translator.trans(T+"missing"))}}flarum.reg.add("xxb-catch-the-fish","forum/components/FishImage",R);const P="xxb-catch-the-fish.forum.basket.";class _{view(){if(!e().session||!e().session.user)return m("div");const t=e().session.user.catchTheFishBasket();if(!t)return m("div");const a=t.filter(t=>t.canPlace());return 0===a.length?m("div"):m(".catchthefish-basket",[m(".catchthefish-basket-title",e().translator.trans(P+"title")),m("p",e().translator.trans(P+"drag-help")),a.map(t=>m(".catchthefish-basket-entry",[m(".catchthefish-basket-fish",{className:e().catchTheFishSelectedFishId===t.id()?"active":"",draggable:!0,onclick(){e().catchTheFishSelectedFishId=e().catchTheFishSelectedFishId===t.id()?null:t.id()},ondragstart(a){a.dataTransfer&&(e().draggedFishId=t.id(),a.dataTransfer.setData("text/plain","fish:"+t.id()))}},m(R,{fish:t})),m(".catchthefish-basket-time",e().translator.trans(P+"time",{time:dayjs(t.placeUntil()).fromNow()}))]))])}}flarum.reg.add("xxb-catch-the-fish","forum/components/Basket",_);const B=flarum.reg.get("core","forum/components/CommentPost");var D=a.n(B);const A=flarum.reg.get("core","forum/components/UserCard");var N=a.n(A);const M=flarum.reg.get("core","forum/components/DiscussionHero");var O=a.n(M);class S{view(){return m(".catchthefish-drop-area",e().translator.trans("xxb-catch-the-fish.forum.drop-area.message"))}}flarum.reg.add("xxb-catch-the-fish","forum/components/DropArea",S);const I=flarum.reg.get("core","common/utils/classList");var C=a.n(I);const E=flarum.reg.get("core","common/components/Modal");var U=a.n(E);const j=flarum.reg.get("core","common/components/Button");var q=a.n(j);const L=flarum.reg.get("core","common/components/Link");var G=a.n(L);const Y=flarum.reg.get("core","common/components/Avatar");var W=a.n(Y);const z=flarum.reg.get("core","common/helpers/username");var H=a.n(z);class J{view(t){const a=t.attrs.user;return m(G(),{href:e().route.user(a)},[m(W(),{user:a})," ",H()(a)])}}flarum.reg.add("xxb-catch-the-fish","forum/components/User",J);const K="xxb-catch-the-fish.forum.caught-fish-modal.";class Q extends(U()){constructor(){super(...arguments),p(this,"newName",void 0),p(this,"dirty",!1),p(this,"loading",!1)}oninit(t){super.oninit(t),this.newName=this.attrs.fish.name()}className(){return"Modal--small catchthefish-catch-modal"}title(){return e().translator.trans(K+"title")}saveNameAndPlacement(t){void 0===t&&(t=!1);const a={};this.dirty&&(a.name=this.newName),t&&(a.placement="random"),a?(this.loading=!0,e().request({method:"POST",url:e().forum.attribute("apiUrl")+"/catch-the-fish/fishes/"+this.attrs.fish.id()+"/place",body:a}).then(a=>{e().store.pushPayload(a),this.hide(),this.attrs.fish.canPlace()&&!t&&e().store.find("users",e().session.user.id()).then(()=>{m.redraw()})}).catch(t=>{throw this.loading=!1,m.redraw(),t})):(this.hide(),this.attrs.fish.canPlace()&&!t&&e().store.find("users",e().session.user.id()).then(()=>{m.redraw()}))}content(){var t;const a=this.attrs.fish,s=a.namedBy(),r=a.placedBy();return m(".Modal-body",[m("h3",'"'+a.name()+'"'),m(R,{fish:a}),s?m("p",[e().translator.trans(K+"named-by")," ",m(J,{user:s})]):null,r?m("p",[e().translator.trans(K+"placed-by")," ",m(J,{user:r})]):null,m("p",e().translator.trans(K+"congratulation",{catch_count:(()=>{const t=a.round(),e=t&&t.myRanking?t.myRanking():null;return t&&"function"==typeof t.my_catch_count?t.my_catch_count():e?("function"==typeof e.catch_count?e.catch_count():e.data&&e.data.attributes&&e.data.attributes.catch_count||e.catch_count||0):0})()})),a.canName()?m(".Form-group",[m("p",e().translator.trans(K+"name-help")),m("label",e().translator.trans(K+"name")),m("input.FormControl",{value:this.newName,oninput:t=>{this.newName=t.target.value,this.dirty=!0}})]):null,a.canPlace()?m("p",e().translator.trans(K+"placement-help")):null,m(".Form-group",q().component({className:"Button Button--primary Button--block",type:"button",loading:this.loading,onclick:()=>{this.saveNameAndPlacement()}},e().translator.trans(K+(this.dirty?a.canPlace()?"submit-name-place-later":"submit-name":a.canPlace()?"submit-place-later":"submit-continue")))),a.canPlace()?m(".Form-group",q().component({className:"Button Button--primary Button--block",type:"button",loading:this.loading,onclick:()=>{this.saveNameAndPlacement(!0)}},e().translator.trans(K+(this.dirty?"submit-name-place-random":"submit-place-random")))):null])}onsubmit(t){t.preventDefault(),this.saveNameAndPlacement()}}flarum.reg.add("xxb-catch-the-fish","forum/modals/CaughtFishModal",Q);class V{constructor(){p(this,"reverseAnimation",void 0),p(this,"animationDuration",void 0)}oninit(){this.reverseAnimation=Math.random()>.5,this.animationDuration=5+Math.floor(70*Math.random())/10+"s"}view(t){const a=t.attrs.fish;return m(".catchthefish-moving-fish",{className:C()({"catchthefish-animate-flip":e().forum.catchTheFishAnimateFlip(),"catchthefish-animate-reverse":this.reverseAnimation}),style:{animationDuration:this.animationDuration},onclick:()=>{a.canCatch()||e().session.user?e().request({method:"POST",url:e().forum.attribute("apiUrl")+"/catch-the-fish/fishes/"+a.id()+"/catch",body:a.placement()}).then(a=>{e().modal.show(Q,{fish:e().store.pushPayload(a)}),t.attrs.oncatch&&t.attrs.oncatch()}):alert(e().translator.trans("xxb-catch-the-fish.forum.moving-fish.login"))}},[m(".catchthefish-name",a.name()),m(R,{fish:a,animationDuration:this.animationDuration})])}}function X(t){if(!t.dataTransfer)return null;const e=t.dataTransfer.getData("text/plain"),a=/^fish:([0-9]+)$/.exec(e);return a?a[1]:null}function $(){return e().draggedFishId||e().catchTheFishSelectedFishId||null}function te(t,a){const s=$();if(!s)return;const r=e().store.getById("catchthefish-fishes",s);if(r){const s={};s[a+"_id"]=t.id(),e().request({method:"POST",url:e().forum.attribute("apiUrl")+"/catch-the-fish/fishes/"+r.id()+"/place",body:{placement:s}}).then(t=>{e().store.pushPayload(t),e().draggedFishId=null,e().catchTheFishSelectedFishId=null,e().store.find("users",e().session.user.id()).then(()=>{m.redraw()})})}else alert(e().translator.trans("xxb-catch-the-fish.forum.drop-area.missing-from-store"))}function Z(t,a){const s=[];(t||e().catchTheFishSelectedFishId)&&s.push(m(S));const r=a.catchTheFishFishes();return r&&r.forEach(t=>{t.canSee()&&s.push(m(V,{fish:t,oncatch:()=>{a.pushData({relationships:{catchTheFishFishes:{data:a.data.relationships.catchTheFishFishes.data.filter(e=>e.id!==t.id())}}})}}))}),s}function tt(t,a){t.ondrop=t=>{this.fishDragOver=!1;const s=e().draggedFishId||X(t);if(s){t.preventDefault();const r=e().store.getById("catchthefish-fishes",s);if(r){const t={};t[a+"_id"]=this.attrs[a].id(),e().request({method:"POST",url:e().forum.attribute("apiUrl")+"/catch-the-fish/fishes/"+r.id()+"/place",body:{placement:t}}).then(t=>{e().store.pushPayload(t),e().draggedFishId=null,e().catchTheFishSelectedFishId=null,e().store.find("users",e().session.user.id()).then(()=>{m.redraw()})})}else alert(e().translator.trans("xxb-catch-the-fish.forum.drop-area.missing-from-store"))}},t.onclick=t=>{e().catchTheFishSelectedFishId&&(t.preventDefault(),t.stopPropagation(),te(this.attrs[a],a))},t.ondragover=t=>{e().draggedFishId||X(t)?(t.preventDefault(),t.dataTransfer.dropEffect="move",this.fishDragOver?t.redraw=!1:(this.fishDragOver=!0,m.redraw())):(t.dataTransfer&&t.dataTransfer.types.includes("text/plain")&&t.preventDefault(),t.redraw=!1)},t.ondragenter=t=>{t.preventDefault(),t.redraw=!1},t.ondragleave=t=>{this.fishDragOver?(this.fishDragOver=!1,m.redraw()):t.redraw=!1}}function et(t,e,a){"content"===e?(0,y.override)(t,e,function(t){return t().concat(Z(this.fishDragOver,this.attrs[a]))}):(0,y.extend)(t,e,function(t){t.add("catchthefish-fish-and-drop",Z(this.fishDragOver,this.attrs[a]))}),(0,y.extend)(t,"oninit",function(){this.fishDragOver=!1,this.subtree&&this.subtree.check(()=>this.fishDragOver)}),"content"===e?(0,y.extend)(t,"elementAttrs",function(t){tt.bind(this)(t,a)}):(0,y.extend)(t,"view",function(t){t.attrs=t.attrs||{},tt.bind(this)(t.attrs,a)})}flarum.reg.add("xxb-catch-the-fish","forum/components/MovingFish",V);const at=flarum.reg.get("core","common/components/Page");var st=a.n(at);const rt="xxb-catch-the-fish.forum.table-ranking.";class nt{constructor(){p(this,"rankings",null)}oninit(t){e().request({method:"GET",url:e().forum.attribute("apiUrl")+"/catch-the-fish/rounds/"+t.attrs.round.id()+"/rankings"}).then(t=>{this.rankings=e().store.pushPayload(t),m.redraw()})}view(t){return null===this.rankings?m("p",e().translator.trans(rt+"loading")):m("div",[m("h2",e().translator.trans(rt+"title",{name:t.attrs.round.name()})),m("table.catchthefish-table",[m("thead",m("tr",[m("th",e().translator.trans(rt+"rank")),m("th",e().translator.trans(rt+"count")),m("th",e().translator.trans(rt+"user"))])),m("tbody",this.rankings.map((t,e)=>m("tr",[m("td","#"+(e+1)),m("td",t.catch_count()),m("td",m(J,{user:t.user()}))])))])])}}flarum.reg.add("xxb-catch-the-fish","forum/components/RoundRankings",nt);const ot="xxb-catch-the-fish.forum.page-ranking.";class it extends(st()){view(){if(!e().forum.catchTheFishCanSeeRankingsPage())return m(".container",m("p",e().translator.trans(ot+"permission")));const t=e().forum.catchTheFishActiveRounds();return m(".container",[m("h2",e().translator.trans(ot+"title")),t?t.map(t=>m(nt,{round:t})):m("p",e().translator.trans(ot+"nothing"))])}}flarum.reg.add("xxb-catch-the-fish","forum/pages/Rankings",it);const ht=flarum.reg.get("core","common/components/LinkButton");var ct=a.n(ht);const mt=flarum.reg.get("core","common/components/Switch");var ut=a.n(mt);const dt=flarum.reg.get("core","common/utils/withAttr");var lt=a.n(dt);const ft="xxb-catch-the-fish.forum.edit-round.";class pt{constructor(){p(this,"round",void 0),p(this,"dirty",!1),p(this,"processing",!1)}oninit(t){let a=t.attrs.round;void 0===a&&(a=e().store.createRecord("catchthefish-rounds",{attributes:{name:"",starts_at:"",ends_at:dayjs().add(1,"day").toISOString(),include_starting_pack:!0}})),this.round=a}view(t){return m("form",{onsubmit:e=>{e.preventDefault(),this.saveRecord(t)}},[m(".Form-group",[m("label",e().translator.trans(ft+"name")),m("input.FormControl",{value:this.round.name(),oninput:lt()("value",this.updateAttribute.bind(this,"name"))}),m(".helpText",e().translator.trans(ft+"name-help"))]),m(".Form-group",[m("label",e().translator.trans(ft+"starts-at")),m("input.FormControl",{value:this.round.starts_at(),oninput:lt()("value",this.updateAttribute.bind(this,"starts_at"))})]),m(".Form-group",[m("label",e().translator.trans(ft+"ends-at")),m("input.FormControl",{value:this.round.ends_at(),oninput:lt()("value",this.updateAttribute.bind(this,"ends_at"))})]),this.round.exists?"":m(".Form-group",[m("label",[ut().component({state:this.round.include_starting_pack(),onchange:this.updateAttribute.bind(this,"include_starting_pack")},e().translator.trans(ft+"starting-pack"))]),m(".helpText",e().translator.trans(ft+"starting-pack-help"))]),m(".ButtonGroup",[q().component({type:"submit",className:"Button Button--primary",loading:this.processing,disabled:!this.readyToSave()},e().translator.trans(ft+(this.round.exists?"save":"create"))),this.round.exists?q().component({type:"button",className:"Button Button--danger",loading:this.processing,onclick:()=>{this.deleteRecord(t)}},e().translator.trans(ft+"delete")):""])])}updateAttribute(t,e){this.round.pushAttributes({[t]:e}),this.dirty=!0}readyToSave(){return!!this.round.name()&&this.dirty}saveRecord(t){this.processing=!0,this.round.save(this.round.data.attributes).then(()=>{t.attrs.onsave&&t.attrs.onsave(),this.processing=!1,this.dirty=!1,m.redraw()}).catch(t=>{throw this.processing=!1,m.redraw(),t})}deleteRecord(t){confirm(k()(e().translator.trans(ft+"delete-confirmation",{name:this.round.name()})))&&(this.processing=!0,this.round.delete().then(()=>{t.attrs.ondelete&&t.attrs.ondelete(),this.processing=!1,m.redraw()}).catch(t=>{throw this.processing=!1,m.redraw(),t}))}}flarum.reg.add("xxb-catch-the-fish","forum/components/EditRound",pt);class gt extends(U()){className(){return"Modal--small"}title(){return e().translator.trans("xxb-catch-the-fish.forum.new-round-modal.title")}content(){return m(".Modal-body",m(pt,{onsave:()=>{this.hide(),this.attrs.oncreateordelete&&this.attrs.oncreateordelete()}}))}}flarum.reg.add("xxb-catch-the-fish","forum/modals/NewRoundModal",gt);class bt extends(U()){className(){return"Modal--small"}title(){return e().translator.trans("xxb-catch-the-fish.forum.edit-round-modal.title",{name:this.attrs.round.name()})}content(){return m(".Modal-body",m(pt,{round:this.attrs.round,ondelete:()=>{this.hide(),this.attrs.oncreateordelete&&this.attrs.oncreateordelete()}}))}}flarum.reg.add("xxb-catch-the-fish","forum/modals/EditRoundModal",bt);const vt="xxb-catch-the-fish.forum.table-round.";class yt extends(st()){constructor(){super(...arguments),p(this,"rounds",null)}oninit(t){super.oninit(t),this.refreshRounds()}refreshRounds(){this.rounds=null,e().request({method:"GET",url:e().forum.attribute("apiUrl")+"/catch-the-fish/rounds"}).then(t=>{this.rounds=e().store.pushPayload(t),m.redraw()})}view(){return null===this.rounds?m(".container",m("p",e().translator.trans(vt+"loading"))):m(".container",[m("h2",e().translator.trans(vt+"title")),q().component({className:"Button Button--primary",onclick:()=>{e().modal.show(gt,{oncreateordelete:()=>{this.refreshRounds()}})}},e().translator.trans(vt+"new")),m("table.catchthefish-table",[m("thead",m("tr",[m("th",e().translator.trans(vt+"name")),m("th",e().translator.trans(vt+"start")),m("th",e().translator.trans(vt+"end")),m("th",e().translator.trans(vt+"actions"))])),m("tbody",this.rounds.map(t=>m("tr",[m("td",t.name()),m("td",t.starts_at()),m("td",t.ends_at()),m("td",[q().component({className:"Button",onclick:()=>{e().modal.show(bt,{round:t,oncreateordelete:()=>{this.refreshRounds()}})}},e().translator.trans(vt+"edit"))," ",ct().component({className:"Button",href:e().route("catchTheFishRound",{id:t.id()})},e().translator.trans(vt+"fishes"))])])))])])}}flarum.reg.add("xxb-catch-the-fish","forum/pages/RoundList",yt);const xt="xxb-catch-the-fish.forum.edit-fish.";class Ft{constructor(){p(this,"fish",void 0),p(this,"dirty",!1),p(this,"processing",!1)}oninit(t){let a=t.attrs.fish;void 0===a&&(a=e().store.createRecord("catchthefish-fishes",{attributes:{round_id:t.attrs.round.id(),name:""}})),this.fish=a}view(t){return m("form",{onsubmit:e=>{e.preventDefault(),this.saveRecord(t)}},[m(".Form-group",[m("label",e().translator.trans(xt+"name")),m("input.FormControl",{value:this.fish.name(),oninput:t=>{this.fish.pushAttributes({name:t.target.value}),this.dirty=!0}}),m(".helpText",e().translator.trans(xt+"name-help"))]),m(".ButtonGroup",[q().component({type:"submit",className:"Button Button--primary",loading:this.processing,disabled:!this.readyToSave()},e().translator.trans(xt+(this.fish.exists?"save":"create"))),this.fish.exists?q().component({type:"button",className:"Button Button--danger",loading:this.processing,onclick:()=>{this.deleteRecord(t)}},e().translator.trans(xt+"delete")):""])])}readyToSave(){return!!this.fish.name()&&this.dirty}saveRecord(t){this.processing=!0,this.fish.save(this.fish.data.attributes).then(()=>{t.attrs.onsave&&t.attrs.onsave(),this.processing=!1,this.dirty=!1,m.redraw()}).catch(t=>{throw this.processing=!1,m.redraw(),t})}deleteRecord(t){confirm(k()(e().translator.trans(xt+"delete-confirmation",{name:this.fish.name()})))&&(this.processing=!0,this.fish.delete().then(()=>{t.attrs.ondelete&&t.attrs.ondelete(),this.processing=!1,m.redraw()}).catch(t=>{throw this.processing=!1,m.redraw(),t}))}}flarum.reg.add("xxb-catch-the-fish","forum/components/EditFish",Ft);class wt extends(U()){className(){return"Modal--small"}title(){return e().translator.trans("xxb-catch-the-fish.forum.new-fish-modal.title")}content(){return m(".Modal-body",m(Ft,{round:this.attrs.round,onsave:()=>{this.hide(),this.attrs.oncreateordelete&&this.attrs.oncreateordelete()}}))}}flarum.reg.add("xxb-catch-the-fish","forum/modals/NewFishModal",wt);class kt extends(U()){className(){return"Modal--small"}title(){return e().translator.trans("xxb-catch-the-fish.forum.edit-fish-modal.title",{name:this.attrs.fish.name()})}content(){return m(".Modal-body",m(Ft,{fish:this.attrs.fish,ondelete:()=>{this.hide(),this.attrs.oncreateordelete&&this.attrs.oncreateordelete()}}))}}flarum.reg.add("xxb-catch-the-fish","forum/modals/EditFishModal",kt);const Tt="xxb-catch-the-fish.forum.table-fish.";class Rt extends(st()){constructor(){super(...arguments),p(this,"roundId",void 0),p(this,"round",null),p(this,"fishes",null),p(this,"uploading",!1)}oninit(t){super.oninit(t),this.roundId=m.route.param("id"),this.round=e().store.getById("catchthefish-round",this.roundId),this.round||e().store.find("catch-the-fish/rounds",this.roundId).then(t=>{this.round=t,m.redraw()}),this.refreshFishes()}refreshFishes(){this.fishes=null,e().request({method:"GET",url:e().forum.attribute("apiUrl")+"/catch-the-fish/rounds/"+this.roundId+"/fishes"}).then(t=>{this.fishes=e().store.pushPayload(t),m.redraw()})}openPicker(t,e){if(void 0===e&&(e=!1),this.uploading)return;const a=$('<input type="file">');a.attr("multiple",e),a.appendTo("body").hide().click().on("change",e=>{t(e.target.files)})}uploadImages(t,a){const s=new FormData;if(a)s.append("image",t[0]);else for(let e=0;e<t.length;e++)s.append("image"+e,t[e]);this.uploading=!0,m.redraw(),e().request({method:"POST",url:e().forum.attribute("apiUrl")+"/catch-the-fish/"+(a?"fishes/"+a.id()+"/image":"rounds/"+this.roundId+"/fishes-from-images"),serialize:t=>t,body:s}).then(()=>{this.uploading=!1,m.redraw(),this.refreshFishes()}).catch(t=>{throw this.uploading=!1,m.redraw(),t})}view(){return this.round&&null!==this.fishes?m(".container",[m("h2",e().translator.trans(Tt+"title",{name:this.round.name()})),q().component({className:"Button Button--primary",onclick:()=>{e().modal.show(wt,{round:this.round,oncreateordelete:()=>{this.refreshFishes()}})}},e().translator.trans(Tt+"new"))," ",q().component({className:"Button",type:"button",onclick:()=>{this.openPicker(t=>{this.uploadImages(t)},!0)},loading:this.uploading},e().translator.trans(Tt+"new-from-image")),m("table.catchthefish-table",[m("thead",m("tr",[m("th",e().translator.trans(Tt+"image")),m("th",e().translator.trans(Tt+"name")),m("th",e().translator.trans(Tt+"user-name")),m("th",e().translator.trans(Tt+"user-place")),m("th",e().translator.trans(Tt+"placement")),m("th",e().translator.trans(Tt+"actions"))])),m("tbody",0===this.fishes.length?m("tr",[m("td","No fishes")]):this.fishes.map(t=>{const a=t.namedBy(),s=t.placedBy();return m("tr",[m("td",m(R,{fish:t})),m("td",t.name()),m("td",a?m(J,{user:a}):m("em",e().translator.trans(Tt+"no-user-name"))),m("td",s?m(J,{user:s}):m("em",e().translator.trans(Tt+"no-user-place"))),m("td",this.placement(t)),m("td",[q().component({className:"Button",onclick:()=>{e().modal.show(kt,{fish:t,oncreateordelete:()=>{this.refreshFishes()}})}},e().translator.trans(Tt+"edit"))," ",q().component({className:"Button",type:"button",onclick:()=>{this.openPicker(e=>{this.uploadImages(e,t)})},loading:this.uploading},e().translator.trans(Tt+"upload"))])])}))])]):m(".container",m("p",e().translator.trans(Tt+"loading")))}placement(t){const a=t.placementModel();if(a instanceof o())return m(G(),{href:e().route.discussion(a)},a.title());if(a instanceof h()){const t=a.discussion();return m(G(),{href:e().route.post(a)},(t?t.title():"")+" #"+a.number())}return a instanceof u()?m(J,{user:a}):"N/A"}}flarum.reg.add("xxb-catch-the-fish","forum/pages/RoundSettings",Rt);const Pt=flarum.reg.get("core","forum/components/IndexPage");var _t=a.n(Pt);const $t=flarum.reg.get("core","forum/components/IndexSidebar");var zt=a.n($t);const Bt="xxb-catch-the-fish.forum.nav.",Dt="xxb-catch-the-fish.forum.round-alert.";class At{view(t){return m(".Alert.Alert-info",m(".container",[m("span.Alert-body",[e().translator.trans(Dt+"message",{name:t.attrs.round.name(),time:dayjs(t.attrs.round.ends_at()).calendar()})]),e().forum.catchTheFishCanSeeRankingsPage()?m("ul.Alert-controls",m("li",ct().component({href:e().route("catchTheFishRankings")},e().translator.trans(Dt+"rankings")))):null]))}}flarum.reg.add("xxb-catch-the-fish","forum/components/RoundAlert",At);var Nt=a(715),Mt=a.n(Nt);dayjs.extend(Mt()),e().initializers.add("xxb-catch-the-fish",()=>{e().store.models["catchthefish-fishes"]=g,e().store.models["catchthefish-rankings"]=b,e().store.models["catchthefish-rounds"]=v,o().prototype.catchTheFishFishes=r().hasMany("catchTheFishFishes"),h().prototype.catchTheFishFishes=r().hasMany("catchTheFishFishes"),u().prototype.catchTheFishFishes=r().hasMany("catchTheFishFishes"),u().prototype.catchTheFishBasket=r().hasMany("catchTheFishBasket"),l().prototype.catchTheFishActiveRounds=r().hasMany("catchTheFishActiveRounds"),l().prototype.catchTheFishCanModerate=r().attribute("catchTheFishCanModerate"),l().prototype.catchTheFishCanSeeRankingsPage=r().attribute("catchTheFishCanSeeRankingsPage"),l().prototype.catchTheFishAnimateFlip=r().attribute("catchTheFishAnimateFlip"),(()=>{let t=document.querySelector(".catchthefish-basket-root");t||(t=document.createElement("div"),t.className="catchthefish-basket-root",document.body.appendChild(t)),m.mount(t,_)})(),et(D().prototype,"content","post"),et(N().prototype,"infoItems","user"),et(O().prototype,"items","discussion"),(0,y.extend)(N().prototype,"oninit",function(){const t=this.attrs.user;t&&t.exists&&!(t.data.relationships&&t.data.relationships.catchTheFishFishes)&&!t.catchTheFishReloading&&(t.catchTheFishReloading=!0,e().store.find("users",t.id()).then(()=>{m.redraw()}).finally(()=>{t.catchTheFishReloading=!1}))}),document.addEventListener("dragend",()=>{e().draggedFishId=null}),e().routes.catchTheFishRankings={path:"/catch-the-fish",component:it},e().routes.catchTheFishRounds={path:"/catch-the-fish/rounds",component:yt},e().routes.catchTheFishRound={path:"/catch-the-fish/rounds/:id",component:Rt},(0,y.extend)(zt().prototype,"navItems",function(t){e().forum.catchTheFishCanSeeRankingsPage()&&t.add("catchthefish-rankings",ct().component({icon:"fas fa-fish",href:e().route("catchTheFishRankings")},e().translator.trans(Bt+"rankings"))),e().forum.catchTheFishCanModerate()&&t.add("catchthefish-settings",ct().component({icon:"fas fa-fish",href:e().route("catchTheFishRounds")},e().translator.trans(Bt+"settings")))}),(0,y.override)(_t().prototype,"hero",function(t){const a=t();if(!e().forum.attribute("catchTheFishAlertRound"))return a;const s=e().forum.catchTheFishActiveRounds();if(!s)return a;const r=s.map(t=>t?m(At,{round:t}):null);return Array.isArray(a)?s.concat(a):m("div",[r,a])})})})(),module.exports={}})();
//# sourceMappingURL=forum.js.map