import{f as l,g as S,i as o,j as c}from"./chunk-TDIPI4U5.js";import{b as G,q as B}from"./chunk-DKYFV7F2.js";import{W as L,Z as d,ba as p,ga as A,k as r,m as k,x as U}from"./chunk-SBSTEEKM.js";import{a as v,b as j}from"./chunk-FBSYYVFF.js";var F=(()=>{class i{static{this.type="[ADMIN] Get Ctf"}}return i})(),M=(()=>{class i{static{this.type="[ADMIN] Get Selected Ctf"}constructor(t){this.id=t}}return i})(),x=(()=>{class i{static{this.type="[ADMIN] Filter Ctf"}constructor(t){this.filter=t}}return i})(),w=(()=>{class i{static{this.type="[ADMIN] Get All Issues"}}return i})(),T=(()=>{class i{static{this.type="[ADMIN] Get Issues By Enigme Id"}constructor(t){this.enigmeId=t}}return i})(),O=(()=>{class i{static{this.type="[ADMIN] Delete Issue"}constructor(t,s){this.issueId=t,this.enigmeId=s}}return i})();function R(i,e){let t=i.name;return typeof t=="string"?t:t.find(s=>s.language===e)?.label??t[0]?.label??""}var D=(()=>{class i{constructor(t){this.httpClient=t,this.adminEndpoint=c.baseUrl+"/admin/enigmes",this.issuesEndpoint=c.baseUrl+"/admin/issues",this.partyEndpoint=c.baseUrl+"/admin/party",this.assetsEndpoint=c.baseUrl+"/admin/enigmes/assets",this.assetEndpoint=c.baseUrl+"/admin/asset",this.cacheEndpoint=c.baseUrl+"/admin/cache"}getAllEnigmes(){return this.httpClient.get(this.adminEndpoint)}getEnigmeById(t){return this.httpClient.get(`${this.adminEndpoint}/${t}`)}updateEnigme(t){return this.httpClient.put(this.adminEndpoint,t)}createEnigme(t){return this.httpClient.post(this.adminEndpoint,t)}getAllIssues(){return this.httpClient.get(this.issuesEndpoint)}getIssuesByEnigmeId(t){return this.httpClient.get(`${this.issuesEndpoint}?enigmeId=${t}`)}deleteIssue(t){return this.httpClient.delete(`${this.issuesEndpoint}/${t}`)}getCTFsDoneBySite(t){return this.httpClient.post(this.partyEndpoint,t)}getAllAssets(){return this.httpClient.get(this.assetsEndpoint)}getAssetById(t){return this.httpClient.get(`${this.assetEndpoint}/${t}`)}uploadFile(t,s){let n=new FormData;return n.append("file",t),this.httpClient.post(`${c.baseUrl}/admin/file/${encodeURIComponent(s)}`,n)}createAsset(t){return this.httpClient.post(this.assetEndpoint,t)}getAssetLinks(){return this.httpClient.get(`${c.baseUrl}/admin/link`)}createAssetLink(t,s){let n={id_enigme:s,id_asset:t};return this.httpClient.post(`${c.baseUrl}/admin/link`,n)}deleteAsset(t){return this.httpClient.delete(`${this.assetEndpoint}/${t}`)}deleteAssetLink(t){return this.httpClient.delete(`${c.baseUrl}/admin/link/${t}`)}syncCtfAssetLinks(t,s,n){let h=s.filter(f=>!n.includes(f)),m=n.filter(f=>!s.includes(f));return h.length===0&&m.length===0?k(null):this.getAssetLinks().pipe(L(f=>{let g=f.filter(C=>C.id_enigme===t&&m.includes(C.id_asset)).map(C=>this.deleteAssetLink(C.id)),E=h.map(C=>this.createAssetLink(C,t)),I=[...g,...E];return I.length?U(I):k(null)}))}deleteAssetFromMinio(t){return this.httpClient.delete(`${c.baseUrl}/admin/file/${encodeURIComponent(t)}`)}refreshCache(){return this.httpClient.post(this.cacheEndpoint,null)}static{this.\u0275fac=function(s){return new(s||i)(A(G))}}static{this.\u0275prov=p({token:i,factory:i.\u0275fac,providedIn:"root"})}}return i})();var a=class K{constructor(e,t){this.service=e,this.translate=t}static selectCtfs(e){return e.filteredEnigmes}static selectAllCtfs(e){return e.allEnigmes}static selectSelectedCtf(e){return e.selectedEnigme}static selectAllIssues(e){return e.allIssues}static selectEnigmeIssues(e){return e.enigmeIssues}static selectIssuesCounts(e){return e.issuesCounts}getCtfAdminAction(e){return this.service.getAllEnigmes().pipe(d(t=>{e.patchState({allEnigmes:t?.enigmeList,filteredEnigmes:t?.enigmeList})}))}getSelectedCtfAdminAction(e,t){return this.service.getEnigmeById(t.id).pipe(d(s=>{e.patchState({selectedEnigme:s})}))}filterCtfAfminAction(e,t){let s=e.getState().allEnigmes;e.patchState({filteredEnigmes:s.filter(n=>(!t.filter.type||n.tags.includes(t.filter.type))&&(t.filter.difficulty===null||t.filter.difficulty===void 0||n.difficulty===+t.filter.difficulty)&&(!t.filter.search||R(n,this.translate.getCurrentLang()).toLowerCase().includes(t.filter.search.toLowerCase())))})}getAllIssuesAction(e){return this.service.getAllIssues().pipe(d(t=>{let s={};t&&t.length>0&&t.forEach(n=>{s[n.idEnigme]||(s[n.idEnigme]=0),s[n.idEnigme]++}),e.patchState({allIssues:t||[],issuesCounts:s})}))}getIssuesByEnigmeIdAction(e,t){return this.service.getIssuesByEnigmeId(t.enigmeId).pipe(d(s=>{e.patchState({enigmeIssues:s||[]})}))}deleteIssueAction(e,t){return this.service.deleteIssue(t.issueId).pipe(d(s=>{let n=e.getState(),h=n.enigmeIssues.filter(g=>g.id!==t.issueId),m=v({},n.issuesCounts);m[t.enigmeId]&&m[t.enigmeId]>0&&m[t.enigmeId]--;let f=n.allIssues.filter(g=>g.id!==t.issueId);e.patchState({enigmeIssues:h,allIssues:f,issuesCounts:m})}))}static{this.\u0275fac=function(t){return new(t||K)(A(D),A(B))}}static{this.\u0275prov=p({token:K,factory:K.\u0275fac})}};r([l(F)],a.prototype,"getCtfAdminAction",null);r([l(M)],a.prototype,"getSelectedCtfAdminAction",null);r([l(x)],a.prototype,"filterCtfAfminAction",null);r([l(w)],a.prototype,"getAllIssuesAction",null);r([l(T)],a.prototype,"getIssuesByEnigmeIdAction",null);r([l(O)],a.prototype,"deleteIssueAction",null);r([o()],a,"selectCtfs",null);r([o()],a,"selectAllCtfs",null);r([o()],a,"selectSelectedCtf",null);r([o()],a,"selectAllIssues",null);r([o()],a,"selectEnigmeIssues",null);r([o()],a,"selectIssuesCounts",null);a=r([S({name:"CtfAdminStore",defaults:{selectedEnigme:null,allEnigmes:[],filteredEnigmes:[],allIssues:[],enigmeIssues:[],issuesCounts:{}}})],a);var H=(()=>{class i{static{this.type="[Kpi] Get Kpis"}constructor(t){this.siteId=t}}return i})(),J=(()=>{class i{static{this.type="[Kpi] Sort Kpis"}constructor(t,s){this.columnToOrder=t,this.isOrderingAscending=s}}return i})();var z=(()=>{class i{constructor(t){this.http=t}getKpis(t){return this.http.get(`${c.baseUrl}/admin/indicators/enigme${t&&!isNaN(+t)?"?siteId="+t:""}`)}static{this.\u0275fac=function(s){return new(s||i)(A(G))}}static{this.\u0275prov=p({token:i,factory:i.\u0275fac,providedIn:"root"})}}return i})();var y=class ${constructor(e){this.service=e}static selectUsers(e){return e.users}static selectCtf(e){return e.ctf}getKpisAction(e,t){return this.service.getKpis(t.siteId).pipe(d(s=>{let n=e.getState();e.setState(j(v({},n),{users:s.users,ctf:s.ctf}))}))}sortKpisAction(e,t){let s=e.getState(),n=t.columnToOrder,h=t.isOrderingAscending;return e.setState(j(v({},s),{ctf:s.ctf.sort((m,f)=>{var g=n.split(".")[1];let E=Number(m[g]),I=Number(f[g]);return E==0?1:I==0?-1:h?E-I:I-E})}))}static{this.\u0275fac=function(t){return new(t||$)(A(z))}}static{this.\u0275prov=p({token:$,factory:$.\u0275fac})}};r([l(H)],y.prototype,"getKpisAction",null);r([l(J)],y.prototype,"sortKpisAction",null);r([o()],y,"selectUsers",null);r([o()],y,"selectCtf",null);y=r([S({name:"KpiStore",defaults:{users:0,ctf:[]}})],y);var P=(()=>{class i{static{this.type="[ADMIN] Get Assets"}}return i})(),Q=(()=>{class i{static{this.type="[ADMIN] Get Selected Asset"}constructor(t){this.id=t}}return i})(),V=(()=>{class i{static{this.type="[ADMIN] Add Asset"}constructor(t){this.assetData=t}}return i})(),W=(()=>{class i{static{this.type="[ADMIN] Delete Asset"}constructor(t,s,n){this.id=t,this.assetType=s,this.resource=n}}return i})(),X=(()=>{class i{static{this.type="[ADMIN] Filter Assets"}constructor(t){this.filter=t}}return i})();var u=class N{constructor(e){this.service=e}static selectAssets(e){return e.filteredAssets}static selectSelectedAsset(e){return e.selectedAsset}static selectAllAssets(e){return e.allAssets}getAssetAdminAction(e){return this.service.getAllAssets().pipe(d(t=>{e.patchState({allAssets:t||[],filteredAssets:t||[]})}))}getSelectedAssetAdminAction(e,t){return this.service.getAssetById(t.id).pipe(d(s=>{e.patchState({selectedAsset:s})}))}addAssetAdminAction(e,t){return this.service.createAsset(t.assetData).pipe(d(s=>{let n=e.getState();e.patchState({allAssets:[...n.allAssets,s],filteredAssets:[...n.filteredAssets,s]})}))}deleteAssetAdminAction(e,t){if(t.assetType==="FILE")return this.service.deleteAssetFromMinio(t.resource).pipe(d(()=>{let n=e.getState().allAssets.filter(h=>h.id!==t.id);e.patchState({allAssets:n,filteredAssets:n})}))}filterAssetAdminAction(e,t){let s=e.getState().allAssets;e.patchState({filteredAssets:s.filter(n=>(!t.filter.name||n.name.toLowerCase().includes(t.filter.name.toLowerCase()))&&(!t.filter.type||n.type===t.filter.type))})}static{this.\u0275fac=function(t){return new(t||N)(A(D))}}static{this.\u0275prov=p({token:N,factory:N.\u0275fac})}};r([l(P)],u.prototype,"getAssetAdminAction",null);r([l(Q)],u.prototype,"getSelectedAssetAdminAction",null);r([l(V)],u.prototype,"addAssetAdminAction",null);r([l(W)],u.prototype,"deleteAssetAdminAction",null);r([l(X)],u.prototype,"filterAssetAdminAction",null);r([o()],u,"selectAssets",null);r([o()],u,"selectSelectedAsset",null);r([o()],u,"selectAllAssets",null);u=r([S({name:"AssetAdminStore",defaults:{selectedAsset:null,allAssets:[],filteredAssets:[]}})],u);export{F as a,M as b,x as c,w as d,T as e,O as f,R as g,D as h,a as i,H as j,J as k,y as l,P as m,W as n,u as o}; //# sourceMappingURL=chunk-PG67MSO4.js.map