1import{a as _,r as N,j as e,z as ke,A as ve,s as Xe,I as Ze,a4 as $t,t as Bt,v as Gt,S as Yt,cm as Jt,E as G,e as es,u as ts,b as ss,aK as is,i as qt,p as Wt,M as Xt,d as as}from"./index.C_jEAofg.js";import{r as d,d as ls}from"./reactRouter.C6cvQAHO.js";import{A as os}from"./AccessDenied.Da_IVTEt.js";import{E as dt}from"./EditIcon.C3zEPxhx.js";import{R as ns}from"./RefreshIcon.C6h3Vb3d.js";import{T as Ve}from"./TrashIcon.BeVW0keM.js";import{I as rs}from"./InfoIcon.D6E0BSOK.js";import{I as cs}from"./ImageIcon.CKUsHZmQ.js";import{P as ds}from"./PencilIcon.BnGOw9qe.js";import{Q as us}from"./QuestionmarkCircleIcon.BMQbaPgm.js";import{D as fs}from"./DragHandleIcon.DD8FtFny.js";import{C as me}from"./Select.BO5et_f4.js";import{g as Nt}from"./uploadErrors.BuoBavFt.js";import{t as re,g as X}from"./rateLimitError.ByypYhRt.js";import{D as wt,C as Ct,P as Pt}from"./react-beautiful-dnd.esm.C8pEIkAv.js";import{u as Qt}from"./i18n.BxWiIRpk.js";import{S as ms}from"./ScrollButton.BuRsjz3s.js";import{D as ps}from"./DiscordRolesPopup.Cg3PX91d.js";import{d as Mt,m as Zt}from"./communityTags.D2n_4RPi.js";import{R as gs}from"./RatingInput.DaDmVNeA.js";import"./recharts.DzmhKP_O.js";import"./raf-schd.esm.Do3U_zjQ.js";(function(){try{var o=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};o.SENTRY_RELEASE={id:"aec9389561908f1f1b5366362ca3b629220ab900"},o._sentryModuleMetadata=o._sentryModuleMetadata||{},o._sentryModuleMetadata[new o.Error().stack]=function(m){for(var n=1;n<arguments.length;n++){var A=arguments[n];if(A!=null)for(var i in A)A.hasOwnProperty(i)&&(m[i]=A[i])}return m}({},o._sentryModuleMetadata[new o.Error().stack],{"_sentryBundlerPluginAppKey:tuf-website":!0});var f=new o.Error().stack;f&&(o._sentryDebugIds=o._sentryDebugIds||{},o._sentryDebugIds[f]="77514e24-7e82-4c14-98b7-370569ed6089",o._sentryDebugIdIdentifier="sentry-dbid-77514e24-7e82-4c14-98b7-370569ed6089")}catch{}})();const We={STATIC:"STATIC",CONDITIONAL:"CONDITIONAL"},rt={PASS:"PASS",LEVEL:"LEVEL"},hs=({isOpen:o,onClose:f,isCreating:m,difficulty:n,onSubmit:A,onChange:i,refreshDifficulties:q,error:Z,verifiedPassword:x})=>{const{t:l}=Qt(["components","common"]),[L,M]=d.useState("details"),[E,R]=d.useState([]),[U,ee]=d.useState([]),[te,b]=d.useState(!1),[pe,H]=d.useState(!1),[ce,se]=d.useState(""),[I,ie]=d.useState(""),[Ke,ge]=d.useState(null),[Y,ae]=d.useState(!1),[S,He]=d.useState(null),[De,he]=d.useState(""),[_e,le]=d.useState(!1),[T,de]=d.useState(null),[ye,Ye]=d.useState([]),[V,Re]=d.useState([]),[Ne,Le]=d.useState(""),[ue,Qe]=d.useState("edit"),[Q,Je]=d.useState("edit"),[we,Ce]=d.useState(""),[Pe,be]=d.useState(""),[Me,je]=d.useState(""),[Se,et]=d.useState({}),[fe,tt]=d.useState({}),[u,$]=d.useState(null),[w,xe]=d.useState(null),[Fe,Te]=d.useState(null),[D,oe]=d.useState(null);d.useEffect(()=>{o&&!m&&(Ue(),W(),J())},[o,m]);const Oe=d.useRef(!1);d.useEffect(()=>{o&&!Oe.current?(n!=null&&n.icon?xe(n.icon):xe(null),n!=null&&n.legacyIcon?oe(n.legacyIcon):oe(null),$(null),Te(null),Oe.current=!0):o||(Oe.current=!1,w&&w.startsWith("blob:")&&URL.revokeObjectURL(w),D&&D.startsWith("blob:")&&URL.revokeObjectURL(D))},[o,n==null?void 0:n.icon,n==null?void 0:n.legacyIcon]),d.useEffect(()=>()=>{w&&w.startsWith("blob:")&&URL.revokeObjectURL(w),D&&D.startsWith("blob:")&&URL.revokeObjectURL(D)},[w,D]);const Ue=async()=>{var a;if(n!=null&&n.id){b(!0);try{const t=(await _.get(`${N.database.difficulties.root()}/${n.id}/directives`,{headers:{"X-Super-Admin-Password":x}})).data||[];if(t.length===0){const s={name:"Default Announcement",description:"Announce all clears",mode:We.STATIC,actions:[{channelId:((a=V[0])==null?void 0:a.id)||"",pingType:"NONE",roleId:null}],sortOrder:0,isActive:!0,firstOfKind:!1};R([s]),ee([s])}else{const s=t.map(r=>({...r,firstOfKind:r.firstOfKind??!1,actions:r.actions||[]}));R(s),ee(s)}}catch(c){console.error(c)}finally{b(!1)}}},W=async()=>{try{const a=await _.get(`${N.database.difficulties.root()}/roles`,{headers:{"X-Super-Admin-Password":x}});Ye(a.data||[])}catch(a){console.error("Error loading roles:",a),Ye([])}},J=async()=>{try{const c=(await _.get(`${N.database.difficulties.root()}/channels`,{headers:{"X-Super-Admin-Password":x}})).data||[];if(Re(c),c.length===0){const t={label:"Default Channel",webhookUrl:"",isActive:!0};await _.post(`${N.database.difficulties.root()}/channels`,t,{headers:{"X-Super-Admin-Password":x}});const s=await _.get(`${N.database.difficulties.root()}/channels`,{headers:{"X-Super-Admin-Password":x}});Re(s.data||[])}}catch(a){console.error("Error loading channels:",a),Re([])}},y=(a,c="success")=>{c==="success"?G.success(a):G.error(a)},Ae=()=>{var a;R([...E,{name:"New Directive",description:"",mode:We.STATIC,triggerType:rt.PASS,condition:null,actions:[{channelId:((a=V[0])==null?void 0:a.id)||"",pingType:"NONE",roleId:null}],sortOrder:E.length,isActive:!0,firstOfKind:!1}]),y(l("difficultyPopup.announcements.directive.addSuccess"))},ut=a=>{const c=E.filter((t,s)=>s!==a);R(c),y(l("difficultyPopup.announcements.directive.removeSuccess"))},F=(a,c,t)=>{const s=[...E];if(c.startsWith("condition.")){const r=c.split(".")[1];s[a]={...s[a],condition:{...s[a].condition,[r]:t}}}else if(c.startsWith("actions.")){const[r,g,v]=c.split("."),h=[...s[a].actions];h[g]={...h[g],[v]:t},s[a]={...s[a],actions:h}}else s[a]={...s[a],[c]:t};R(s)},j=async a=>{if(a.preventDefault(),!x){y(l("difficultyPopup.errors.passwordRequired"),"error");return}b(!0);try{const c=E.map(s=>({name:s.name,description:s.description||"",mode:s.mode,triggerType:s.triggerType,condition:s.condition,actions:s.actions.map(r=>({channelId:r.channelId,pingType:r.pingType,roleId:r.roleId})),isActive:s.isActive,firstOfKind:s.firstOfKind})),t=await _.post(`${N.database.difficulties.root()}/${n.id}/directives`,{directives:c},{headers:{"X-Super-Admin-Password":x}});R(t.data),ee(t.data),y(l("difficultyPopup.announcements.notifications.saved"),"success")}catch(c){console.error("Failed to save directives:",c),re(c)||y(l("difficultyPopup.announcements.errors.saveFailed"),"error")}finally{b(!1)}},z=async a=>{var c,t;if(a.preventDefault(),!(!Ke||!(n!=null&&n.id)))try{await _.post(`${N.database.difficulties.root()}/${n.id}/directives`,{directives:Ke},{headers:{"X-Super-Admin-Password":ce}}),ie(""),H(!1),se(""),ge(null),await Ue()}catch(s){re(s)?ie(X(s)):((c=s.response)==null?void 0:c.status)===401||((t=s.response)==null?void 0:t.status)===403?ie(l("difficultyPopup.errors.invalidPassword")):(H(!1),se(""),ge(null)),console.error(s)}},K=a=>
1{if(!a){console.error("Cannot edit channel: channel object is null or undefined"),y(l("difficultyPopup.errors.channelEditFailed"),"error");return}if(!a.id){console.error("Cannot edit channel: channel ID is missing",a),y(l("difficultyPopup.errors.channelEditFailed"),"error");return}try{Qe("edit"),He(a),Ce(a.label||""),be(a.webhookUrl||""),ae(!0)}catch(c){console.error("Error opening channel modal:",c),y(l("difficultyPopup.errors.channelEditFailed"),"error")}},St=a=>{if(!a){console.error("Cannot edit role: role object is null or undefined"),y(l("difficultyPopup.errors.roleEditFailed"),"error");return}if(!a.id){console.error("Cannot edit role: role ID is missing",a),y(l("difficultyPopup.errors.roleEditFailed"),"error");return}try{Je("edit"),de(a),le(!0)}catch(c){console.error("Error opening role modal:",c),y(l("difficultyPopup.errors.roleEditFailed"),"error")}},Tt=()=>{Qe("new"),He({webhookUrl:""}),ae(!0)},Ot=()=>{Je("new"),de({id:"",roleId:"",label:"",messageFormat:null}),le(!0)},st=async a=>{if(a.preventDefault(),!x){y(l("difficultyPopup.errors.passwordRequired"),"error");return}he("");try{ue==="edit"&&S?(await _.put(`${N.database.difficulties.root()}/channels/${S.id}`,{label:we,webhookUrl:Pe},{headers:{"X-Super-Admin-Password":x}}),y(l("difficultyPopup.announcements.channel.notifications.updated"),"success")):(await _.post(`${N.database.difficulties.root()}/channels`,{label:we,webhookUrl:Pe},{headers:{"X-Super-Admin-Password":x}}),y(l("difficultyPopup.announcements.channel.notifications.created"),"success")),await J(),Ce(""),be(""),ae(!1)}catch(c){console.error("Failed to save channel:",c),re(c)||(he(l("difficultyPopup.announcements.channel.errors.saveFailed")),y(l("difficultyPopup.announcements.channel.errors.saveFailed"),"error"))}},it=async a=>{if(a.preventDefault(),!x){y(l("difficultyPopup.errors.passwordRequired"),"error");return}Le("");try{Q==="edit"&&T?(await _.put(`${N.database.difficulties.root()}/roles/${T.id}`,{roleId:T.roleId,label:T.label,messageFormat:T.messageFormat||null},{headers:{"X-Super-Admin-Password":x}}),y(l("difficultyPopup.announcements.role.notifications.updated"),"success")):(await _.post(`${N.database.difficulties.root()}/roles`,{roleId:T.roleId,label:T.label,messageFormat:T.messageFormat||null},{headers:{"X-Super-Admin-Password":x}}),y(l("difficultyPopup.announcements.role.notifications.created"),"success")),await W(),de(null),le(!1)}catch(c){console.error("Failed to save role:",c),re(c)||(Le(l("difficultyPopup.announcements.role.errors.saveFailed")),y(l("difficultyPopup.announcements.role.errors.saveFailed"),"error"))}},at=async()=>{if(!x){y(l("difficultyPopup.errors.passwordRequired"),"error");return}if(S)try{await _.delete(`${N.database.difficulties.root()}/channels/${S.id}`,{headers:{"X-Super-Admin-Password":x}}),y(l("difficultyPopup.announcements.channel.notifications.deleted"),"success"),await J(),ae(!1)}catch(a){console.error("Failed to delete channel:",a),re(a)||y(l("difficultyPopup.announcements.channel.errors.deleteFailed"),"error")}},At=async()=>{if(!x){y(l("difficultyPopup.errors.passwordRequired"),"error");return}if(T)try{await _.delete(`${N.database.difficulties.root()}/roles/${T.id}`,{headers:{"X-Super-Admin-Password":x}}),y(l("difficultyPopup.announcements.role.notifications.deleted"),"success"),await W(),le(!1)}catch(a){console.error("Failed to delete role:",a),re(a)||y(l("difficultyPopup.announcements.role.errors.deleteFailed"),"error")}},lt=a=>{var t;const c=[...E];c[a].actions||(c[a].actions=[]),c[a].actions.push({channelId:((t=V[0])==null?void 0:t.id)||"",pingType:"NONE",roleId:null}),R(c)},Et=(a,c)=>{const t=[...E];t[a].actions=t[a].actions.filter((s,r)=>r!==c),R(t)},ft=a=>l(`difficultyPopup.announcements.condition.type.options.${a}`),mt=a=>l(`difficultyPopup.announcements.condition.operator.options.${a}`),$e=a=>l(`difficultyPopup.announcements.actions.pingType.options.${a}`),ot=a=>{et(c=>({...c,[a]:!c[a]}))},pt=d.useMemo(()=>[{value:"PGU",label:l("difficultyPopup.difficultyTypes.PGU")},{value:"SPECIAL",label:l("difficultyPopup.difficultyTypes.SPECIAL")},{value:"LEGACY",label:l("difficultyPopup.difficultyTypes.LEGACY")}],[ot]),gt=d.useMemo(()=>[{value:We.STATIC,label:l("difficultyPopup.announcements.mode.static")},{value:We.CONDITIONAL,label:l("difficultyPopup.announcements.mode.conditional")}],[l]),ht=d.useMemo(()=>["ACCURACY","WORLDS_FIRST","WORLDS_FIRST_PP","BASE_SCORE","CUSTOM"].map(a=>({value:a,label:ft(a)})),[ft]),yt=d.useMemo(()=>["EQUAL","GREATER_THAN","LESS_THAN","GREATER_THAN_EQUAL","LESS_THAN_EQUAL"].map(a=>({value:a,label:mt(a)})),[mt]),bt=(a,c)=>{const t=U[c];if(!t||!a.actions||!t.actions||a.actions.length!==t.actions.length||a.actions.some((v,h)=>{const O=t.actions[h];return O?Object.keys(v).some(C=>v[C]!==O[C]):!0}))return!0;const r={...a},g={...t};return delete r.actions,delete g.actions,JSON.stringify(r)!==JSON.stringify(g)},It=()=>E.length!==U.length?!0:E.some((a,c)=>bt(a,c)),kt=a=>{const c={name:a.name,description:a.description,mode:a.mode,triggerType:a.triggerType,condition:a.condition,actions:a.actions.map(t=>({channelId:t.channelId,pingType:t.pingType,roleId:t.roleId})),isActive:a.isActive,firstOfKind:a.firstOfKind??!1};navigator.clipboard.writeText(JSON.stringify(c)).then(()=>{y(l("difficultyPopup.announcements.directive.copySuccess"))}).catch(t=>{console.error("Failed to copy directive settings:",t),y(l("difficultyPopup.announcements.directive.copyError"),"error"),je(l("difficultyPopup.announcements.directive.copyError"))})},Dt=(a,c)=>{c.preventDefault();const t=c.clipboardData.getData("text");je("");try{const s=JSON.parse(t);if(!s.name||!s.mode||!s.actions)throw new Error("Invalid directive format");const r=[...E];r[a]={...r[a],name:s.name,description:s.description||"",mode:s.mode,triggerType:s.triggerType||rt.PASS,condition:s.condition,actions:s.actions.map(g=>({channelId:Number(g.channelId),pingType:g.pingType,roleId:g.pingType==="ROLE"?Number(g.roleId):null})),isActive:s.isActive??!0,firstOfKind:s.firstOfKind??!1},R(r),y(l("difficultyPopup.announcements.directive.pasteSuccess"))}catch(s){console.error("Failed to paste directive settings:",s),je(l("difficultyPopup.announcements.directive.pasteError")),y(l("difficultyPopup.announcements.directive.pasteError"),"error")}},Rt=a=>{tt(c=>({...c,[a]:!c[a]}))},Lt=a=>{if(!a.destination)return;const c=Array.from(E),[t]=c.splice(a.source.index,1);c.splice(a.destination.index,0,t);const s=c.map((r,g)=>({...r,sortOrder:g}));R(s)},jt=(a,c=!1)=>{const t=a.target.files[0];if(t){if(!Jt(t.type)){y("Invalid file type. Only JPEG, PNG, WebP, GIF, and SVG files are allowed.","error");return}if(t.size>5*1024*1024){y("File size too large. Maximum size is 5MB.","error");return}if(c){Te(t);const s=new FileReader;s.onload=r=>{oe(r.target.result)},s.readAsDataURL(t)}else{$(t);const s=new FileReader;s.onload=r=>{xe(r.target.result)},s.readAsDataURL(t)}}},Be=(a=!1)=>{a?(Te(null),oe(null),i({...n,legacyIcon:null})):($(null),xe(null),i({...n,icon:null}))},Ee=a=>{if(a.preventDefault(),L==="details"){if(!x){y(l("difficultyPopup.errors.passwordRequired"),"error");return}(async()=>{try{const t=new FormData;n.id!==void 0&&n.id!==null&&n.id!==""&&t.append("id",n.id.toString()),t.append("name",n.name),t.append("type",n.type),t.append("emoji",n.emoji),t.append("color",n.color),t.append("baseScore",n.baseScore.toString()),t.append("legacy",n.legacy),t.append("legacyEmoji",n.legacyEmoji),n.sortOrder!==void 0&&t.append("sortOrder",n.sortOrder.toString()),u?t.append("icon",u):w===null&&n.icon===null?t.append("icon","null"):n.icon&&t.append("icon",n.icon),Fe?t.append("legacyIcon",Fe):D===null&&n.legacyIcon===null?t.append("legacyIcon","null"):n.legacyIcon&&t.append("legacyIcon",n.legacyIcon);const s=await _[m?"post":"put"](`${N.database.difficulties.root()}${m?"":`/${n.id}`}`,t,{headers:{"X-Super-Admin-Password":x,"Content-Type":"multipart/form-data"}});w&&w.startsWith("blob:")&&URL.revokeObjectURL(w),D&&D.startsWith("blob:")&&URL.revokeObjectURL(D),y(l(m?"difficultyPopup.notifications.created":"difficultyPopup.notifications.updated"),"success"),q(s.data),f()}catch(t){if(!re(t)){const s=Nt(t,l(m?"difficultyPopup.errors.createFailed":"difficultyPopup.errors.updateFailed"));y(s,"error")}console.error(t)}})()}else L==="announcements"&&j(a)},ne=()=>{H(!1),se(""),ie(""),ge(null)},Ge=()=>{ae(!1),He(null),Ce(""),be(""),he("")},xt=()=>{le(!1),de(null),Le("")},vt=!!(pe&&!x)||Y||_e;return o?e.jsxs(ke,{onClose:f,closeDisabled:vt,overlayClassName:"difficulty-modal",panelClassName:"difficulty-modal__content",children:[e.jsx(ve,{variant:"floating",className:"difficulty-modal__close-button",onClick:f,"aria-label":l("difficultyPopup.modal.close")}),pe&&!x&&e.jsxs(ke,{onClose:ne,overlayClassName:"difficulty-modal__password-modal",panelClassName:"difficulty-modal__password-modal-content",children:[e.jsx("h3",{children:l("difficultyPopup.modal.password.title")}),e.jsxs("form",{onSubmit:z,children:[e.jsx("div",{className:"difficulty-modal__form-group",children:e.jsx("input",{type:"password",autoComplete:"section-password-super-admin",value:ce,onChange:a=>se(a.target.value),placeholder:l("difficultyPopup.modal.password.placeholder"),required:!0,className:"difficulty-modal__form-input"})}),I&&e.jsx("div",{className:"difficulty-modal__error-message",children:I}),e.jsxs("div",{className:"difficulty-modal__actions",children:[e.jsx("button",{type:"submit",className:"difficulty-modal__button btn-fill-primary",children:l("difficultyPopup.modal.password.confirm")}),e.jsx("button",{type:"button",className:"difficulty-modal__button btn-fill-ghost",onClick:ne,children:l("buttons.cancel",{ns:"common"})})]})]})]}),Y&&e.jsxs(ke,{onClose:Ge,overlayClassName:"difficulty-modal__channel-modal",panelClassName:"difficulty-modal__channel-modal-content",children:[e.jsx("h3",{children:l(ue==="edit"?"difficultyPopup.modal.channel.editTitle":"difficultyPopup.modal.channel.addTitle")}),e.jsxs("form",{onSubmit:st,children:[e.jsxs("div",{className:"difficulty-modal__form-group",children:[e.jsx("label",{className:"difficulty-modal__form-label",children:l("difficultyPopup.modal.channel.label")}),e.jsx("input",{type:"text",value:we,onChange:a=>Ce(a.target.value),placeholder:l("difficultyPopup.modal.channel.labelPlaceholder"),required:!0,className:"difficulty-modal__form-input"})]}),e.jsxs("div",{className:"difficulty-modal__form-group",children:[e.jsx("label",{className:"difficulty-modal__form-label",children:l("difficultyPopup.modal.channel.webhookUrl")}),e.jsx("input",{type:"text",value:Pe,onChange:a=>be(a.target.value),placeholder:l("difficultyPopup.modal.channel.webhookUrlPlaceholder"),required:!0,className:"difficulty-modal__form-input"})]}),De&&e.jsx("div",{className:"difficulty-modal__error-message",children:De}),e.jsxs("div",{className:"difficulty-modal__actions",children:[e.jsx("button",{type:"submit",className:"difficulty-modal__button btn-fill-primary",children:ue==="edit"?l("buttons.save",{ns:"common"}):l("buttons.add",{ns:"common"})}),ue==="edit"&&e.jsx("button",{type:"button",className:"difficulty-modal__button difficulty-modal__button--delete btn-fill-danger",onClick:at,children:l("buttons.delete",{ns:"common"})}),e.jsx("button",{type:"button",className:"difficulty-modal__button btn-fill-ghost",onClick:Ge,children:l("buttons.cancel",{ns:"common"})})]})]})]}),_e&&e.jsxs(ke,{onClose:xt,overlayClassName:"difficulty-modal__role-modal",panelClassName:"difficulty-modal__role-modal-content",children:[e.jsx("h3",{children:l(Q==="edit"?"difficultyPopup.modal.role.editTitle":"difficultyPopup.modal.role.addTitle")}),e.jsxs("form",{onSubmit:it,children:[e.jsxs("div",{className:"difficulty-modal__form-group",children:[e.jsx("label",{className:"difficulty-modal__form-label",children:l("difficultyPopup.modal.role.roleId")}),e.jsx("input",{type:"text",value:(T==null?void 0:T.roleId)||"",onChange:a=>de({...T,roleId:a.target.value}),placeholder:l("difficultyPopup.modal.role.roleIdPlaceholder"),required:!0,className:"difficulty-modal__form-input"})]}),e.jsxs("div",{className:"difficulty-modal__form-group",children:[e.jsx("label",{className:"difficulty-modal__form-label",children:l("difficultyPopup.modal.role.label")}),e.jsx("input",{type:"text",value:(T==null?void 0:T.label)||"",onChange:a=>de({...T,label:a.target.value}),placeholder:l("difficultyPopup.modal.role.labelPlaceholder"),required:!0,className:"difficulty-modal__form-input"})]}),e.jsxs("div",{className:"difficulty-modal__form-group",children:[e.jsxs("label",{className:"difficulty-modal__form-label",children:[l("difficultyPopup.modal.role.messageFormat")||"Message Format",e.jsxs("span",{className:"difficulty-modal__form-label-hint",children:[" ","(",l("difficultyPopup.announcements.directive.optional")||"Optional",")"]})]}),e.jsx("textarea",{value:(T==null?void 0:T.messageFormat)||"",onChange:a=>de({...T,messageFormat:a.target.value||null}),placeholder:l("difficultyPopup.modal.role.messageFormatPlaceholder")||"e.g., {count} {difficultyName} Clears! {ping}",className:"difficulty-modal__form-textarea",rows:3,maxLength:500}),e.jsxs("p",{className:"difficulty-modal__form-hint",children:[l("difficultyPopup.modal.role.messageFormatHint")||"Template for grouped message. Use variables: {count}, {difficultyName}, {ping}, {groupName}. Messages will be grouped by role ID.",e.jsx("br",{}),e.jsx("strong",{children:l("difficultyPopup.announcements.directive.messageFormat.variables")||"Variables:"})," ",l("difficultyPopup.announcements.directive.messageFormat.variablesList")||"{c
1ount}, {difficultyName}, {ping}, {groupName}"]})]}),Ne&&e.jsx("div",{className:"difficulty-modal__error-message",children:Ne}),e.jsxs("div",{className:"difficulty-modal__actions",children:[e.jsx("button",{type:"submit",className:"difficulty-modal__button btn-fill-primary",children:Q==="edit"?l("buttons.save",{ns:"common"}):l("buttons.add",{ns:"common"})}),Q==="edit"&&e.jsx("button",{type:"button",className:"difficulty-modal__button difficulty-modal__button--delete btn-fill-danger",onClick:At,children:l("buttons.delete",{ns:"common"})}),e.jsx("button",{type:"button",className:"difficulty-modal__button btn-fill-ghost",onClick:xt,children:l("buttons.cancel",{ns:"common"})})]})]})]}),e.jsxs("div",{className:"difficulty-modal__tabs",children:[e.jsx("button",{className:`difficulty-modal__tab-button ${L==="details"?"difficulty-modal__tab-button--active":""}`,onClick:()=>M("details"),children:l("difficultyPopup.tabs.details")}),!m&&e.jsx("button",{className:`difficulty-modal__tab-button ${L==="announcements"?"difficulty-modal__tab-button--active":""}`,onClick:()=>M("announcements"),children:l("difficultyPopup.tabs.announcement")})]}),e.jsx("div",{className:"difficulty-modal__content-scroll",children:L==="details"?e.jsxs("form",{onSubmit:Ee,children:[e.jsx("h2",{className:"difficulty-modal__title",children:l(m?"difficultyPopup.modal.create.title":"difficultyPopup.modal.edit.title")}),e.jsxs("div",{className:"difficulty-modal__form-group",children:[e.jsxs("label",{className:"difficulty-modal__form-label",children:[l("difficultyPopup.form.labels.id"),e.jsxs("span",{className:"difficulty-modal__form-label-hint",children:[" ","(",l("difficultyPopup.form.optional"),")"]})]}),e.jsx("input",{type:"number",value:n.id||"",onChange:a=>i({...n,id:a.target.value?parseInt(a.target.value):void 0}),disabled:!m,placeholder:m?l("difficultyPopup.form.placeholders.id"):"",className:"difficulty-modal__form-input"}),m&&e.jsx("p",{className:"difficulty-modal__help-text",children:l("difficultyPopup.form.helpText.id")})]}),e.jsxs("div",{className:"difficulty-modal__form-group",children:[e.jsx("label",{className:"difficulty-modal__form-label",children:l("difficultyPopup.form.labels.name")}),e.jsx("input",{type:"text",value:n.name,onChange:a=>i({...n,name:a.target.value}),required:!0,className:"difficulty-modal__form-input"})]}),e.jsx("div",{className:"difficulty-modal__form-group",children:e.jsx(me,{label:l("difficultyPopup.form.labels.type"),options:pt,value:pt.find(a=>a.value===n.type),onChange:a=>i({...n,type:a.value}),width:"100%"})}),e.jsxs("div",{className:"difficulty-modal__form-group",children:[e.jsx("label",{className:"difficulty-modal__form-label",children:l("difficultyPopup.form.labels.icon")}),e.jsxs("div",{className:"difficulty-modal__icon-upload",children:[w&&e.jsxs("div",{className:"difficulty-modal__icon-preview",children:[e.jsx("img",{src:Xe(w,Ze.MEDIUM),alt:"Icon preview",className:"difficulty-modal__icon-preview-img"}),e.jsx("button",{type:"button",onClick:()=>Be(!1),className:"difficulty-modal__icon-remove",children:"â"})]}),e.jsx("input",{type:"file",accept:$t,onChange:a=>jt(a,!1),className:"difficulty-modal__file-input",id:"icon-upload"}),e.jsx("label",{htmlFor:"icon-upload",className:"difficulty-modal__file-label",children:l(w?"difficultyPopup.form.icon.change":"difficultyPopup.form.icon.select")})]}),e.jsx("p",{className:"difficulty-modal__help-text",children:l("difficultyPopup.form.icon.help")})]}),e.jsxs("div",{className:"difficulty-modal__form-group",children:[e.jsx("label",{className:"difficulty-modal__form-label",children:l("difficultyPopup.form.labels.legacyIcon")}),e.jsxs("div",{className:"difficulty-modal__icon-upload",children:[D&&e.jsxs("div",{className:"difficulty-modal__icon-preview",children:[e.jsx("img",{src:Xe(D,Ze.MEDIUM),alt:"Legacy icon preview",className:"difficulty-modal__icon-preview-img"}),e.jsx("button",{type:"button",onClick:()=>Be(!0),className:"difficulty-modal__icon-remove",children:"â"})]}),e.jsx("input",{type:"file",accept:$t,onChange:a=>jt(a,!0),className:"difficulty-modal__file-input",id:"legacy-icon-upload"}),e.jsx("label",{htmlFor:"legacy-icon-upload",className:"difficulty-modal__file-label",children:l(D?"difficultyPopup.form.legacyIcon.change":"difficultyPopup.form.legacyIcon.select")})]}),e.jsx("p",{className:"difficulty-modal__help-text",children:l("difficultyPopup.form.legacyIcon.help")})]}),e.jsxs("div",{className:"difficulty-modal__form-group",children:[e.jsx("label",{className:"difficulty-modal__form-label",children:l("difficultyPopup.form.labels.emoji")}),e.jsx("input",{type:"text",value:n.emoji,onChange:a=>i({...n,emoji:a.target.value}),required:!0,className:"difficulty-modal__form-input"})]}),e.jsxs("div",{className:"difficulty-modal__form-group",children:[e.jsx("label",{className:"difficulty-modal__form-label",children:l("difficultyPopup.form.labels.legacyEmoji")}),e.jsx("input",{type:"text",value:n.legacyEmoji,onChange:a=>i({...n,legacyEmoji:a.target.value}),className:"difficulty-modal__form-input"})]}),e.jsxs("div",{className:"difficulty-modal__form-group",children:[e.jsx("label",{className:"difficulty-modal__form-label",children:l("difficultyPopup.form.labels.color")}),e.jsxs("div",{className:"difficulty-modal__color-input-container",children:[e.jsx("input",{type:"color",value:n.color,onChange:a=>i({...n,color:a.target.value}),required:!0,className:"difficulty-modal__color-picker"}),e.jsx("input",{type:"text",value:n.color,onChange:a=>i({...n,color:a.target.value}),pattern:"^#[0-9A-Fa-f]{6}$",placeholder:l("difficultyPopup.form.placeholders.color"),required:!0,className:"difficulty-modal__form-input"})]})]}),e.jsxs("div",{className:"difficulty-modal__form-group",children:[e.jsx("label",{className:"difficulty-modal__form-label",children:l("difficultyPopup.form.labels.baseScore")}),e.jsx("input",{type:"number",step:"0.01",value:n.baseScore,onChange:a=>i({...n,baseScore:parseFloat(a.target.value)}),required:!0,className:"difficulty-modal__form-input"})]}),e.jsxs("div",{className:"difficulty-modal__form-group",children:[e.jsx("label",{className:"difficulty-modal__form-label",children:l("difficultyPopup.form.labels.legacy")}),e.jsx("input",{type:"text",value:n.legacy,onChange:a=>i({...n,legacy:a.target.value}),className:"difficulty-modal__form-input"})]}),Z&&e.jsx("div",{className:"difficulty-modal__error-message",children:Z}),e.jsxs("div",{className:"difficulty-modal__actions",children:[e.jsx("button",{type:"submit",className:"difficulty-modal__button btn-fill-primary",children:m?l("buttons.create",{ns:"common"}):l("buttons.save",{ns:"common"})}),e.jsx("button",{type:"button",className:"difficulty-modal__button btn-fill-ghost",onClick:f,children:l("buttons.cancel",{ns:"common"})})]})]}):L==="announcements"?e.jsxs("div",{className:"difficulty-modal__announcements",children:[e.jsx("h2",{className:"difficulty-modal__title",children:l("difficultyPopup.announcements.title",{diffName:n.name})}),te?e.jsx("div",{className:"difficulty-modal__loading-message",children:l("difficultyPopup.loading.directives")}):e.jsxs("form",{onSubmit:Ee,children:[e.jsx("div",{className:"difficulty-modal__directives-list",children:e.jsx(wt,{onDragEnd:Lt,children:e.jsx(Ct,{droppableId:"directives",children:a=>e.jsxs("div",{...a.droppableProps,ref:a.innerRef,className:"difficulty-modal__directives-container",children:[E.map((c,t)=>e.jsx(Pt,{draggableId:`directive-${t}`,index:t,children:(s,r)=>{var g,v,h,O,C,B;return e.jsxs("div",{ref:s.innerRef,...s.draggableProps,className:`difficulty-modal__directive-item ${r.isDragging?"difficulty-modal__directive-item--dragging":""}`,children:[e.jsxs("div",{className:"difficulty-modal__directive-header",children:[e.jsxs("div",{className:"difficulty-modal__directive-header-left",children:[e.jsx("div",{...s.dragHandleProps,className:"difficulty-modal__drag-handle",children:e.jsx(fs,{})}),e.jsx("button",{type:"button",className:`difficulty-modal__expand-button ${Se[t]?"expanded":""}`,onClick:p=>{p.preventDefault(),p.stopPropagation(),ot(t)},"aria-label":Se[t]?"Collapse directive":"Expand directive",children:e.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M6 9L12 15L18 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),e.jsx("h3",{className:"difficulty-modal__directive-title",children:c.name})]}),e.jsxs("div",{className:"difficulty-modal__directive-status",children:[bt(c,t)?e.jsx(e.Fragment,{children:e.jsx(ds,{className:"difficulty-modal__directive-edit-icon"})}):e.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"difficulty-modal__directive-check-icon",children:e.jsx("path",{d:"M20 6L9 17L4 12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),E.length>1&&e.jsx("button",{type:"button",className:"difficulty-modal__directive-remove-button",onClick:()=>ut(t),"aria-label":l("difficultyPopup.announcements.directive.remove"),children:e.jsx(Ve,{color:"#f55",size:"1.5rem"})})]})]}),e.jsx(Bt,{open:!!Se[t],onOpenChange:p=>et(k=>({...k,[t]:p})),revealOverflow:!0,duration:"0.3s",children:e.jsx(Gt,{children:e.jsxs("div",{className:"difficulty-modal__directive-content",children:[e.jsxs("div",{className:"difficulty-modal__directive-actions",children:[e.jsx("button",{type:"button",className:"difficulty-modal__directive-copy-button",onClick:()=>kt(c),"aria-label":l("difficultyPopup.announcements.directive.copy"),children:e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("path",{d:"M8 4V16C8 17.1046 8.89543 18 10 18H18C19.1046 18 20 17.1046 20 16V7.24162C20 6.7034 19.7831 6.18861 19.4 5.8L16.2 2.6C15.8114 2.21687 15.2966 2 14.7584 2H10C8.89543 2 8 2.89543 8 4Z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M16 18V20C16 21.1046 15.1046 22 14 22H6C4.89543 22 4 21.1046 4 20V8C4 6.89543 4.89543 6 6 6H8",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})}),e.jsx("div",{className:"difficulty-modal__directive-paste-container",children:e.jsx("input",{type:"text",className:"difficulty-modal__directive-paste-input",placeholder:l("difficultyPopup.announcements.directive.paste"),onPaste:p=>Dt(t,p)})}),Me&&e.jsx("div",{className:"difficulty-modal__paste-error",children:Me})]}),e.jsxs("div",{className:"difficulty-modal__form-group",children:[e.jsx("label",{className:"difficulty-modal__form-label",children:l("difficultyPopup.announcements.directive.name")}),e.jsx("input",{type:"text",value:c.name,onChange:p=>F(t,"name",p.target.value),required:!0,className:"difficulty-modal__form-input"})]}),e.jsx("div",{className:"difficulty-modal__form-group",children:e.jsx(me,{label:l("difficultyPopup.announcements.mode.label"),options:gt,value:gt.find(p=>p.value===c.mode),onChange:p=>{const k=p.value,P={...c,mode:k,...k===We.CONDITIONAL&&!c.condition?{condition:{type:"ACCURACY",value:0,operator:"GREATER_THAN_EQUAL"}}:{}};R(nt=>{const qe=[...nt];return qe[t]=P,qe})},width:"100%"})}),e.jsx("div",{className:"difficulty-modal__form-group",children:e.jsx(Yt,{currentState:c.triggerType||rt.PASS,states:[rt.PASS,rt.LEVEL],onChange:p=>F(t,"triggerType",p),width:60,label:l("difficultyPopup.announcements.directive.triggerType")})}),e.jsxs("div",{className:"difficulty-modal__form-group",children:[e.jsx("label",{className:"difficulty-modal__form-label",children:l("difficultyPopup.announcements.directive.de
1scription")}),e.jsx("textarea",{value:c.description,onChange:p=>F(t,"description",p.target.value),className:"difficulty-modal__form-textarea"})]}),c.mode===We.CONDITIONAL&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"difficulty-modal__form-group",children:e.jsx(me,{label:l("difficultyPopup.announcements.condition.type.label"),options:ht,value:ht.find(p=>{var k;return p.value===(((k=c.condition)==null?void 0:k.type)||"ACCURACY")}),onChange:p=>F(t,"condition.type",p.value),width:"100%"})}),(((g=c.condition)==null?void 0:g.type)==="ACCURACY"||((v=c.condition)==null?void 0:v.type)==="BASE_SCORE")&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"difficulty-modal__form-group",children:e.jsx(me,{label:l("difficultyPopup.announcements.condition.operator.label"),options:yt,value:yt.find(p=>{var k;return p.value===(((k=c.condition)==null?void 0:k.operator)||"GREATER_THAN_EQUAL")}),onChange:p=>F(t,"condition.operator",p.value),width:"100%"})}),e.jsxs("div",{className:"difficulty-modal__form-group",children:[e.jsx("label",{className:"difficulty-modal__form-label",children:l("difficultyPopup.announcements.condition.value")}),e.jsx("input",{type:"number",step:"0.01",value:(h=c.condition)==null?void 0:h.value,onChange:p=>F(t,"condition.value",parseFloat(p.target.value)),required:!0,className:"difficulty-modal__form-input"})]})]}),((O=c.condition)==null?void 0:O.type)==="CUSTOM"&&e.jsxs("div",{className:"difficulty-modal__form-group",children:[e.jsxs("div",{className:"difficulty-modal__custom-function-header",children:[e.jsx("label",{className:"difficulty-modal__form-label",children:l("difficultyPopup.announcements.condition.customFunction")}),e.jsx("button",{type:"button",className:"difficulty-modal__help-button","aria-label":"Show custom function help",children:e.jsx(us,{color:"#fff",size:"24px"})})]}),e.jsx("textarea",{value:((C=c.condition)==null?void 0:C.customFunction)||"",onChange:p=>F(t,"condition.customFunction",p.target.value),required:!0,className:"difficulty-modal__form-textarea"})]})]}),e.jsxs("div",{className:"difficulty-modal__actions-section",children:[e.jsxs("div",{className:"difficulty-modal__actions-header",children:[e.jsx("h4",{className:"difficulty-modal__actions-title",children:l("difficultyPopup.announcements.actions.title")}),e.jsx("button",{type:"button",className:`difficulty-modal__expand-button ${fe[t]?"expanded":""}`,onClick:p=>{p.preventDefault(),p.stopPropagation(),Rt(t)},"aria-label":fe[t]?"Collapse actions":"Expand actions",children:e.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M6 9L12 15L18 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),e.jsx(Bt,{open:!!fe[t],onOpenChange:p=>tt(k=>({...k,[t]:p})),revealOverflow:!0,duration:"0.3s",children:e.jsx(Gt,{children:e.jsxs("div",{className:"difficulty-modal__actions-content",children:[(B=c==null?void 0:c.actions)==null?void 0:B.map((p,k)=>e.jsxs("div",{className:"difficulty-modal__action-item",children:[e.jsx("button",{type:"button",className:"difficulty-modal__action-remove-button",onClick:()=>Et(t,k),"aria-label":l("difficultyPopup.announcements.actions.remove"),children:e.jsx(Ve,{color:"#f55",size:"1.2rem"})}),e.jsxs("div",{className:"difficulty-modal__form-group",children:[e.jsx("label",{className:"difficulty-modal__form-label",children:l("difficultyPopup.announcements.actions.channel",{returnObjects:!0}).label}),e.jsxs("div",{className:"difficulty-modal__select-with-edit",children:[e.jsx(me,{width:"100%",value:V.find(P=>P.id===p.channelId)||null,onChange:P=>{P.value==="add_new"?Tt():F(t,`actions.${k}.channelId`,P.value)},options:[...V.map(P=>({value:P.id,label:P.label})),{value:"add_new",label:`+ ${l("difficultyPopup.announcements.actions.channel.add")}`}]}),p.channelId&&!["EVERYONE","NONE"].includes(p.channelId)&&e.jsx("button",{type:"button",className:"difficulty-modal__select-edit-button",onClick:P=>{P.preventDefault(),P.stopPropagation();const nt=V.find(qe=>qe.id===p.channelId);K(nt)},"aria-label":l("difficultyPopup.announcements.actions.channel.edit"),children:e.jsx(dt,{className:"difficulty-modal__select-edit-button-icon"})})]})]}),e.jsxs("div",{className:"difficulty-modal__form-group",children:[e.jsx("label",{className:"difficulty-modal__form-label",children:l("difficultyPopup.announcements.actions.pingType",{returnObjects:!0}).label}),e.jsx(me,{value:{value:p.pingType,label:$e(p.pingType)},onChange:P=>F(t,`actions.${k}.pingType`,P.value),options:["NONE","ROLE","EVERYONE"].map(P=>({value:P,label:$e(P)})),width:"100%"})]}),p.pingType==="ROLE"&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"difficulty-modal__form-group",children:[e.jsx("label",{className:"difficulty-modal__form-label",children:l("difficultyPopup.announcements.actions.role",{returnObjects:!0}).label}),e.jsxs("div",{className:"difficulty-modal__select-with-edit",children:[e.jsx(me,{value:ye.find(P=>P.id===p.roleId)||null,onChange:P=>{P.value==="add_new"?Ot():F(t,`actions.${k}.roleId`,P.value)},options:[...ye.map(P=>({value:P.id,label:P.label})),{value:"add_new",label:`+ ${l("difficultyPopup.announcements.actions.role.add")}`}],width:"100%"}),p.roleId&&p.roleId!=="EVERYONE"&&e.jsx("button",{type:"button",className:"difficulty-modal__select-edit-button",onClick:P=>{P.preventDefault(),P.stopPropagation();
1const nt=ye.find(qe=>qe.id===p.roleId);St(nt)},"aria-label":l("difficultyPopup.announcements.actions.role.edit"),children:e.jsx(dt,{className:"difficulty-modal__select-edit-button-icon"})})]})]})})]},k)),e.jsx("button",{type:"button",className:"difficulty-modal__action-add-button",onClick:()=>lt(t),children:l("difficultyPopup.announcements.actions.add")})]})})})]}),e.jsxs("div",{className:"difficulty-modal__form-group-checkbox",children:[e.jsx("input",{type:"checkbox",checked:c.isActive,onChange:p=>F(t,"isActive",p.target.checked),className:"difficulty-modal__form-input-checkbox"}),e.jsx("label",{children:l("difficultyPopup.announcements.directive.isActive")})]}),e.jsxs("div",{className:"difficulty-modal__form-group-checkbox",children:[e.jsx("input",{type:"checkbox",checked:c.firstOfKind,onChange:p=>F(t,"firstOfKind",p.target.checked),className:"difficulty-modal__form-input-checkbox"}),e.jsx("label",{children:l("difficultyPopup.announcements.firstOfKind")})]})]})})})]})}},t)),a.placeholder]})})})}),e.jsx("button",{type:"button",className:"difficulty-modal__directive-add-button",onClick:Ae,children:l("difficultyPopup.announcements.directive.add")}),e.jsxs("div",{className:"difficulty-modal__actions",children:[e.jsx("button",{type:"submit",className:`difficulty-modal__button btn-fill-primary ${It()?"":"difficulty-modal__button--disabled"}`,children:l("buttons.save",{ns:"common"})}),e.jsx("button",{type:"button",className:"difficulty-modal__button btn-fill-ghost",onClick:f,children:l("buttons.cancel",{ns:"common"})})]})]})]}):null})]}):null},ys={description:"",wilsonZ:"",scoreOn:"",scoreOff:"",scoringMode:"",requireTopPlay:"",allowedBands:[]},Ft={name:"",iconFile:null,icon:null,color:"#FF5733",group:"",isCommunity:!1,passWarningEnabled:!0,...ys},Vt=["P","G","U","SPEC"],bs={P:"bandP",G:"bandG",U:"bandU",SPEC:"bandSpec"};function ze(o){return o===!0||o==="true"||o===1||o==="1"?"true":o===!1||o==="false"||o===0||o==="0"?"false":""}function Ut(o={}){return{...o,description:o.description||"",wilsonZ:o.wilsonZ??"",scoreOn:o.scoreOn??"",scoreOff:o.scoreOff??"",scoringMode:o.scoringMode||"",requireTopPlay:ze(o.requireTopPlay),allowedBands:Array.isArray(o.allowedBands)?[...o.allowedBands]:[]}}function zt(o,f){o.append("description",f.description??""),o.append("wilsonZ",f.wilsonZ===0||f.wilsonZ?String(f.wilsonZ):""),o.append("scoreOn",f.scoreOn===0||f.scoreOn?String(f.scoreOn):""),o.append("scoreOff",f.scoreOff===0||f.scoreOff?String(f.scoreOff):""),o.append("scoringMode",f.scoringMode||""),o.append("requireTopPlay",ze(f.requireTopPlay)),o.append("allowedBands",JSON.stringify(Array.isArray(f.allowedBands)?f.allowedBands:[]))}function js(o){return{wilsonZ:o.wilsonZ===0||o.wilsonZ?o.wilsonZ:"",scoreOn:o.scoreOn===0||o.scoreOn?o.scoreOn:"",scoreOff:o.scoreOff===0||o.scoreOff?o.scoreOff:"",scoringMode:o.scoringMode||"",requireTopPlay:ze(o.requireTopPlay),allowedBands:Array.isArray(o.allowedBands)?o.allowedBands:[]}}function xs(o,f){const m=(Array.isArray(o)?[...o]:[]).sort().join(","),n=(Array.isArray(f)?[...f]:[]).sort().join(",");return m===n}function Kt(o){if(o===""||o==null)return null;const f=Number(o);return Number.isFinite(f)&&f>0?f:null}function _t(o){if(o===""||o==null)return null;const f=Number(o);return Number.isFinite(f)&&f>=0&&f<=1?f:null}function vs(o,f){if(!Array.isArray(o)||!f)return null;if(f.groupId!=null){const n=o.find(A=>A.id===f.groupId);if(n)return n}const m=String(f.group||"").trim();return m&&o.find(n=>n.name===m)||null}function _s(o,f,m){const n=m?vs(f,o):null;return{wilsonZ:Kt(o.wilsonZ)??Kt(n==null?void 0:n.wilsonZ)??Mt.wilsonZ,scoreOn:_t(o.scoreOn)??_t(n==null?void 0:n.scoreOn)??Mt.scoreOn,scoreOff:_t(o.scoreOff)??_t(n==null?void 0:n.scoreOff)??Mt.scoreOff}}function Ht({icon:o,onSelectFile:f,onRemove:m,t:n,i18nPrefix:A}){const i=d.useRef(null);return e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:n(`${A}.icon.label`)}),e.jsxs("div",{className:"tag-icon-editor",children:[e.jsx("input",{ref:i,type:"file",accept:$t,className:"tag-icon-editor-input",onChange:q=>{var x;const Z=(x=q.target.files)==null?void 0:x[0];q.target.value="",Z&&f(Z)}}),e.jsx("button",{type:"button",className:"tag-icon-editor-preview",onClick:()=>{var q;return(q=i.current)==null?void 0:q.click()},"aria-label":n(`${A}.icon.preview`),children:o?e.jsx("img",{src:Xe(o,Ze.SMALL),alt:""}):e.jsx(cs,{size:"28px",color:"currentColor"})}),o?e.jsx("button",{type:"button",className:"tag-icon-editor-remove",onClick:m,"aria-label":n(`${A}.icon.remove`),children:e.jsx(Ve,{color:"currentColor",size:"20px"})}):null]})]})}function ct({value:o,onChange:f,t:m,includeDescription:n=!1,includeAssignment:A=!0,inheritFromGroup:i=!1,tagGroups:q=[],inactive:Z=!1}){const x=(b,pe)=>{const H=Array.isArray(o.allowedBands)?o.allowedBands:[],ce=new Set(H);pe==="show"?ce.add(b):ce.delete(b),f({...o,allowedBands:Vt.filter(se=>ce.has(se))})},l=_s(o,q,i),L=Zt(l.wilsonZ,l.scoreOn),M=Zt(l.wilsonZ,l.scoreOff),E=[{value:"",label:m("difficulty.tags.fields.inherit")},{value:"wilson",label:m("difficulty.tags.fields.modeWilson")},{value:"skillset",label:m("difficulty.tags.fields.modeSkillset")}],R=E.find(b=>b.value===(o.scoringMode||""))||E[0],U=i?[{value:"",label:m("difficulty.tags.fields.inherit")},{value:"true",label:m("difficulty.tags.fields.requireTopPlayOn")},{value:"false",label:m("difficulty.tags.fields.requireTopPlayOff")}]:[{value:"false",label:m("difficulty.tags.fields.requireTopPlayOff")},{value:"true",label:m("difficulty.tags.fields.requireTopPlayOn")}],ee=ze(o.requireTopPlay),te=U.find(b=>b.value===ee)||U[0];return e.jsxs(e.Fragment,{children:[n?e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:m("difficulty.tags.fields.description")}),e.jsx("textarea",{value:o.description||"",onChange:b=>f({...o,description:b.target.value}),rows:3})]}):null,A?e.jsxs("div",{className:`form-assignment-fields${Z?" is-inactive":""}`,inert:Z?!0:void 0,children:[e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:m("difficulty.tags.fields.allowedBands")}),e.jsx("p",{className:"form-hint",children:m("difficulty.tags.fields.allowedBandsHint")}),e.jsx("div",{className:"form-group-bands",children:Vt.map(b=>{const pe=Array.isArray(o.allowedBands)&&o.allowedBands.includes(b);return e.jsx(Yt,{currentState:pe?"show":"hide",states:["hide","show"],activeStates:["show"],label:m(`difficulty.tags.fields.${bs[b]}`),onChange:H=>x(b,H)},b)})})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:m("difficulty.tags.fields.scoringMode")}),e.jsx(me,{options:E,value:R,onChange:b=>f({...o,scoringMode:(b==null?void 0:b.value)??""}),width:"100%",direction:"auto",isSearchable:!1})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:m("difficulty.tags.fields.requireTopPlay")}),e.jsx("p",{className:"form-hint",children:m(i?"difficulty.tags.fields.requireTopPlayHint":"difficulty.tags.fields.requireTopPlayGroupHint")}),e.jsx(me,{options:U,value:te,onChange:b=>f({...o,requireTopPlay:(b==null?void 0:b.value)??""}),width:"100%",direction:"auto",isSearchable:!1})]}),e.jsxs("div",{className:"form-group",children:[e.jsxs("div",{className:"form-group-label-with-info",children:[e.jsx("label",{children:m("difficulty.tags.fields.wilsonZ")}),e.jsx("button",{type:"button",className:"form-info-button","data-tooltip-id":"difficulty-wilson-z-info","aria-label":m("difficulty.tags.fields.wilsonZInfoAria"),children:e.jsx(rs,{color:"currentColor",size:16})}),e.jsx(as,{id:"difficulty-wilson-z-info",place:"top",noArrow:!0,style:{zIndex:2e3},children:m("difficulty.tags.fields.wilsonZWeightHint")})]}),e.jsx("p",{className:"form-hint",children:m("difficulty.tags.fields.wilsonZHint")}),e.jsx("input",{type:"number",min:"0.01",step:"0.01",placeholder:m("difficulty.tags.fields.inherit"),value:o.wilsonZ,onChange:b=>f({...o,wilsonZ:b.target.value})})]}),e.jsxs("div",{className:"form-group",children:[e.jsxs("div",{className:"form-group-label-row",children:[e.jsx("label",{children:m("difficulty.tags.fields.scoreOn")}),L!=null?e.jsx("span",{className:"form-hint",children:m("difficulty.tags.fields.reqVotes",{count:L})}):null]}),e.jsx("input",{type:"number",min:"0",max:"1",step:"0.01",placeholder:m("difficulty.tags.fields.inherit"),value:o.scoreOn,onChange:b=>f({...o,scoreOn:b.target.value})})]}),e.jsxs("div",{className:"form-group",children:[e.jsxs("div",{className:"form-group-label-row",children:[e.jsx("label",{children:m("difficulty.tags.fields.scoreOff")}),M!=null?e.jsx("span",{className:"form-hint",children:m("difficulty.tags.fields.reqVotes",{count:M})}):null]}),e.jsx("input",{type:"number",min:"0",max:"1",step:"0.01",placeholder:m("difficulty.tags.fields.inherit"),value:o.scoreOff,onChange:b=>f({...o,scoreOff:b.target.value})})]})]}):null]})}function Ns(){}function Ie({onClose:o,children:f,panelClassName:m="",closeDisabled:n,dismissOnOverlay:A=!0,dismissOnEscape:i=!0,ariaLabelledBy:q,ariaLabel:Z}){return e.jsx(ke,{onClose:o,closeDisabled:n,dismissOnOverlay:A,dismissOnEscape:i,overlayClassName:"difficulty-page difficulty-page__modal",panelClassName:["difficulty-modal-content",m].filter(
1Boolean).join(" "),ariaLabelledBy:q,ariaLabel:Z,children:f})}const Zs=()=>{const{user:o}=es(),{difficulties:f,loading:m,reloadDifficulties:n,setDifficulties:A}=ts(),{t:i}=Qt(["pages","common"]),q=ls(),Z=d.useMemo(()=>ss({title:i("difficulty.meta.title"),description:i("difficulty.meta.description"),pathname:q.pathname,image:"/og-image.jpg",noindex:!0}),[i,q.pathname]),[x,l]=d.useState(!1),[L,M]=d.useState(""),[E,R]=d.useState(null),[U,ee]=d.useState(!1),[te,b]=d.useState(""),[pe,H]=d.useState({type:"",data:null}),[ce,se]=d.useState({id:"",name:"",type:"PGU",icon:"",emoji:"",color:"#ffffff",baseScore:0,legacy:"",legacyIcon:"",legacyEmoji:""}),[I,ie]=d.useState(null),[Ke,ge]=d.useState(!1),[Y,ae]=d.useState(""),[S,He]=d.useState(""),[De,he]=d.useState(!1),[_e,le]=d.useState(null),[T,de]=d.useState(!1),[ye,Ye]=d.useState(!0),[V,Re]=d.useState(!1),[Ne,Le]=d.useState(!1),[ue,Qe]=d.useState(!1),[Q,Je]=d.useState("difficulties"),[we,Ce]=d.useState("tags"),[Pe,be]=d.useState(!1),[Me,je]=d.useState([]),[Se,et]=d.useState([]),[fe,tt]=d.useState(!1),[u,$]=d.useState(null),[w,xe]=d.useState(null),[Fe,Te]=d.useState(!1),[D,oe]=d.useState(null),[Oe,Ue]=d.useState(!1),[W,J]=d.useState(null),[y,Ae]=d.useState(null),[ut,F]=d.useState(""),[j,z]=d.useState(Ft);d.useEffect(()=>{Q==="tags"&&S&&K()},[Q,S]);const K=async()=>{tt(!0);try{const[t,s]=await Promise.all([_.get(`${N.database.difficulties.root()}/tags`,{headers:{"X-Super-Admin-Password":S}}),_.get(N.database.difficulties.tagGroups(),{headers:{"X-Super-Admin-Password":S}})]);je(t.data||[]),et(s.data||[])}catch(t){console.error("Error fetching tags:",t),G.error(i("difficulty.tags.notifications.fetchFailed"))}finally{tt(!1)}},St=async()=>{try{await G.promise((async()=>{const t=new FormData;t.append("name",j.name),t.append("color",j.color),j.group&&t.append("group",j.group),t.append("isCommunity",j.isCommunity?"true":"false"),t.append("passWarningEnabled",j.passWarningEnabled!==!1?"true":"false"),zt(t,j),j.iconFile?t.append("icon",j.iconFile):j.icon===null&&t.append("icon","null");const s=await _.post(`${N.database.difficulties.root()}/tags`,t,{headers:{"X-Super-Admin-Password":S,"Content-Type":"multipart/form-data"}});return j.icon&&j.icon.startsWith("blob:")&&URL.revokeObjectURL(j.icon),Te(!1),z(Ft),await K(),s.data})(),{loading:i("difficulty.loading.savingTag"),success:i("difficulty.tags.notifications.created"),error:t=>X(t)||Nt(t,i("difficulty.tags.notifications.createFailed"))})}catch(t){console.error("Error creating tag:",t)}},Tt=async()=>{try{await G.promise((async()=>{const t=new FormData;t.append("name",u.name),t.append("color",u.color),u.group!==void 0&&t.append("group",u.group||""),t.append("isCommunity",u.isCommunity?"true":"false"),t.append("passWarningEnabled",u.passWarningEnabled!==!1?"true":"false"),zt(t,u),u.iconFile?t.append("icon",u.iconFile):u.icon===null&&u.icon!==void 0&&t.append("icon","null");const s=await _.put(`${N.database.difficulties.root()}/tags/${u.id}`,t,{headers:{"X-Super-Admin-Password":S,"Content-Type":"multipart/form-data"}});return je(r=>r.map(g=>g.id===u.id?s.data:g)),u.icon&&u.icon.startsWith("blob:")&&URL.revokeObjectURL(u.icon),$(null),xe(null),await K(),s.data})(),{loading:i("difficulty.loading.updatingTag"),success:i("difficulty.tags.notifications.updated"),error:t=>X(t)||Nt(t,i("difficulty.tags.notifications.updateFailed"))})}catch(t){console.error("Error updating tag:",t)}},Ot=()=>{if(!u||!w)return!1;if(u.name!==w.name||u.color!==w.color)return!0;const t=(u.group||"").trim(),s=(w.group||"").trim();return!!(t!==s||!!u.isCommunity!=!!w.isCommunity||u.passWarningEnabled!==!1!=(w.passWarningEnabled!==!1)||String(u.description||"")!==String(w.description||"")||String(u.wilsonZ??"")!==String(w.wilsonZ??"")||String(u.scoreOn??"")!==String(w.scoreOn??"")||String(u.scoreOff??"")!==String(w.scoreOff??"")||String(u.scoringMode||"")!==String(w.scoringMode||"")||ze(u.requireTopPlay)!==ze(w.requireTopPlay)||!xs(u.allowedBands,w.allowedBands)||u.iconFile||u.icon===null&&w.icon!==null)},st=()=>{Ot()&&!window.confirm(i("difficulty.tags.edit.unsavedChanges"))||(u!=null&&u.icon&&u.icon.startsWith("blob:")&&URL.revokeObjectURL(u.icon),$(null),xe(null))},it=()=>{j.icon&&j.icon.startsWith("blob:")&&URL.revokeObjectURL(j.icon),Te(!1),z(Ft)},at=()=>{Ue(!1),F("")},At=async()=>{const t=D.id;try{await G.promise((async()=>{await _.delete(`${N.database.difficulties.root()}/tags/${t}`,{headers:{"X-Super-Admin-Password":S}}),je(s=>s.filter(r=>r.id!==t)),oe(null),await K()})(),{loading:i("difficulty.loading.deletingTag"),success:i("difficulty.tags.notifications.deleted"),error:s=>X(s)||Nt(s,i("difficulty.tags.notifications.deleteFailed"))})}catch(s){console.error("Error deleting tag:",s)}},lt=d.useMemo(()=>U||E!==null||I!==null||De||ye||Fe||u!==null||D!==null||Oe||W!==null||y!==null||Pe,[U,E,I,De,ye,Fe,u,D,Oe,W,y,Pe]);d.useEffect(()=>{de(lt)},[lt]),is(lt),d.useEffect(()=>{qt(o,Wt.SUPER_ADMIN)&&ye&&Ye(!0)},[o]);const Et=async t=>{var h;const s=t??pe,{type:r,data:g}=s;if(!r||!g)return;M("");const v=i(r==="delete"?"difficulty.loading.deleting":"difficulty.loading.savingDifficulty");try{await G.promise((async()=>{var O;if(r==="create"){const B=(await _.post(`${N.database.difficulties.root()}`,{...g,superAdminPassword:S})).data;return A(p=>[...p,B]),"create"}if(r==="edit"){const B=(await _.put(`${N.database.difficulties.root()}/${g.id}`,{...g,superAdminPassword:S})).data;return A(p=>p.map(k=>k.id===B.id?B:k)),"edit"}if(r==="delete")return await _.delete(`${N.database.difficulties.root()}/${g.id}?fallbackId=${(O=f.find(C=>C.name===g.fallbackDiff))==null?void 0:O.id}`,{data:{superAdminPassword:S}}),A(C=>
1C.filter(B=>B.id!==g.id)),"delete";throw new Error("Unknown action")})(),{loading:v,success:O=>i(O==="create"?"difficulty.notifications.created":O==="edit"?"difficulty.notifications.updated":"difficulty.notifications.deleted"),error:O=>{var C;return((C=O.response)==null?void 0:C.status)===403?i("difficulty.passwordModal.errors.invalid"):i("difficulty.passwordModal.errors.generic")}}),b(""),H({type:"",data:null}),M(""),ee(!1),R(null),ie(null),ge(!1),ae(""),se({id:"",name:"",type:"PGU",icon:"",emoji:"",color:"#ffffff",baseScore:0,legacy:"",legacyIcon:"",legacyEmoji:""})}catch(O){if(re(O)){M(X(O)||i("difficulty.passwordModal.errors.generic"));return}const C=((h=O==null?void 0:O.response)==null?void 0:h.status)===403?i("difficulty.passwordModal.errors.invalid"):i("difficulty.passwordModal.errors.generic");M(C)}},ft=()=>{ee(!1),M(""),se({id:"",name:"",type:"PGU",icon:"",emoji:"",color:"#ffffff",baseScore:0,legacy:"",legacyIcon:"",legacyEmoji:""})},mt=()=>{R(null),M("")},$e=()=>{ie(null),ge(!1),ae(""),M("")},ot=async t=>{try{return await _.head(`${N.admin.verifyPassword()}?origin=difficulty`,{headers:{"X-Super-Admin-Password":t}}),He(t),he(!1),Ye(!1),!0}catch(s){return re(s)?(M(X(s)||i("difficulty.passwordModal.errors.generic")),!1):(M(i("difficulty.passwordModal.errors.invalid")),G.error(i("difficulty.passwordModal.errors.invalid")),!1)}},pt=async()=>{await ot(te)&&b("")},gt=async()=>{if(await ot(te)){const{type:s,data:r}=_e;switch(s){case"edit":const g=f.find(v=>v.id===r.id);R(g);break;case"create":ee(!0);break;case"delete":ie(r);break;case"discordRoles":be(!0);break}le(null)}b("")},ht=t=>{R(t)},yt=()=>{ee(!0)},bt=async t=>{var v;if(!t.destination)return;Re(!0);const s=Array.from(Be),[r]=s.splice(t.source.index,1);s.splice(t.destination.index,0,r);const g=s.map((h,O)=>({...h,sortOrder:O}));A(g);try{await G.promise(_.put(`${N.database.difficulties.root()}/sort-orders`,{sortOrders:g.map(h=>({id:h.id,sortOrder:h.sortOrder}))},{headers:{"X-Super-Admin-Password":S}}),{loading:i("difficulty.loading.reorderingDifficulties"),success:i("difficulty.notifications.reordered"),error:h=>X(h)||i("difficulty.notifications.reorderFailed")})}catch(h){console.error("Error updating sort orders:",{error:h.message,status:(v=h.response)==null?void 0:v.status,difficultyId:r==null?void 0:r.id,difficultyName:r==null?void 0:r.name}),await n()}finally{Re(!1)}},It=t=>{t.preventDefault();const s=U?{type:"create",data:ce}:{type:"edit",data:E};H(s),Et(s)},kt=async(t,s)=>{if(t.destination&&t.source.droppableId===t.destination.droppableId){Le(!0);try{const g=[...Me.filter(C=>(C.group||"")===s)].sort((C,B)=>(C.sortOrder??0)-(B.sortOrder??0)),v=Array.from(g),[h]=v.splice(t.source.index,1);v.splice(t.destination.index,0,h);const O=v.map((C,B)=>({...C,sortOrder:B}));je(C=>C.map(B=>{const p=O.find(k=>k.id===B.id);return p||B})),await G.promise(_.put(`${N.database.difficulties.root()}/tags/sort-orders`,{sortOrders:O.map(C=>({id:C.id,sortOrder:C.sortOrder}))},{headers:{"X-Super-Admin-Password":S}}),{loading:i("difficulty.loading.reorderingTags"),success:i("difficulty.tags.notifications.reordered"),error:C=>X(C)||i("difficulty.tags.notifications.reorderFailed")})}catch(r){console.error("Error updating tag sort orders:",r),await K()}finally{Le(!1)}}},Dt=async t=>{if(t.destination){Qe(!0);try{const s=Array.from(Ee),[r]=s.splice(t.source.index,1);s.splice(t.destination.index,0,r);const g=s.map((v,h)=>({id:v.id,name:v.name,sortOrder:h}));et(s.map((v,h)=>({...v,sortOrder:h}))),await G.promise(_.put(`${N.database.difficulties.root()}/tags/group-sort-orders`,{groups:g},{headers:{"X-Super-Admin-Password":S}}),{loading:i("difficulty.loading.reorderingGroups"),success:i("difficulty.groups.notifications.reordered"),error:v=>X(v)||i("difficulty.groups.notifications.reorderFailed")})}catch(s){console.error("Error updating group sort orders:",s),await K()}finally{Qe(!1)}}},Rt=async()=>{const t=ut.trim();if(t)try{await G.promise((async()=>{await _.post(N.database.difficulties.tagGroups(),{name:t},{headers:{"X-Super-Admin-Password":S}}),Ue(!1),F(""),await K()})(),{loading:i("difficulty.loading.savingGroup"),success:i("difficulty.groups.notifications.created"),error:s=>X(s)||i("difficulty.groups.notifications.createFailed")})}catch(s){console.error("Error creating tag group:",s)}},Lt=async()=>
1{if(!W)return;const t=String(W.name||"").trim();if(t)try{await G.promise((async()=>{const s=js(W);s.requireTopPlay||(s.requireTopPlay="false"),await _.put(N.database.difficulties.tagGroup(W.id),{name:t,...s},{headers:{"X-Super-Admin-Password":S}}),J(null),await K()})(),{loading:i("difficulty.loading.updatingGroup"),success:i("difficulty.groups.notifications.updated"),error:s=>X(s)||i("difficulty.groups.notifications.updateFailed")})}catch(s){console.error("Error updating tag group:",s)}},jt=async()=>{if(!y)return;const t=y.id;try{await G.promise((async()=>{await _.delete(N.database.difficulties.tagGroup(t),{headers:{"X-Super-Admin-Password":S}}),Ae(null),await K()})(),{loading:i("difficulty.loading.deletingGroup"),success:i("difficulty.groups.notifications.deleted"),error:s=>X(s)||i("difficulty.groups.notifications.deleteFailed")})}catch(s){console.error("Error deleting tag group:",s)}},Be=[...f].sort((t,s)=>t.sortOrder-s.sortOrder),Ee=[...Se].sort((t,s)=>{const r=t.sortOrder??0,g=s.sortOrder??0;return r!==g?r-g:String(t.name||"").localeCompare(String(s.name||""))}),ne=Me.reduce((t,s)=>{const r=s.groupId==null?"ungrouped":String(s.groupId);return t[r]||(t[r]=[]),t[r].push(s),t},{}),Ge=t=>[...t||[]].sort((s,r)=>(s.sortOrder??0)-(r.sortOrder??0)),xt=Ee.map(t=>({id:t.id,name:t.name,groupSortOrder:t.sortOrder??0,tags:Ge(ne[String(t.id)])})),vt=Ge(ne.ungrouped),a=[...xt,...vt.length?[{id:null,name:"",groupSortOrder:Number.MAX_SAFE_INTEGER,tags:vt}]:[]],c=async()=>{if(!Y||Y===String(I==null?void 0:I.id))return;const t=I.id;try{l(!0),await G.promise((async()=>{var s;await _.delete(`${N.database.difficulties.root()}/${t}?fallbackId=${(s=f.find(r=>r.name===Y))==null?void 0:s.id}`,{data:{superAdminPassword:S}}),A(r=>r.filter(g=>g.id!==t)),ie(null),ge(!1),ae("")})(),{loading:i("difficulty.loading.deleting"),success:i("difficulty.notifications.deleted"),error:s=>{var r;return X(s)||(((r=s.response)==null?void 0:r.status)===403?i("difficulty.passwordModal.errors.invalid"):i("difficulty.passwordModal.errors.generic"))}})}catch(s){re(s)?M(X(s)||i("difficulty.passwordModal.errors.generic")):M(i("difficulty.passwordModal.errors.generic"))}finally{l(!1)}};return o.permissionFlags===void 0?e.jsxs("div",{className:"difficulty-page",children:[e.jsx(Xt,{...Z}),e.jsx("div",{className:"difficulty-container page-content",children:e.jsx("div",{className:"loader-shell loader-shell--tall",children:e.jsx("div",{className:"loader loader-relative"})})})]}):qt(o,Wt.SUPER_ADMIN)?e.jsxs(e.Fragment,{children:[e.jsx(Xt,{...Z}),e.jsxs("div",{className:"difficulty-page",children:[!T&&e.jsx(ms,{}),e.jsxs("div",{className:"difficulty-container page-content-1000",children:[e.jsxs("div",{className:"header-container",children:[e.jsx("h1",{children:i("difficulty.header.title")}),e.jsx("button",{className:"refresh-button",onClick:Q==="difficulties"?n:K,disabled:x||m||V||fe,"aria-label":i("difficulty.header.refresh"),children:e.jsx(ns,{color:"#fff",size:"36px"})})]}),e.jsxs("div",{className:"tab-navigation",children:[e.jsx("button",{className:`tab-button ${Q==="difficulties"?"active":""}`,onClick:()=>Je("difficulties"),children:i("difficulty.tabs.difficulties")}),e.jsx("button",{className:`tab-button ${Q==="tags"?"active":""}`,onClick:()=>Je("tags"),children:i("difficulty.tabs.tags")})]}),L&&e.jsx("div",{className:"error-message",children:L}),Q==="difficulties"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"difficulty-actions-container",children:[e.jsx("button",{className:"create-button btn-fill-primary",onClick:yt,disabled:x||m||V,children:i("difficulty.buttons.create")}),e.jsx("button",{className:"discord-roles-button btn-fill-glass",onClick:()=>{S?be(!0):(le({type:"discordRoles"}),he(!0))},disabled:x||m||V,children:i("difficulty.buttons.discordRoles")})]}),e.jsx(wt,{onDragEnd:bt,children:e.jsx(Ct,{droppableId:"difficulties",children:t=>e.jsxs("div",{className:"difficulties-list",...t.droppableProps,ref:t.innerRef,children:[x||m?e.jsx("div",{className:"loading-message",children:i("difficulty.loading.difficulties")}):Be.length===0?e.jsx("div",{className:"no-items-message",children:i("difficulty.noItems.message")}):Be.map((s,r)=>e.jsx(Pt,{draggableId:s.id.toString(),index:r,isDragDisabled:V,children:(g,v)=>e.jsxs("div",{ref:g.innerRef,...g.draggableProps,...g.dragHandleProps,className:`difficulty-item ${v.isDragging?"dragging":""}`,children:[e.jsxs("div",{className:"difficulty-info",children:[e.jsx("img",{src:Xe(s.icon,Ze.MEDIUM),alt:s.name,className:"difficulty-icon"}),e.jsxs("div",{className:"difficulty-details",children:[e.jsx("span",{className:"difficulty-name",children:s.name}),e.jsx("span",{className:"difficulty-type",children:s.type})]})]}),e.jsxs("div",{className:"difficulty-actions",children:[e.jsx("button",{className:"edit-button",onClick:()=>ht(s),disabled:x||V,children:e.jsx(dt,{color:"#fff",size:"24px"})}),e.jsx("button",{className:"delete-button",onClick:()=>ie(s),disabled:x||V,children:e.jsx(Ve,{color:"#fff",size:"24px"})})]})]})},s.id)),t.placeholder]})})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"sub-tab-navigation",children:[e.jsx("button",{className:`sub-tab-button ${we==="tags"?"active":""}`,onClick:()=>Ce("tags"),children:i("difficulty.tabs.tags")}),e.jsx("button",{className:`sub-tab-button ${we==="groups"?"active":""}`,onClick:()=>Ce("groups"),children:i("difficulty.tabs.groups")})]}),we==="tags"?e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"create-button btn-fill-primary",onClick:()=>Te(!0),disabled:fe||Ne,children:i("difficulty.tags.createButton")}),fe?e.jsx("div",{className:"loading-message",children:i("loading.generic",{ns:"common"})}):Me.length===0?e.jsx("div",{className:"no-items-message",children:i("difficulty.tags.noTags")}
1):e.jsx("div",{className:"grouped-tags-container",children:a.map(t=>e.jsxs("div",{className:"tag-group-section",children:[e.jsxs("h3",{className:"tag-group-header",children:[t.name||i("difficulty.tags.ungrouped"),e.jsxs("span",{className:"tag-count",children:["(",t.tags.length,")"]})]}),e.jsx(wt,{onDragEnd:s=>kt(s,t.name),children:e.jsx(Ct,{droppableId:`group-${t.name||"ungrouped"}`,children:s=>e.jsxs("div",{className:"tags-list",...s.droppableProps,ref:s.innerRef,children:[t.tags.map((r,g)=>e.jsx(Pt,{draggableId:`tag-${r.id}`,index:g,isDragDisabled:Ne,children:(v,h)=>e.jsxs("div",{ref:v.innerRef,...v.draggableProps,...v.dragHandleProps,className:`tag-item ${h.isDragging?"dragging":""}`,children:[e.jsxs("div",{className:"tag-item-content",children:[r.icon&&e.jsx("img",{src:Xe(r.icon,Ze.SMALL),alt:r.name,className:"tag-item-icon"}),e.jsxs("div",{className:"tag-item-info",children:[e.jsx("div",{className:"tag-item-name",style:{color:r.color},children:r.name}),e.jsx("div",{className:"tag-item-color",children:r.color})]})]}),e.jsxs("div",{className:"tag-item-actions",children:[e.jsx("button",{onClick:()=>{xe(Ut(r)),$(Ut({...r,iconFile:null,group:r.group||""}))},disabled:Ne,children:e.jsx(dt,{color:"#fff",size:"20px"})}),e.jsx("button",{onClick:()=>oe(r),disabled:Ne,children:e.jsx(Ve,{color:"#fff",size:"20px"})})]})]})},r.id)),s.placeholder]})})})]},t.name||"ungrouped"))})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"create-button btn-fill-primary",onClick:()=>{F(""),Ue(!0)},disabled:fe||ue,children:i("difficulty.groups.createButton")}),fe?e.jsx("div",{className:"loading-message",children:i("loading.generic",{ns:"common"})}):Ee.length===0?e.jsx("div",{className:"no-items-message",children:i("difficulty.groups.noGroups")}):e.jsx(wt,{onDragEnd:Dt,children:e.jsx(Ct,{droppableId:"groups",children:t=>e.jsxs("div",{className:"groups-list",...t.droppableProps,ref:t.innerRef,children:[Ee.map((s,r)=>e.jsx(Pt,{draggableId:`group-${s.id}`,index:r,isDragDisabled:ue,children:(g,v)=>e.jsxs("div",{ref:g.innerRef,...g.draggableProps,...g.dragHandleProps,className:`group-item ${v.isDragging?"dragging":""}`,children:[e.jsxs("div",{className:"group-item-content",children:[e.jsx("div",{className:"group-item-name",children:s.name}),e.jsx("div",{className:"group-item-count",children:i("difficulty.tags.tagCount",{count:(ne[String(s.id)]||[]).length,plural:(ne[String(s.id)]||[]).length!==1?"s":""})})]}),e.jsxs("div",{className:"group-item-preview",children:[Ge(ne[String(s.id)]).slice(0,5).map(h=>e.jsx("div",{className:"group-tag-preview",style:{backgroundColor:`${h.color}40`,borderColor:h.color},title:h.name,children:h.icon?e.jsx("img",{src:Xe(h.icon,Ze.SMALL),alt:h.name}):e.jsx("span",{children:h.name.charAt(0)})},h.id)),(ne[String(s.id)]||[]).length>5&&e.jsxs("span",{className:"more-tags",children:["+",(ne[String(s.id)]||[]).length-5]})]}),e.jsxs("div",{className:"group-item-actions",children:[e.jsx("button",{type:"button",onMouseDown:h=>h.stopPropagation(),onClick:h=>{h.stopPropagation(),J(Ut(s))},disabled:ue,children:e.jsx(dt,{color:"#fff",size:"20px"})}),e.jsx("button",{type:"button",onMouseDown:h=>h.stopPropagation(),onClick:h=>{h.stopPropagation(),Ae(s)},disabled:ue,children:e.jsx(Ve,{color:"#fff",size:"20px"})})]})]})},s.id)),t.placeholder]})})})]}),Fe&&e.jsxs(Ie,{onClose:it,ariaLabelledBy:"difficulty-create-tag-title",children:[e.jsx(ve,{variant:"floating",className:"modal-close-button",onClick:it,"aria-label":i("buttons.close",{ns:"common"})}),e.jsx("h2",{id:"difficulty-create-tag-title",children:i("difficulty.tags.create.title")}),e.jsxs("form",{onSubmit:t=>{t.preventDefault(),St()},children:[e.jsx(Ht,{icon:j.icon,i18nPrefix:"difficulty.tags.create",t:i,onSelectFile:t=>{j.icon&&j.icon.startsWith("blob:")&&URL.revokeObjectURL(j.icon),z({...j,iconFile:t,icon:URL.createObjectURL(t)})},onRemove:()=>{j.icon&&j.icon.startsWith("blob:")&&URL.revokeObjectURL(j.icon),z({...j,iconFile:null,icon:null})}}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:i("difficulty.tags.create.name")}),e.jsx("input",{type:"text",value:j.name,onChange:t=>z({...j,name:t.target.value}),required:!0})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:i("difficulty.tags.create.color")}),e.jsx("input",{type:"color",value:j.color,onChange:t=>z({...j,color:t.target.value}),required:!0})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:i("difficulty.tags.create.group.label")}),e.jsx("input",{type:"text",value:j.group,onChange:t=>z({...j,group:t.target.value}),placeholder:i("difficulty.tags.create.group.placeholder")})]}),e.jsx(ct,{value:j,onChange:z,t:i,includeDescription:!0,includeAssignment:!1}),e.jsx("div",{className:"form-group form-group--checkbox",children:e.jsxs("label",{children:[e.jsx("input",{type:"checkbox",checked:!!j.isCommunity,onChange:t=>z({...j,isCommunity:t.target.checked})}),e.jsx("span",{children:i("difficulty.tags.create.isCommunity")})]})}),e.jsx("div",{className:"form-group form-group--checkbox",children:e.jsxs("label",{children:[e.jsx("input",{type:"checkbox",checked:j.passWarningEnabled!==!1,onChange:t=>z({...j,passWarningEnabled:t.target.checked})}),e.jsx("span",{children:i("difficulty.tags.create.passWarningEnabled")})]})}),e.jsx("div",{className:"form-section-split",children:e.jsx("span",{className:"form-section-split-label",children:i("difficulty.tags.fields.assignmentSection")})}),e.jsx(ct,{value:j,onChange:z,t:i,inheritFromGroup:!0,tagGroups:Se,inactive:!j.isCommunity}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{type:"submit",className:"confirm-button btn-fill-primary",children:i("difficulty.tags.create.createButton")}),e.jsx("button",{type:"button",className:"cancel-button btn-fill-ghost",onClick:it,children:i("buttons.cancel",{ns:"common"})})]})]})]}),u&&e.jsxs(Ie,{onClose:st,ariaLabelledBy:"difficulty-edit-tag-title",children:[e.jsx(ve,{variant:"floating",className:"modal-close-button",onClick:st,"aria-label":i("buttons.close",{ns:"common"})}),e.jsx("h2",{id:"difficulty-edit-tag-title",children:i("difficulty.tags.edit.title")}),e.jsxs("form",{onSubmit:t=>{t.preventDefault(),Tt()},children:[e.jsx(Ht,{icon:u.icon,i18nPrefix:"difficulty.tags.edit",t:i,onSelectFile:t=>{u.icon&&u.icon.startsWith("blob:")&&URL.revokeObjectURL(u.icon),$({...u,iconFile:t,icon:URL.createObjectURL(t)})},onRemove:()=>{u.icon&&u.icon.startsWith("blob:")&&URL.revokeObjectURL(u.icon),$({...u,iconFile:null,icon:null})}}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:i("difficulty.tags.edit.name")}),e.jsx("input",{type:"text",value:u.name,onChange:t=>$({...u,name:t.target.value}),required:!0})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:i("difficulty.tags.edit.color")}),e.jsx("input",{type:"color",value:u.color,onChange:t=>$({...u,color:t.target.value}),required:!0})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:i("difficulty.tags.edit.group.label")}),e.jsx("input",{type:"text",value:u.group||"",onChange:t=>$({...u,group:t.target.value}),placeholder:i("difficulty.tags.edit.group.placeholder")})]}),e.jsx(ct,{value:u,onChange:$,t:i,includeDescription:!0,includeAssignment:!1}),e.jsx("div",{className:"form-group form-group--checkbox",children:e.jsxs("label",{children:[e.jsx("input",{type:"checkbox",checked:!!u.isCommunity,onChange:t=>$({...u,isCommunity:t.target.checked})}),e.jsx("span",{children:i("difficulty.tags.edit.isCommunity")})]})}),e.jsx("div",{className:"form-group form-group--checkbox",children:e.jsxs("label",{children:[e.jsx("input",{type:"checkbox",checked:u.passWarningEnabled!==!1,onChange:t=>$({...u,passWarningEnabled:t.target.checked})}),e.jsx("span",{children:i("difficulty.tags.edit.passWarningEnabled")})]})}),e.jsx("div",{className:"form-section-split",children:e.jsx("span",{className:"form-section-split-label",children:i("difficulty.tags.fields.assignmentSection")})}),e.jsx(ct,{value:u,onChange:$,t:i,inheritFromGroup:!0,tagGroups:Se,inactive:!u.isCommunity}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{type:"submit",className:"confirm-button btn-fill-primary",children:i("difficulty.tags.edit.updateButton")}),e.jsx("button",{type:"button",className:"cancel-button btn-fill-ghost",onClick:st,children:i("buttons.cancel",{ns:"common"})})]})]})]}),D&&e.jsxs(Ie,{onClose:()=>oe(null),ariaLabelledBy:"difficulty-delete-tag-title",children:[e.jsx(ve,{variant:"floating",className:"modal-close-button",onClick:()=>oe(null),"aria-label":i("buttons.close",{ns:"common"})}),e.jsx("h2",{id:"difficulty-delete-tag-title",children:i("difficulty.tags.delete.title")}),e.jsx("p",{children:i("difficulty.tags.delete.message",{name:D.name})}),e.jsx("p",{children:i("difficulty.tags.delete.description")}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{type:"button",className:"delete-confirm-button btn-fill-danger",onClick:At,children:i("difficulty.tags.delete.deleteButton")}),e.jsx("button",{type:"button",className:"cancel-button btn-fill-ghost",onClick:()=>oe(null),children:i("buttons.cancel",{ns:"common"})})]})]}),Oe&&e.jsxs(Ie,{onClose:at,ariaLabelledBy:"difficulty-create-group-title",children:[e.jsx(ve,{variant:"floating",className:"modal-close-button",onClick:at,"aria-label":i("buttons.close",{ns:"common"})}),e.jsx("h2",{id:"difficulty-create-group-title",children:i("difficulty.groups.create.title")}),e.jsxs("form",{onSubmit:t=>{t.preventDefault(),Rt()},children:[e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:i("difficulty.groups.create.name")}),e.jsx("input",{type:"text",value:ut,onChange:t=>F(t.target.value),required:!0})]}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{type:"submit",className:"confirm-button btn-fill-primary",children:i("difficulty.groups.create.createButton")}),e.jsx("button",{type:"button",className:"cancel-button btn-fill-ghost",onClick:at,children:i("buttons.cancel",{ns:"common"})})]})]})]}),W&&e.jsxs(Ie,{onClose:()=>J(null),ariaLabelledBy:"difficulty-edit-group-title",children:[e.jsx(ve,{variant:"floating",className:"modal-close-button",onClick:()=>J(null),"aria-label":i("buttons.close",{ns:"common"})}),e.jsx("h2",{id:"difficulty-edit-group-title",children:i("difficulty.groups.edit.title")}),e.jsxs("form",{onSubmit:t=>{t.preventDefault(),Lt()},children:[e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:i("difficulty.groups.edit.name")}),e.jsx("input",{type:"text",value:W.name,onChange:t=>J({...W,name:t.target.value}),required:!0})]}
1),e.jsx(ct,{value:W,onChange:J,t:i}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{type:"submit",className:"confirm-button btn-fill-primary",children:i("difficulty.groups.edit.updateButton")}),e.jsx("button",{type:"button",className:"cancel-button btn-fill-ghost",onClick:()=>J(null),children:i("buttons.cancel",{ns:"common"})})]})]})]}),y&&e.jsxs(Ie,{onClose:()=>Ae(null),ariaLabelledBy:"difficulty-delete-group-title",children:[e.jsx(ve,{variant:"floating",className:"modal-close-button",onClick:()=>Ae(null),"aria-label":i("buttons.close",{ns:"common"})}),e.jsx("h2",{id:"difficulty-delete-group-title",children:i("difficulty.groups.delete.title")}),e.jsx("p",{children:i("difficulty.groups.delete.message",{name:y.name})}),e.jsx("p",{children:i("difficulty.groups.delete.description")}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{type:"button",className:"delete-confirm-button btn-fill-danger",onClick:jt,children:i("difficulty.groups.delete.deleteButton")}),e.jsx("button",{type:"button",className:"cancel-button btn-fill-ghost",onClick:()=>Ae(null),children:i("buttons.cancel",{ns:"common"})})]})]})]}),I&&e.jsxs(Ie,{onClose:$e,panelClassName:"delete-modal",ariaLabelledBy:"difficulty-delete-title",children:[e.jsx(ve,{variant:"floating",className:"modal-close-button",onClick:$e,"aria-label":i("buttons.close",{ns:"common"})}),e.jsxs("div",{className:`delete-warning ${Ke?"fade-out":""}`,children:[e.jsx("h2",{id:"difficulty-delete-title",children:i("difficulty.modal.delete.warning.title")}),e.jsxs("div",{className:"warning-content",children:[e.jsx("p",{children:i("difficulty.modal.delete.warning.message",{name:I==null?void 0:I.name})}),e.jsx("p",{children:i("difficulty.modal.delete.warning.description")}),e.jsx("ul",{children:i("difficulty.modal.delete.warning.points",{returnObjects:!0}).map((t,s)=>e.jsx("li",{children:t},s))}),e.jsx("p",{className:"warning-highlight",children:i("difficulty.modal.delete.warning.highlight")})]}),e.jsx("button",{className:"understand-button",onClick:()=>ge(!0),children:i("difficulty.buttons.understand")})]}),e.jsxs("div",{className:`delete-input ${Ke?"fade-in":""}`,children:[e.jsx("h2",{children:i("difficulty.modal.delete.title")}),e.jsxs("form",{onSubmit:t=>{t.preventDefault(),Y&&H({type:"delete",data:{id:I.id,fallbackDiff:Y}})},children:[e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:i("difficulty.form.labels.fallbackDiff")}),e.jsx(gs,{value:Y||"",onChange:t=>ae(t||""),showDiff:!0,difficulties:f.filter(t=>t.id!==(I==null?void 0:I.id)),allowCustomInput:!1,placeholder:i("difficulty.form.placeholders.fallbackDiff")}),e.jsx("p",{className:"help-text",children:i("difficulty.form.helpText.fallbackDiff",{name:I==null?void 0:I.name})})]}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{type:"button",className:"delete-confirm-button btn-fill-danger",onClick:c,disabled:!Y||Y===String(I==null?void 0:I.id)||x,children:x?i("difficulty.loading.deleting")||"Deleting...":i("buttons.delete",{ns:"common"})}),e.jsx("button",{type:"button",className:"cancel-button btn-fill-ghost",onClick:$e,children:i("buttons.cancel",{ns:"common"})})]})]})]})]}),De&&e.jsxs(ke,{onClose:()=>{he(!1),b(""),le(null)},dismissOnOverlay:!1,overlayClassName:"difficulty-page difficulty-page__modal",panelClassName:"password-modal-content",ariaLabelledBy:"difficulty-password-title",children:[e.jsx("h3",{id:"difficulty-password-title",children:i("difficulty.passwordModal.title")}),e.jsx("p",{children:i("difficulty.passwordModal.message",{action:_e==null?void 0:_e.type})}),e.jsx("input",{type:"password",autoComplete:"section-password-super-admin",value:te,onChange:t=>b(t.target.value),placeholder:i("difficulty.passwordModal.placeholder")}),L&&e.jsx("p",{className:"error-message",children:L}),e.jsxs("div",{className:"password-modal-actions",children:[e.jsx("button",{className:"confirm-btn btn-fill-primary",onClick:gt,disabled:!te,children:i("buttons.confirm",{ns:"common"})}),e.jsx("button",{className:"cancel-btn btn-fill-neutral-dark",onClick:()=>{he(!1),b(""),le(null)},children:i("buttons.cancel",{ns:"common"})})]})]}),ye&&e.jsxs(ke,{onClose:Ns,dismissOnOverlay:!1,dismissOnEscape:!1,overlayClassName:"difficulty-page difficulty-page__modal",panelClassName:"password-modal-content",ariaLabelledBy:"difficulty-initial-password-title",children:[e.jsx("h3",{id:"difficulty-initial-password-title",children:i("difficulty.passwordModal.initialTitle")}),e.jsx("p",{children:i("difficulty.passwordModal.initialMessage")}),e.jsx("input",{type:"password",autoComplete:"section-password-super-admin",value:te,onChange:t=>b(t.target.value),placeholder:i("difficulty.passwordModal.placeholder")}),L&&e.jsx("p",{className:"error-message",children:L}),e.jsx("div",{className:"password-modal-actions",children:e.jsx("button",{className:"confirm-btn btn-fill-primary",onClick:pt,disabled:!te,children:i("buttons.confirm",{ns:"common"})})})]}),e.jsx(hs,{isOpen:U||E!==null,onClose:()=>{U?ft():mt()},isCreating:U,difficulty:U?ce:E||{},onSubmit:It,onChange:t=>{U?se(t):R(t)},refreshDifficulties:t=>{t?A(U?s=>[...s,t]:s=>s.map(r=>r.id===t.id?t:r)):n()},error:L,verifiedPassword:S}),e.jsx(ps,{isOpen:Pe,onClose:()=>be(!1),roleType:"DIFFICULTY",verifiedPassword:S})]})]})]}):e.jsx(os,{metaTitle:i("difficulty.meta.title"),metaDescription:i("difficulty.meta.description")})};export{Zs as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.