1import{u as L,r as c,j as e,I as he,b as D,K as xe,M as H,D as ee,e as ae,f as re,d as O,P as G,a as be,h as je,o as F,s as W,w as fe,p as $,S as K,k as V,Y as ge,Z as ye,v as Se,_ as Ge,Q as Ce}from"./index-DN_nZfwy.js";import{L as Z}from"./Label-CUAhpR_S.js";import{T as Pe}from"./Switch-B-EaaMnE.js";import{T as we,d as Te,a as Ie,c as _e}from"./TableRow-Kp_7xLhT.js";import{T as b}from"./TableCell-D3Cgczqs.js";import{D as ke}from"./DialogContentText-Dyhq9Trb.js";import{D as se}from"./DialogActions-DhL-seZ5.js";import{K as Fe}from"./TableHead-BjtdZ3Er.js";import{g as Oe,P as Re,s as De}from"./CommonConstants-BmHHPz5Y.js";import{F as ve,c as We,d as U,e as N,a as Q}from"./array-DhzcVmbX.js";import{F as S}from"./FormControl-KJFw7VFa.js";import{I as _,F as x}from"./InputLabel-3h1Cja0O.js";import{O as k}from"./OutlinedInput-BOQxxPG8.js";import{F as Y}from"./FormControlLabel-XNL3QA_Y.js";import{S as J}from"./Switch-CHjEAZ80.js";import{B as Me}from"./ButtonGroup-DpHBYuLd.js";import{T as Be}from"./TablePagination-Btikr2hV.js";import"./SwitchBase--SLxuARJ.js";import"./getValidReactChildren-DOPKkRlc.js";import"./KeyboardArrowRight-UNnS4-iT.js";import"./LastPage-ZbCzsbd3.js";import"./Select-CPtTnIEa.js";function te({item:r,manageUserGroup:d,handleOpenModal:C,setModalUserGroupId:g}){const{t:l}=L(),[f,y]=c.useState(null),[a,w]=c.useState(!1),[T,s]=c.useState(r.enable),u=()=>{m(),w(!0)},i=()=>{w(!1)},p=P=>{y(P.currentTarget)},m=()=>{y(null)},t=async()=>{const P=!T,{success:v}=await d(r.id,"status");v&&s(P)},n=async()=>{m(),await d(r.id,"delete")};return e.jsxs(e.Fragment,{children:[e.jsxs(we,{tabIndex:r.id,children:[e.jsx(b,{children:r.id}),e.jsx(b,{children:r.symbol}),e.jsx(b,{children:r.name}),e.jsx(b,{children:r.ratio}),e.jsx(b,{children:r.api_rate}),e.jsx(b,{children:e.jsx(Z,{variant:"outlined",color:r.public?"primary":"error",children:r.public?"æ¯":"å¦"})}),e.jsx(b,{children:e.jsx(Z,{variant:"outlined",color:r.promotion?"primary":"error",children:r.promotion?"æ¯":"å¦"})}),e.jsx(b,{children:r.min}),e.jsx(b,{children:r.max}),e.jsxs(b,{children:[" ",e.jsx(Pe,{id:`switch-${r.id}`,checked:T,onChange:t})]}),e.jsx(b,{children:e.jsx(he,{onClick:p,sx:{color:"rgb(99, 115, 129)"},children:e.jsx(D,{icon:"solar:menu-dots-circle-bold-duotone"})})})]}),e.jsxs(xe,{open:!!f,anchorEl:f,onClose:m,anchorOrigin:{vertical:"top",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"right"},PaperProps:{sx:{minWidth:140}},children:[e.jsxs(H,{onClick:()=>{m(),C(),g(r.id)},children:[e.jsx(D,{icon:"solar:pen-bold-duotone",style:{marginRight:"16px"}}),l("common.edit")]}),e.jsxs(H,{onClick:u,sx:{color:"error.main"},children:[e.jsx(D,{icon:"solar:trash-bin-trash-bold-duotone",style:{marginRight:"16px"}}),l("common.delete")]})]}),e.jsxs(ee,{open:a,onClose:i,children:[e.jsx(ae,{children:l("common.delete")}),e.jsx(re,{children:e.jsx(ke,{children:l("common.deleteConfirm",{title:r.name})})}),e.jsxs(se,{children:[e.jsx(O,{onClick:i,children:l("common.close")}),e.jsx(O,{onClick:n,sx:{color:"error.main"},autoFocus:!0,children:l("common.delete")})]})]})]})}te.propTypes={item:G.object,manageUserGroup:G.func,handleOpenModal:G.func,setModalUserGroupId:G.func};const Ee=We().shape({is_edit:N(),symbol:Q().required("symbol is required"),name:Q().required("name is required"),ratio:U().required("ratio is required"),promotion:N(),min:U(),max:U()}),X={is_edit:!1,symbol:"",name:"",ratio:1,public:!1,api_rate:300,promotion:!1,min:0,max:0},ne=({open:r,userGroupId:d,onCancel:C,onOk:g})=>{const l=be(),[f,y]=c.useState(X),{t:a}=L(),w=async(s,{setErrors:u,setStatus:i,setSubmitting:p})=>{p(!0);let m;s=fe(s);try{s.is_edit?m=await F.put("/api/user_group/",{...s,id:parseInt(d)}):m=await F.post("/api/user_group/",s);const{success:t,message:n}=m.data;t?(s.is_edit?$(a("userPage.saveSuccess")):$(a("userPage.saveSuccess")),p(!1),i({success:!0}),g(!0)):(W(n),u({submit:n}))}catch{return}},T=async()=>{try{let s=await F.get(`/api/user_group/${d}`);const{success:u,message:i,data:p}=s.data;u?(p.is_edit=!0,y(p)):W(i)}catch{return}};return c.useEffect(()=>{d?T().then():y(X)},[d]),e.jsxs(ee,{open:r,onClose:C,fullWidth:!0,maxWidth:"md",children:[e.jsx(ae,{sx:{margin:"0px",fontWeight:700,lineHeight:"1.55556",padding:"24px",fontSize:"1.125rem"},children:a(d?"common.edit":"common.create")}),e.jsx(je,{}),e.jsx(re,{children:e.jsx(ve,{initialValues:f,enableReinitialize:!0,validationSchema:Ee,onSubmit:w,children:({errors:s,handleBlur:u,handleChange:i,setFieldValue:p,handleSubmit:m,touched:t,values:n,isSubmitting:P})=>e.jsxs("form",{noValidate:!0,onSubmit:m,children:[e.jsxs(S,{fullWidth:!0,error:!!(t.symbol&&s.symbol),sx:{...l.typography.otherInput},children:[e.jsx(_,{htmlFor:"channel-symbol-label",children:a("userGroup.symbol")}),e.jsx(k,{id:"channel-symbol-label",label:a("userGroup.symbol"),type:"text",value:n.symbol,n
1ame:"symbol",onBlur:u,onChange:i,inputProps:{autoComplete:"symbol"},"aria-describedby":"helper-text-channel-symbol-label",disabled:n.is_edit}),t.symbol&&s.symbol?e.jsx(x,{error:!0,id:"helper-tex-channel-symbol-label",children:a(s.symbol)}):e.jsxs(x,{id:"helper-tex-channel-type-label",children:[" ",a("userGroup.symbolTip")," "]})]}),e.jsxs(S,{fullWidth:!0,error:!!(t.name&&s.name),sx:{...l.typography.otherInput},children:[e.jsx(_,{htmlFor:"channel-name-label",children:a("userGroup.name")}),e.jsx(k,{id:"channel-name-label",label:a("userGroup.name"),type:"text",value:n.name,name:"name",onBlur:u,onChange:i,inputProps:{autoComplete:"name"},"aria-describedby":"helper-text-channel-name-label"}),t.name&&s.name?e.jsx(x,{error:!0,id:"helper-tex-channel-name-label",children:a(s.name)}):e.jsxs(x,{id:"helper-tex-channel-type-label",children:[" ",a("userGroup.nameTip")," "]})]}),e.jsxs(S,{fullWidth:!0,error:!!(t.ratio&&s.ratio),sx:{...l.typography.otherInput},children:[e.jsx(_,{htmlFor:"channel-ratio-label",children:a("userGroup.ratio")}),e.jsx(k,{id:"channel-ratio-label",label:a("userGroup.ratio"),type:"number",value:n.ratio,name:"ratio",onBlur:u,onChange:i,"aria-describedby":"helper-text-channel-ratio-label"}),t.ratio&&s.ratio&&e.jsx(x,{error:!0,id:"helper-tex-channel-ratio-label",children:a(s.ratio)})]}),e.jsxs(S,{fullWidth:!0,error:!!(t.api_rate&&s.api_rate),sx:{...l.typography.otherInput},children:[e.jsx(_,{htmlFor:"channel-api-rate-label",children:a("userGroup.apiRate")}),e.jsx(k,{id:"channel-api-rate-label",label:a("userGroup.apiRate"),type:"number",value:n.api_rate,name:"api_rate",onBlur:u,onChange:i,"aria-describedby":"helper-text-channel-api-rate-label"}),t.api_rate&&s.api_rate?e.jsx(x,{error:!0,id:"helper-tex-channel-api-rate-label",children:a(s.api_rate)}):e.jsxs(x,{id:"helper-tex-channel-api-rate-label",children:[" ",a("userGroup.apiRateTip")," "]})]}),e.jsxs(S,{fullWidth:!0,children:[e.jsx(Y,{control:e.jsx(J,{checked:n.promotion,onClick:()=>{p("promotion",!n.promotion)}}),label:a("userGroup.promotion")}),e.jsxs(x,{id:"helper-tex-channel-promotion-label",children:[" ",a("userGroup.promotionTip")," "]})]}),e.jsxs(S,{fullWidth:!0,error:!!(t.min&&s.min),sx:{...l.typography.otherInput},children:[e.jsx(_,{htmlFor:"channel-min-label",children:a("userGroup.min")}),e.jsx(k,{id:"channel-min-label",label:a("userGroup.min"),type:"number",value:n.min,name:"min",onBlur:u,onChange:i,"aria-describedby":"helper-text-channel-min-label"}),t.min&&s.min?e.jsx(x,{error:!0,id:"helper-tex-channel-min-label",children:a(s.min)}):e.jsxs(x,{id:"helper-tex-channel-min-label",children:[" ",a("userGroup.minTip")," "]})]}),e.jsxs(S,{fullWidth:!0,error:!!(t.max&&s.max),sx:{...l.typography.otherInput},children:[e.jsx(_,{htmlFor:"channel-max-label",children:a("userGroup.max")}),e.jsx(k,{id:"channel-max-label",label:a("userGroup.max"),type:"number",value:n.max,name:"max",onBlur:u,onChange:i,"aria-describedby":"helper-text-channel-max-label"}),t.max&&s.max?e.jsx(x,{error:!0,id:"helper-tex-channel-max-label",children:a(s.max)}):e.jsxs(x,{id:"helper-tex-channel-max-label",children:[" ",a("userGroup.maxTip")," "]})]}),e.jsx(S,{fullWidth:!0,children:e.jsx(Y,{control:e.jsx(J,{checked:n.public,onClick:()=>{p("public",!n.public)}}),label:a("userGroup.public")})}),e.jsxs(se,{children:[e.jsx(O,{onClick:C,children:a("userPage.cancel")}),e.jsx(O,{disableElevation:!0,disabled:P,type:"submit",variant:"contained",color:"primary",children:a("userPage.submit")})]})]})})})]})};ne.propTypes={open:G.bool,userGroupId:G.number,onCancel:G.func,onOk:G.func};function la(){const{t:r}=L(),[d,C]=c.useState(0),[g,l]=c.useState("desc"),[f,y]=c.useState("id"),[a,w]=c.useState(()=>Oe("userGroup")),[T,s]=c.useState(0),[u,i]=c.useState(!1),[p,m]=c.useState([]),[t,n]=c.useState(!1),[P,v]=c.useState(!1),[oe,M]=c.useState(0),le=(o,h)=>{h!==""&&(l(f===h&&g==="asc"?"desc":"asc"),y(h))},ie=(o,h)=>{C(h)},ce=o=>{const h=parseInt(o.target.value,10);C(0),w(h),De("userGroup",h)},ue=async(o,h,R,j)=>{i(!0);try{j&&(j=R==="desc"?"-"+j:j);const I=await F.get("/api/user_group/",{params:{page:o+1,size:h,order:j}}),{success:E,message:me,data:A}=I.data;E?(s(A.total_count),m(A.data)):W(me)}catch(I){console.error(I)}i(!1)},B=async()=>{y("id"),l("desc"),n(!t)};c.useEffect(()=>{ue(d,a,g,f)},[d,a,g,f,t]);const de=async(o,h)=>{const R="/api/user_group/";let j;try{switch(h){case"delete":j=await F.delete(R+o);break;case"status":j=await F.put(`${R}enable/${o}`);break;default:return!1}const{success:I,message:E}=j.data;return I?($(r("userPage.operationSuccess")),await B()):W(E),j.data}catch{return}},q=o=>{M(o),v(!0)},z=()=>
1{v(!1),M(0)},pe=o=>{o===!0&&(z(),B())};return e.jsxs(e.Fragment,{children:[e.jsxs(K,{direction:"row",alignItems:"center",justifyContent:"space-between",mb:5,children:[e.jsxs(K,{direction:"column",spacing:1,children:[e.jsx(V,{variant:"h2",children:r("userGroup.title")}),e.jsx(V,{variant:"subtitle1",color:"text.secondary",children:"User Group"})]}),e.jsx(O,{variant:"contained",color:"primary",startIcon:e.jsx(D,{icon:"solar:add-circle-line-duotone"}),onClick:()=>q(0),children:r("userGroup.create")})]}),e.jsxs(ge,{children:[e.jsx(ye,{sx:{textAlign:"right",height:50,display:"flex",justifyContent:"space-between",p:o=>o.spacing(0,1,0,3)},children:e.jsx(Se,{maxWidth:"xl",children:e.jsx(Me,{variant:"outlined","aria-label":"outlined small primary button group",children:e.jsx(O,{onClick:B,startIcon:e.jsx(D,{icon:"solar:refresh-bold-duotone",width:18}),children:r("userPage.refresh")})})})}),u&&e.jsx(Ge,{}),e.jsx(Ce,{component:"div",children:e.jsx(Te,{sx:{overflow:"unset"},children:e.jsxs(Ie,{sx:{minWidth:800},children:[e.jsx(Fe,{order:g,orderBy:f,onRequestSort:le,headLabel:[{id:"id",label:r("userGroup.id"),disableSort:!1},{id:"symbol",label:r("userGroup.symbol"),disableSort:!1},{id:"name",label:r("userGroup.name"),disableSort:!1},{id:"ratio",label:r("userGroup.ratio"),disableSort:!1},{id:"api_rate",label:r("userGroup.apiRate"),disableSort:!1},{id:"public",label:r("userGroup.public"),disableSort:!1},{id:"promotion",label:r("userGroup.promotion"),disableSort:!1},{id:"min",label:r("userGroup.min")+"($)",disableSort:!1},{id:"max",label:r("userGroup.max")+"($)",disableSort:!1},{id:"enable",label:r("userGroup.enable"),disableSort:!1},{id:"action",label:r("userPage.action"),disableSort:!0}]}),e.jsx(_e,{children:p.map(o=>e.jsx(te,{item:o,manageUserGroup:de,handleOpenModal:q,setModalUserGroupId:M},o.id))})]})})}),e.jsx(Be,{page:d,component:"div",count:T,rowsPerPage:a,onPageChange:ie,rowsPerPageOptions:Re,onRowsPerPageChange:ce,showFirstButton:!0,showLastButton:!0})]}),e.jsx(ne,{open:P,onCancel:z,onOk:pe,userGroupId:oe})]})}export{la 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.