"use strict";(self.webpackChunkunifiNetworkUi=self.webpackChunkunifiNetworkUi||[]).push([[8339],{33830:(e,t,n)=>{n.d(t,{$E:()=>i,Go:()=>s,JG:()=>r});var a=n(691189),l=n(348216);const i=(e={},t={})=>(0,a.t9)(l.MODEL,l.GET_PATH,e,{idField:"_id",...t}),r=e=>e._id?(0,a.vL)(l.MODEL,e._id,`${l.REST_PATH}/${e._id}`,e):(0,a.eC)(l.MODEL,l.REST_PATH,e),s=e=>(0,a.LK)(l.MODEL,e,`${l.REST_PATH}/${e}`)},116351:(e,t,n)=>{n.d(t,{U8:()=>d,Vj:()=>m,ls:()=>c});var a=n(801081),l=n(25553),i=n(87485),r=n(33830),s=n(195672);const o=(0,l.uh)((0,r.$E)()),c=(0,a.Mz)(o,i.kh),m=(0,a.Mz)(c,e=>e.filter(({amount:e})=>!(0,s.z)(e))),d=(0,a.Mz)(c,e=>e.find(({amount:e})=>(0,s.z)(e))||{})},195672:(e,t,n)=>{n.d(t,{z:()=>a});const a=e=>0===e},297465:(e,t,n)=>{n.d(t,{OL:()=>c,fX:()=>m,UY:()=>d,P5:()=>o});var a=n(953141),l=n(294201),i=n(742920),r=n(691189);const s="/api/s/{site}/cmd/hotspot",o=(e={},t={})=>(0,r.t9)("hotspotVouchers","/api/s/{site}/stat/voucher",e,{idField:"_id",...t}),c=e=>(0,r.Xj)(l.A.CREATE_VOUCHER,s,e,{failureToast:(e,t)=>({icon:i.C.danger,message:"HOTSPOT_VOUCHER_CREATE_ERROR",errorMessage:a.r[t.apiMsg],errorValues:t})}),m=e=>(0,r.Xj)(l.A.DELETE_VOUCHER,s,{_id:e},{failureToast:(e,t)=>({icon:i.C.danger,message:"HOTSPOT_VOUCHER_REVOKE_ERROR",values:{count:1},errorMessage:a.r[t.apiMsg],errorValues:t})}),d=(e,t=!1)=>(0,r.Xj)(l.A.DELETE_VOUCHERS,s,t?{all:!0}:{ids:e},{failureToast:(t,n)=>({icon:i.C.danger,message:"HOTSPOT_VOUCHER_REVOKE_ERROR",values:{count:e.length},errorMessage:a.r[n.apiMsg],errorValues:n})})},712492:(e,t,n)=>{n.d(t,{pV:()=>u,nY:()=>A,uS:()=>O});var a=n(801081),l=n(87485),i=n(25553),r=n(297465),s=n(376618),o=n(165126),c=n(546391);const m=e=>({...e,code:e.code.replace(c.fe,"$&-")}),d=(0,i.uh)((0,r.P5)()),E=(0,a.Mz)(d,l.kh),A=(0,a.Mz)(E,e=>e.map(m)),u=(0,a.Mz)(E,e=>{return t=(0,s.A)(e,({create_time:e,site_id:t,note:n})=>`${e}_${t}_${n}`),Object.keys(t).map(e=>t[e].reduce((t,n,a)=>(t.ids.push(n._id),t.id=e,t.amount+=n.quota,a?t:{...t,...(0,o.A)(n,"_id","code","used")}),{id:"",amount:0,ids:[]}));var t}),O=(0,a.Mz)(d,({lastFetchTime:e})=>Boolean(e))},10164:(e,t,n)=>{n.d(t,{A:()=>P});var a=n(296540),l=n(927099),i=n(75585),r=n(469733),s=n(758649),o=n(459449),c=n(294303),m=n(297465),d=n(712492),E=n(602021),A=n(792073),u=n(842630),O=n(566723),M=n(951272),_=n(321793),T=n(847883),C=n(71479),b=n(388151),h=n(705426),N=n(855630);const I=(0,C.A)(h.A)`
  header {
    height: ${O.nf};

    svg {
      display: none;
    }
  }
  > div {
    overflow: visible !important;
    padding: ${O.Ln} ${O.fS};
  }
  footer {
    margin-top: ${O.S2};
  }
`,p=_.OO.map(({value:e,label:t})=>a.createElement(b.A,{key:e,name:"usageType",type:"radio",value:e,fast:!0},a.createElement(o.sA,{id:t}))),v=({closeModal:e})=>{const{values:t,isSubmitting:n,isValid:l,handleSubmit:i}=(0,M.j7)(),r=(0,a.useMemo)(()=>[{disabled:n,text:a.createElement(o.sA,{id:"COMMON_ACTION_CANCEL"}),type:"button",variant:"default",onClick:e},{disabled:n||!l,text:a.createElement(o.sA,{id:"COMMON_ACTION_ADD"}),type:"button",variant:"primary",onClick:()=>i()}],[e,i,n,l]);return a.createElement(I,{size:"small",isOpen:!0,title:a.createElement(o.sA,{id:"HOTSPOT_VOUCHER_ADD_NEW"}),actions:r,onRequestClose:e},a.createElement(c.A,{flexDirection:"column"},a.createElement(T.A,null,a.createElement(c.A,{alignItems:"center",justifyContent:"space-between",width:"100%"},a.createElement(c.A,{width:"100%"},a.createElement(b.A,{full:!0,name:"note",variant:"secondary",label:"COMMON_NAME"})),a.createElement(c.A,{marginLeft:O.Ln,width:110},a.createElement(b.A,{full:!0,name:"n",type:"number",min:1,max:1e4,variant:"secondary",label:"COMMON_AMOUNT"})))),a.createElement(T.A,null,a.createElement(c.A,{gap:O.Ln},p)),t.usageType===N.w.MULTI_USE?a.createElement(T.A,null,a.createElement(c.A,{width:110},a.createElement(b.A,{full:!0,name:"quota",type:"number",min:1,max:1e4,variant:"secondary",label:"COMMON_USES_PER_VOUCHER"}))):null,a.createElement(T.A,null,a.createElement(c.A,{alignItems:"center",justifyContent:"space-between",width:"100%"},a.createElement(c.A,{width:"calc(50% - 8px)"},a.createElement(b.A,{full:!0,name:"expire_number",min:1,max:1e6,variant:"secondary",label:"COMMON_EXPIRATION"})),a.createElement(c.A,{width:"calc(50% - 8px)"},a.createElement(b.A,{name:"expire_unit",type:"dropdown",options:_.GJ,translateOptions:!0,full:!0,variant:"secondary",label:"COMMON_UNIT",translateLabel:!0})))),a.createElement(T.A,null,a.createElement(c.A,{width:"100%"},a.createElement(c.A,{width:"calc(50% - 8px)"},a.createElement(b.A,{full:!0,name:"bytes",min:1,max:1048576,variant:"secondary",label:"COMMON_DATA_LIMIT",placeholder:"COMMON_UNLIMITED",contentAfter:a.createElement(c.A,{marginRight:O.YC},a.createElement(o.sA,{id:"COMMON_UNIT_BYTES_SHORT",values:{prefix:"M"}}))})))),a.createElement(T.A,null,a.createElement(c.A,{alignItems:"center",justifyContent:"space-between",width:"100%"},a.createElement(c.A,{width:"calc(50% - 8px)"},a.createElement(b.A,{full:!0,name:"down",min:1,max:100,variant:"secondary",label:"COMMON_DOWNLOAD_LIMIT",contentAfter:a.createElement(c.A,{marginRight:O.xO},a.createElement(o.sA,{id:"COMMON_SPEED_METRICS_MBPS"}))})),a.createElement(c.A,{width:"calc(50% - 8px)"},a.createElement(b.A,{full:!0,name:"up",min:1,max:100,variant:"secondary",label:"COMMON_UPLOAD_LIMIT",contentAfter:a.createElement(c.A,{marginRight:O.xO},a.createElement(o.sA,{id:"COMMON_SPEED_METRICS_MBPS"}))}))))))},L=(e,t)=>{switch(e){case N.w.ONE_TIME:return 1;case N.w.UNLIMITED:return 0}return t};var U=n(870443);const g=U.A.object().shape({note:U.A.string().label("COMMON_NAME").required(),n:U.A.number().integer().label("COMMON_AMOUNT").required().min(1).max(1e4),usageType:U.A.string(),quota:U.A.number().when("usageType",{is:N.w.MULTI_USE,then:U.A.number().integer().label("COMMON_USES_PER_VOUCHER").required().min(1).max(1e4)}),expire_number:U.A.number().integer().label("COMMON_EXPIRATION").required().min(1).max(1e6),expire_unit:U.A.string().when("expire",{is:e=>!e,then:U.A.string().required()}),down:U.A.number().integer().label("COMMON_DOWNLOAD_LIMIT").min(1).max(100),up:U.A.number().integer().label("COMMON_UPLOAD_LIMIT").min(1).max(100),bytes:U.A.number().integer().label("COMMON_DATA_LIMIT").min(1).max(1048576)}),D=({closeModal:e})=>{const t=(0,r.useDispatch)(),n=(0,a.useCallback)((n,{setSubmitting:a})=>{t((0,m.OL)((({usageType:e,quota:t,up:n,down:a,bytes:l,expire:i,...r})=>({quota:L(e,t),up:n?1e3*n:void 0,down:a?1e3*a:void 0,bytes:l||void 0,expire:i||void 0,...r}))(n))).then(()=>{e(),t((0,m.P5)())}).catch(()=>{a(!1)})},[t,e]);return a.createElement(M.l1,{enableReinitialize:!0,initialValues:_.b$,validationSchema:g,onSubmit:n},a.createElement(v,{closeModal:e}))};var S=n(137298),y=n(287264),R=n(140271);const f=[{id:N.h.NAME,label:a.createElement(l.A,{size:"body",weight:"bold",color:"inherit"},a.createElement(o.sA,{id:_.z$[N.h.NAME]})),renderCell:({note:e})=>a.createElement(l.A,{size:"body"},e),minWidth:110},{id:N.h.AMOUNT,label:a.createElement(o.sA,{id:_.z$[N.h.AMOUNT]}),renderCell:({amount:e})=>a.createElement(l.A,{size:"body"},0===e?a.createElement(o.sA,{id:"COMMON_UNLIMITED"}):e),minWidth:60},{id:N.h.EXPIRATION,label:a.createElement(l.A,{size:"body",weight:"bold",color:"inherit"},a.createElement(o.sA,{id:_.z$[N.h.EXPIRATION]})),renderCell:({duration:e})=>a.createElement(l.A,{style:{textTransform:"capitalize"},color:"secondary",size:"body"},a.createElement(y.A,{duration:e})),minWidth:60},{id:N.h.TYPE,label:a.createElement(l.A,{size:"body",weight:"bold",color:"inherit"},a.createElement(o.sA,{id:_.z$[N.h.TYPE]})),renderCell:({quota:e})=>a.createElement(l.A,{size:"body"},a.createElement(o.sA,{id:(0,R.Q)(e)})),minWidth:70},{id:N.h.DATA_LIMIT,label:a.createElement(l.A,{size:"body",weight:"bold",color:"inherit"},a.createElement(o.sA,{id:_.z$[N.h.DATA_LIMIT]})),renderCell:({qos_usage_quota:e})=>a.createElement(l.A,{size:"body"},e?(0,S.Bn)(e):a.createElement(o.sA,{id:"COMMON_FALLBACK"})),minWidth:80},{id:N.h.DOWNLOAD_UPLOAD_LIMIT,label:a.createElement(l.A,{size:"body",weight:"bold",color:"inherit"},a.createElement(o.sA,{id:_.z$[N.h.DOWNLOAD_UPLOAD_LIMIT]})),renderCell:({qos_rate_max_down:e,qos_rate_max_up:t})=>a.createElement(l.A,{size:"body"},e?(0,S.Up)(e):a.createElement(o.sA,{id:"COMMON_FALLBACK"})," / ",t?(0,S.Up)(t):a.createElement(o.sA,{id:"COMMON_FALLBACK"})),minWidth:145}];var w=n(316400);const P=({isVouchersDefaultValid:e,groupedHotspotVouchers:t=[],onCancel:n,onlyVoucherForm:M=!1})=>{const _=(0,r.useDispatch)(),[T,C]=(0,a.useState)(!1),[b,h]=(0,a.useState)(!e),N=(0,r.useSelector)(d.uS)||M,I=(0,r.useSelector)(E.EL),p=(0,a.useCallback)(e=>{e?.preventDefault?.(),h(!0)},[]),v=(0,a.useCallback)(e=>{e?.preventDefault?.(),h(!1),n?.()},[n]),L=(0,a.useCallback)(e=>{e?.preventDefault?.(),C(!0)},[]),U=(0,a.useMemo)(()=>M?void 0:t.reduce((e,{ids:t})=>e+t.length,0),[M,t]),g=(0,a.useCallback)((e,t)=>(e?.preventDefault?.(),_(1===t.length?(0,m.fX)(t[0]):(0,m.UY)(t,t.length===U)).then(()=>_((0,m.P5)()))),[_,U]),S=(0,a.useMemo)(()=>[{type:"button",text:a.createElement(o.sA,{id:"COMMON_ACTION_CLOSE"}),onClick:v}],[v]),y=(0,a.useCallback)(e=>g(void 0,e.map(({ids:e})=>e).flat()),[g]),R=(0,a.useCallback)(()=>!I,[I]),P=(0,a.useCallback)(()=>C(!1),[]),x=(0,a.useCallback)(({note:e})=>e,[]);return N?a.createElement(a.Fragment,null,M||!b||T?null:a.createElement(w.s,{style:{content:{width:"767px",maxWidth:"100%"}},size:"large",onRequestClose:v,title:a.createElement(c.A,{width:"100%",justifyContent:"center"},a.createElement(o.sA,{id:"COMMON_VOUCHERS"})),actions:S},a.createElement(A.Ay,{columns:f,disableColumnFilters:!0,disableSelection:!0,disableTextPointer:!0,disableSort:!0,items:t,isRemovable:R,removeItems:y,getName:x,footerContent:a.createElement(u.A,null,a.createElement(s.A,{name:"add-new-voucher",size:"small",type:"button",variant:"inline",Icon:i.A,iconProps:{isActive:!0},onClick:L},a.createElement(l.A,{size:"body",color:"inherit"},a.createElement(o.sA,{id:"HOTSPOT_VOUCHER_ADD_NEW"}))))})),(b||M)&&T?a.createElement(D,{closeModal:P}):null,M?a.createElement(s.A,{style:{marginRight:O.kc},variant:"inline",type:"button",size:"medium",onClick:L},a.createElement(o.sA,{id:"HOTSPOT_ADD_VOUCHER"})):a.createElement(s.A,{type:"button",variant:"inline",size:"medium",onClick:p},a.createElement(l.A,{size:"inherit",color:"inherit"},a.createElement(o.sA,{id:"COMMON_ACTION_EDIT"})))):null}},316400:(e,t,n)=>{n.d(t,{s:()=>r});var a=n(71479),l=n(705426),i=n(566723);const r=(0,a.A)(l.A)`
  width: 408px;
  header {
    height: ${i.nf};
    svg {
      display: none;
    }
  }
  > div {
    overflow: visible !important;
    padding: ${i.Ln} ${i.fS};
  }
  footer {
    margin-top: ${i.S2};
  }
`},321793:(e,t,n)=>{n.d(t,{DG:()=>s,GJ:()=>m,OO:()=>l,b$:()=>c,b8:()=>i,j9:()=>r,z$:()=>o});var a=n(855630);const l=[{value:a.w.ONE_TIME,label:"HOTSPOT_VOUCHER_STATUS_VALID_ONE"},{value:a.w.MULTI_USE,label:"HOTSPOT_VOUCHER_STATUS_VALID_MULTI"},{value:a.w.UNLIMITED,label:"COMMON_UNLIMITED"}],i=1,r=60*i,s=24*r,o={[a.h.NAME]:"COMMON_NAME",[a.h.AMOUNT]:"COMMON_AMOUNT",[a.h.EXPIRATION]:"COMMON_EXPIRATION",[a.h.TYPE]:"COMMON_TYPE",[a.h.DATA_LIMIT]:"COMMON_DATA_LIMIT",[a.h.DOWNLOAD_UPLOAD_LIMIT]:"HOTSPOT_VOUCHER_TABLE_RATE_LIMIT"},c={note:"",n:10,usageType:l[0].value,quota:2,expire_number:24,expire_unit:r,down:void 0,up:void 0,bytes:void 0},m=[{value:s,label:"COMMON_UNIT_DAYS"},{value:r,label:"COMMON_UNIT_HOURS"},{value:i,label:"COMMON_UNIT_MINUTES"}]},855630:(e,t,n)=>{var a,l;n.d(t,{h:()=>a,w:()=>l}),function(e){e.NAME="note",e.AMOUNT="amount",e.EXPIRATION="duration",e.TYPE="quota",e.DATA_LIMIT="qos_usage_quota",e.DOWNLOAD_UPLOAD_LIMIT="qos_rate_max_down"}(a||(a={})),function(e){e.ONE_TIME="oneTime",e.MULTI_USE="multiUse",e.UNLIMITED="unlimited"}(l||(l={}))},287264:(e,t,n)=>{n.d(t,{A:()=>r});var a=n(296540),l=n(459449),i=n(321793);const r=({duration:e})=>e<i.j9?a.createElement(l.sA,{id:"COMMON_MINUTES",values:{minutes:Math.floor(e/i.b8)}}):e<i.DG?a.createElement(l.sA,{id:"COMMON_HOURS",values:{hours:Math.floor(e/i.j9)}}):a.createElement(l.sA,{id:"COMMON_DAYS",values:{days:Math.floor(e/i.DG)}})},140271:(e,t,n)=>{n.d(t,{Q:()=>a});const a=e=>0===e?"COMMON_UNLIMITED":e>1?"HOTSPOT_VOUCHER_STATUS_VALID_MULTI":"HOTSPOT_VOUCHER_STATUS_VALID_ONE"},879002:(e,t,n)=>{n.d(t,{A:()=>l});var a=n(296540);const l=(e,t,n=[])=>{const l=(0,a.useCallback)(({target:n})=>{e?.current&&n!==e.current&&!e.current.contains(n)&&t()},[t,e?.current]);(0,a.useEffect)(()=>(document.addEventListener("click",l),()=>{document.removeEventListener("click",l)}),[...n,l])}}}]);