1import{r as l,Z as e,a2 as g,a3 as r,aC as m}from"./vendor-mui-D5pLRgDb.js";import{U as N,v as D,M as T,A as S,o as w,a as x,R as j,r as z,q as W,z as V,C as Q,Q as K,e as P,w as Z,d as J,T as X}from"./index-BSFWpFMK.js";import{S as I,N as Y}from"./InputFields-BJUL-RVv.js";import{S as ee}from"./Select-BphtUsk_.js";import{T as te}from"./TwoColumnBox-gHXb3Blm.js";import{A as ae}from"./Alert-D3YZt4Ux.js";import{M as re}from"./ManageTabs-CrKh4Y_n.js";import{S as A}from"./CheckBox-Dkb41L1G.js";import{C as ne}from"./DateTimePicker-avwAFAEf.js";import"./__commonjsHelpers__-BosuxZz1.js";import"./vendor-sweetalert2-CokzRhbv.js";const O="SWITCH_TABS",k="FETCH_SETTINGS",q="UPDATE_USER_SEARCH",B="FETCH_PREMIUM_USER";function R(t){return{type:O,payload:t}}function H(t){return{type:k,payload:t}}function L(t){return{type:q,payload:t}}function E(t){return{type:B,payload:t}}const se=t=>{const{isAdmin:a}=t,o=[["Edit Premium User",a],["User Discount",a],["General Settings",a]],n=[];return o.forEach(([i,h,s=!1])=>{h&&typeof i=="string"&&n.push({id:i.toLowerCase().replace(/[\W]+/g,"_"),name:i,isHighlighted:s})}),n},ie=[{id:"DISCOUNT10",name:"10% Discount"},{id:"DISCOUNT20",name:"20% Discount"},{id:"DISCOUNT30",name:"30% Discount"},{id:"DISCOUNT40",name:"40% Discount"},{id:"DISCOUNT50",name:"50% Discount"},{id:"DISCOUNT60",name:"60% Discount"},{id:"DISCOUNT70",name:"70% Discount"},{id:"DISCOUNT80",name:"80% Discount"},{id:"DISCOUNT90",name:"90% Discount"}],ce="_form_gngny_1",le="_formGroup_gngny_5",oe="_inputGroup_gngny_11",b={form:ce,formGroup:le,inputGroup:oe};function ue(){const{dispatch:t}=l.useContext(N),[a,o]=l.useState(""),[n,i]=l.useState(1),[h,s]=l.useState("DISCOUNT20");return e(g,{children:r("form",{onSubmit:async f=>{f.preventDefault(),await t(T(!0,"ajax"));try{const y=await S.post("/api/manage/discount",{username:a,duration:n,discountCode:h});w(y)}catch(y){x(y)}finally{await t(T(!1))}},className:b.form,children:[r("div",{className:b.formGroup,children:[e("label",{className:b.inputGroup,children:" Username: "}),e("div",{children:e(I,{value:a,handleChange:o,required:!0,placeholder:"admin",type:"text",props:{}})})]}),r("div",{className:b.formGroup,children:[e("label",{className:b.inputGroup,children:" Discount Duration "}),e(Y,{placeholder:"Days",minValue:0,maxValue:1e4,initialValue:n.toString(),handleChange:f=>{f.length===0&&(f="0"),i(parseInt(f,10))}})]}),r("div",{className:b.formGroup,children:[e("label",{className:b.inputGroup,children:" Select Discount Percentage "}),e("div",{children:e(ee,{name:"discount-values",options:ie,handleChange:s,selectedKey:h,props:{}})})]}),e("div",{className:b.submit,children:e(D,{title:"Give Discount",type:"primary"})})]})})}const de="_form_12z3y_1",me="_formGroup_12z3y_6",he="_formGroup__fullWidth_12z3y_12",pe="_labelText_12z3y_20",fe="_inputLabel_12z3y_25",_e="_submitButton_12z3y_31",d={form:de,formGroup:me,formGroup__fullWidth:he,labelText:pe,inputLabel:fe,submitButton:_e};function be(){const{state:t,dispatch:a}=l.useContext(v),{settings:o}=t,{dispatch:n}=l.useContext(N),i=async s=>{s.preventDefault(),await n(T(!0,"ajax"));try{const _=await S.post("/api/manage/premium/general_settings",{...o});w(_)}catch(_){x(_)}finally{await n(T(!1))}},h=s=>{a(H({...o,...s}))};return r("form",{className:d.form,onSubmit:i,children:[r(m,{container:!0,className:d.formGroup,children:[e(m,{container:!0,item:!0,xs:5,children:e("h4",{className:d.labelText,children:"Difficulty Threshold:"})}),r(m,{container:!0,item:!0,xs:7,children:[e(I,{props:{min:0,max:5e3,step:1},type:"number",value:o?.difficultyThreshold?.toString(),required:!0,handleChange:s=>h({difficultyThreshold:+s})}),e("label",{className:d.inputLabel,children:"Enter a difficulty level between 0 and 5000"})]})]}),r(m,{container:!0,className:d.formGroup,children:[e(m,{container:!0,item:!0,xs:5,children:e("h4",{className:d.labelText,children:"Video Restriction:"})}),e(m,{container:!0,item:!0,xs:7,children:r("div",{className:d.formGroup__fullWidth,children:[e(A,{style:{margin:0},checked:+o?.videoRestriction==1,handleChange:s=>h({videoRestriction:+s})}),e("label",{className:d.inputLabel,children:"Once enabled only premium users can play gumlet videos"})]})})]}),r(m,{container:!0,className:d.formGroup,children:[e(m,{container:!0,item:!0,xs:5,children:e("h4",{className:d.labelText,children:"Doubt Support Restriction:"})}),e(m,{container:!0,item:!0,xs:7,children:r("div",{className:d.formGroup__fullWidth,children:[e(A,{style:{margin:0},checked:+o?.doubtSupportRestriction==1,handleChange:s=>h({doubtSupportRestriction:+s})}),e("label",{className:d.inputLabel,children:"Once enabled only premium users can access doubt support"})]})})]}),e("div",{className:d.submitButton,children:e(D,{title:"Submit",type:"primary"})})]})}const Te="_form_1k7q9_1",ye="_formGroup_1k7q9_5",ge="_labelText_1k7q9_10",Se="_inputLabel_1k7q9_14",Ce="_clear_1k7q9_40",De="_clear__text_1k7q9_45",xe="_discountTable_1k7q9_51",p={form:Te,formGroup:ye,labelText:ge,inputLabel:Se,clear:Ce,clear__text:De,discountTable:xe};function Ne(){const{state:t,dispatch:a}=l.useContext(v),{search:o,user:n}=t.editUser,{dispatch:i}=l.useContext(N),h=async u=>{u.preventDefault(),await i(T(!0,"ajax"));try{const c=await S.get(`/api/manage/premium/user?handle=${o}`),{data:C}=c.data;await a(E(C))}catch(c){x(c)}finally{await i(T(!1))}},s=async u=>{u.preventDefault(),await i(T(!0,"ajax"));try{const c=await S.post("/api/manage/premium/user",{handle:n.handle,validTill:n.validTill});w(c)}catch(c){x(c)}finally{await i(T(!1))}},_=()=>e("thead",{children:r("tr",{children:[e("th",{children:"Discount Code"}),e("th",{children:"Percentage"}),e("th",{children:"Valid Till"}),e("th",{children:"Description"})]})}),f=()=>e("div",{className:p.discountTable,children:r("table",{children:[_(),e("tbody",{children:Object.entries(n.discounts)?.map(([,u])=>{const c=u;return r("tr",{children:[e("td",{children:c.code}),e("td",{children:c.amount}),e("td",{children:c.validTill}),e("td",{children:c.description})]},c.code)})})]})}),y=()=>e(g,{children:n?.discounts?.length?r(g,{children:[e("hr",{}),r("div",{children:[e("h3",{children:" Discounts Available to User"}),f()]})]}):null});return r(g,{children:[r("form",{className:p.form,onSubmit:h,children:[r(m,{container:!0,className:p.formGroup,children:[e(m,{container:!0,item:!0,xs:2,children:e("h4",{className:p.labelText,children:"Username:"})}),r(m,{container:!0,item:!0,xs:4,children:[e(I,{props:{maxLength:255},type:"text",value:o,required:!0,handleChange:u=>a(L(u))}),e("label",{className:p.inputLabel,children:"Enter the user handle"})]}),e(m,{container:!0,item:!0,xs:2,children:e("div",{className:p.clear,children:e("span",{onClick:()=>{a(E(null)),a(L(""))},className:p.clear__text,children:"Clear"})})})]}),e("div",{className:p.submitButton,children:e(D,{title:"Search",type:"primary"})})]}),e("hr",{}),n&&r("form",{className:p.form,onSubmit:s,children:[r("table",{children:[e("thead",{children:r("tr",{children:[e("th",{children:"User Handle"}),e("th",{children:"Premium Valid Till"})]})}),e("tbody",{children:r("tr",{children:[e("td",{children:e("h4",{children:n.handle})}),e("td",{children:e(ne,{value:n.validTill,props:{className:p.dateTimePicker},handleChange:u=>{a(E({...n,validTill:j(u)}))}})})]})})]}),e("div",{className:p.submitButton,children:e(D,{title:"Update",type:"primary"})})]}),y()]})}const ve=t=>{switch(t){case"general_settings":return e(be,{});case"edit_premium_user":return e(Ne,{});case"user_discount":return e(ue,{});default:return e("h1",{children:"Not Found"})}};function Ue(){const t=l.useContext(v),{activeTab:a}=t.state;
1return ve(a)}const M={activeTab:"loader",settings:null,editUser:{search:"",user:null}},Ge=(t,a)=>{switch(a.type){case O:return{...t,activeTab:a.payload};case k:return{...t,settings:a.payload};case q:return{...t,editUser:{...t.editUser,search:a.payload}};case B:return{...t,editUser:{...t.editUser,user:a.payload}};default:return t}},v=l.createContext({state:M,dispatch:()=>{}});function He(){const[t,a]=l.useReducer(Ge,M),{state:o,dispatch:n}=l.useContext(N),{userData:i,alertOpen:h,alertMessage:s,alertType:_}=o,f=z(),y=W(),[u,c]=l.useState([]),C=V.parse(y.search);return l.useEffect(()=>{u.length&&a(R(Q(u,C)))},[C.tab,u]),l.useEffect(()=>{(async()=>{if(!i?.user?.isAdmin)n(P(Z(403,"Hold right there, you are forbidden to enter this realm.")));else try{const G=await S.get("/api/manage/premium/general_settings"),{data:F}=G.data;await a(H(F));const $=se(i.user);c($),await n(J("Premium - Admin"))}catch(G){await n(P(G))}finally{await n(X(!1))}})()},[]),e(v.Provider,{value:{state:t,dispatch:a},children:e(te,{leftColumn:e(re,{fields:u,handleTabChange:U=>{f({pathname:"/manage/premium",search:`?tab=${U}`}),a(R(U))},activeTab:t.activeTab,name:"Premium Administration"}),leftMaxWidth:"240px",rightColumn:r(g,{children:[e(ae,{alertOpen:h,alertMessage:s,alertType:_,alertClose:()=>n(K(!1,""))}),e(Ue,{})]})})})}export{v as PremiumAdminContext,He 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.