@teamco/ischeduler-mui 2.0.9 → 2.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`@teamco/ischeduler-core`),l=require(`react`);l=s(l);let u=require(`@mui/material`),d=require(`@mui/x-date-pickers/DateTimePicker`),f=require(`@mui/x-date-pickers/LocalizationProvider`),p=require(`@mui/x-date-pickers/AdapterDayjs`),m=require(`dayjs`);m=s(m);let h=require(`react/jsx-runtime`),g=require(`@mui/icons-material/CalendarMonth`);g=s(g);let _=require(`@mui/icons-material/Settings`);_=s(_);let v=require(`@mui/icons-material/Add`);v=s(v);let y=require(`@mui/icons-material/DateRange`);y=s(y);let b=require(`@mui/icons-material/Close`);b=s(b);let x=require(`@mui/icons-material/Save`);x=s(x);let S=require(`@mui/icons-material/MoreVert`);S=s(S);let C=require(`@mui/icons-material/Refresh`);C=s(C);let w=require(`@mui/icons-material/Delete`);w=s(w);let T=require(`@mui/icons-material/Edit`);T=s(T);var E=e=>{let{t}=(0,c.useSchedulerContext)(),{min:n=1,label:r,disabled:i,durationTypes:a=[],exclude:o=[],typeValue:s,periodValue:l,onTypeChange:d,onValueChange:f}=e;return(0,h.jsxs)(u.Box,{sx:{display:`flex`,gap:1,width:`100%`},children:[(0,h.jsxs)(u.FormControl,{fullWidth:!0,size:`small`,children:[(0,h.jsx)(u.InputLabel,{id:`duration-type-label`,children:t(`scheduler.meta.period`)}),(0,h.jsx)(u.Select,{labelId:`duration-type-label`,value:s||``,label:t(`scheduler.meta.period`),disabled:i,onChange:e=>d?.(e.target.value),children:a.filter(e=>!o.includes(e)).map(e=>(0,h.jsx)(u.MenuItem,{value:e,children:c.EDurationTypes[e]},String(e)))})]}),(0,h.jsx)(u.TextField,{fullWidth:!0,size:`small`,type:`number`,label:r,value:l??``,disabled:i,slotProps:{htmlInput:{min:n}},onChange:e=>f?.(parseInt(e.target.value,10))})]})},D=e=>{let{options:t,value:n=[],onChange:r,disabled:i,loading:a,label:o,error:s,helperText:c}=e;return(0,h.jsxs)(u.Box,{children:[o&&(0,h.jsx)(u.Typography,{variant:`caption`,color:s?`error`:`textSecondary`,sx:{mb:.5,display:`block`},children:o}),(0,h.jsx)(u.ToggleButtonGroup,{value:n,onChange:(e,t)=>{r?.(t??[])},disabled:i||a,size:`small`,exclusive:!1,sx:{flexWrap:`wrap`,gap:.5,"& .MuiToggleButtonGroup-grouped":{margin:0,border:`1px solid rgba(0, 0, 0, 0.12) !important`,borderRadius:`4px !important`}},children:t.map(e=>(0,h.jsx)(u.ToggleButton,{value:e.value,sx:{minWidth:40,px:1},children:e.label},e.key))}),c&&(0,h.jsx)(u.FormHelperText,{error:s,children:c})]})},O=e=>{let{t,loading:n}=(0,c.useSchedulerContext)(),{value:r=[],onChange:i,disabled:a,setOccurs:o,scheduler:s}=e,d=(0,l.useRef)(s);(0,l.useEffect)(()=>{d.current=s},[s]);let f=(0,l.useMemo)(()=>Object.keys(c.EDays).map(e=>t(`scheduler.weekdays.short.${c.EDays[e].toLowerCase()}`)),[t]),p=(0,l.useMemo)(()=>Object.keys(c.EDays).map(e=>t(`scheduler.weekdays.${c.EDays[e].toLowerCase()}`)),[t]),m=e=>e.map((t,n)=>e[(n+c.CFirstDayIdx)%7]),g=m(f),_=m(p),v=g.map((e,t)=>{let n=_[t],r=(0,c.getKeyFromEnum)(c.EDays,n);return{key:`${e}-${t}`,label:e,value:r}}),y=(0,l.useCallback)(e=>{if(i){let n=e;i(n);let r=d.current,a={...r,repeat:{...r.repeat,weekly:{days:n}}};(0,c.handleDurationValueChange)(a.duration,a,o,t)}},[i,o,t]);return(0,h.jsx)(u.Box,{children:(0,h.jsx)(D,{label:t(`scheduler.days`),options:v,value:r,onChange:y,disabled:a,loading:n})})},k=e=>{let{t,loading:n}=(0,c.useSchedulerContext)(),{value:r,onChange:i,onWeeklyChange:a,disabled:o,setOccurs:s,scheduler:d}=e,f=(0,l.useRef)(d);(0,l.useEffect)(()=>{f.current=d},[d]);let p=r?.type||`DAY`,m=(e,n)=>{if(n!==null&&i){let e={...r,type:n,...n===`PERIOD`&&!r?.weekDay?{weekDay:`FIRST`}:{}};i(e);let a=f.current,o={...a,repeat:{...a.repeat,monthly:e}};n===`DAY`?(0,c.handleSelectWeeklyDay)(o.duration.period,o,s,t):(0,c.handleDurationValueChange)(o.duration,o,s,t)}},v=e=>{if(i){let n={...r,monthDay:e};i(n);let a=f.current;(0,c.handleSelectWeeklyDay)(e,{...a,repeat:{...a.repeat,monthly:n}},s,t)}},y=(e,n)=>{if(n!==null&&i){let e={...r,weekDay:n};i(e);let a=f.current,o={...a,repeat:{...a.repeat,monthly:e}};(0,c.handleDurationValueChange)(o.duration,o,s,t)}},b=[{value:`FIRST`,label:t(`scheduler.day.first`)},{value:`SECOND`,label:t(`scheduler.day.second`)},{value:`THIRD`,label:t(`scheduler.day.third`)},{value:`FOURTH`,label:t(`scheduler.day.fourth`)},{value:`LAST`,label:t(`scheduler.day.last`)}];return(0,h.jsxs)(u.Box,{sx:{display:`flex`,flexDirection:`column`,gap:2},children:[(0,h.jsxs)(u.ToggleButtonGroup,{value:p,exclusive:!0,onChange:m,disabled:o||n,size:`small`,children:[(0,h.jsxs)(u.ToggleButton,{value:`DAY`,"aria-label":`day`,children:[(0,h.jsx)(g.default,{fontSize:`small`,sx:{mr:1}}),t(`scheduler.day`)]}),(0,h.jsxs)(u.ToggleButton,{value:`PERIOD`,"aria-label":`period`,children:[(0,h.jsx)(_.default,{fontSize:`small`,sx:{mr:1}}),t(`scheduler.meta.period`)]})]}),p===`DAY`?(0,h.jsx)(u.TextField,{label:t(`scheduler.day`),type:`number`,size:`small`,value:r?.monthDay??``,disabled:o||n,slotProps:{htmlInput:{min:1,max:31}},onChange:e=>v(parseInt(e.target.value,10)),sx:{width:120}}):(0,h.jsxs)(u.Box,{sx:{display:`flex`,flexDirection:`column`,gap:2},children:[(0,h.jsx)(u.ToggleButtonGroup,{value:r?.weekDay||``,exclusive:!0,onChange:y,disabled:o||n,size:`small`,sx:{flexWrap:`wrap`},children:b.map(e=>(0,h.jsx)(u.ToggleButton,{value:e.value,children:e.label},e.value))}),(0,h.jsx)(O,{value:d.repeat?.weekly?.days,onChange:e=>{a?.(e)},disabled:o,setOccurs:s,scheduler:d})]})]})},A=e=>{let{t,loading:n}=(0,c.useSchedulerContext)(),{value:r,onChange:i,disabled:a,setOccurs:o,scheduler:s,repeatMonthly:d,onMonthlyChange:f,onWeeklyChange:p}=e,m=(0,l.useRef)(s);(0,l.useEffect)(()=>{m.current=s},[s]);let g=(0,l.useMemo)(()=>Object.keys(c.EMonths).map(e=>t(`scheduler.months.${c.EMonths[e].toLowerCase()}`)),[t]),_=(0,l.useMemo)(()=>Object.keys(c.EMonths).map(e=>t(`scheduler.months.short.${c.EMonths[e].toLowerCase()}`)),[t]),v=Object.keys(c.EMonths).map((e,t)=>({key:`${e}-${t}`,label:(0,h.jsx)(u.Tooltip,{title:g[t],children:(0,h.jsx)(`span`,{children:_[t]})}),value:e}));return(0,h.jsxs)(u.Box,{sx:{display:`flex`,flexDirection:`column`,gap:3},children:[(0,h.jsx)(D,{label:t(`scheduler.months`),options:v,value:r?.months||[],onChange:e=>{if(i){let n=e,a={...r,months:n};i(a);let s=m.current,l={...s,repeat:{...s.repeat,yearly:a}};(0,c.handleDurationValueChange)(l.duration,l,o,t)}},disabled:a,loading:n}),(0,h.jsx)(k,{value:d,onChange:f,onWeeklyChange:p,disabled:a,setOccurs:o,scheduler:s})]})},j=e=>{let{disabled:t,value:n,startedAt:r,onChange:i}=e,{t:a}=(0,c.useSchedulerContext)(),o=r?(0,m.default)(r).add(1,`day`):(0,m.default)();return(0,h.jsx)(d.DateTimePicker,{label:a(`scheduler.duration.endDate`),value:n??null,onChange:i,disabled:t||!r,minDateTime:o,slotProps:{textField:{size:`small`,fullWidth:!0}}})},M=e=>{let{t}=(0,c.useSchedulerContext)(),{min:n=1,value:r,onChange:i,disabled:a=!1}=e;return(0,h.jsx)(u.TextField,{fullWidth:!0,size:`small`,type:`number`,label:t(`scheduler.occurrences`),value:r??``,disabled:a,slotProps:{htmlInput:{min:n}},onChange:e=>i?.(parseInt(e.target.value,10))})},N=e=>{let{t,loading:n}=(0,c.useSchedulerContext)(),{value:r,onChange:i,disabled:a=!1,durationTypes:o=Object.keys(c.EDurationTypes),discountTypes:s=Object.keys(c.EDiscountType),schedulerType:g}=e,_=g===c.ESchedulerPrefix.SALE?c.DEFAULT_SALE_SCHEDULER:c.DEFAULT_DISCOUNT_SCHEDULER,[v,y]=(0,l.useState)(()=>_),b=r??v,[x,S]=(0,l.useState)(`0`),[C,w]=(0,l.useState)(null);(0,l.useEffect)(()=>{b.range?.startedAt&&(0,c.handleChangeStartDate)((0,m.default)(b.range.startedAt),w),b.duration&&(0,c.handleDurationValueChange)(b.duration,b,S,t)},[r,t]);let T=(e,t)=>{let n=e.split(`.`),r=(e,t,n)=>{if(t.length===1)return{...e,[t[0]]:n};let[i,...a]=t;return{...e,[i]:r(e[i]??{},a,n)}},a=r(b,n,t);y(a),i?.(a)};return(0,h.jsx)(f.LocalizationProvider,{dateAdapter:p.AdapterDayjs,children:(0,h.jsxs)(u.Box,{sx:{display:`flex`,flexDirection:`column`,gap:3,py:2},children:[[c.ESchedulerPrefix.DISCOUNT,c.ESchedulerPrefix.TRIAL_DISCOUNT].includes(g)&&(0,h.jsx)(u.Grid2,{container:!0,spacing:2,children:(0,h.jsx)(u.Grid2,{size:{xs:12,sm:6},children:(0,h.jsxs)(u.Box,{sx:{display:`flex`,gap:1},children:[(0,h.jsxs)(u.FormControl,{fullWidth:!0,size:`small`,children:[(0,h.jsx)(u.InputLabel,{children:t(`scheduler.meta.duration`)}),(0,h.jsx)(u.Select,{value:b.discount?.type||``,label:t(`scheduler.meta.duration`),disabled:a||n,onChange:e=>T(`discount.type`,e.target.value),children:s.map(e=>(0,h.jsx)(u.MenuItem,{value:e,children:c.EDiscountType[e]},String(e)))})]}),(0,h.jsx)(u.TextField,{fullWidth:!0,size:`small`,type:`number`,label:t(`scheduler.meta.duration`),value:b.discount?.value||``,disabled:a||n,onChange:e=>T(`discount.value`,parseInt(e.target.value,10))})]})})}),(0,h.jsxs)(u.Grid2,{container:!0,spacing:2,children:[(0,h.jsx)(u.Grid2,{size:{xs:12,sm:6},children:(0,h.jsx)(E,{label:t(`scheduler.duration`),disabled:a||n,typeValue:b.duration?.type,periodValue:b.duration?.period,durationTypes:o,required:!0,onTypeChange:e=>T(`duration.type`,e),onValueChange:e=>T(`duration.period`,e)})}),(0,h.jsx)(u.Grid2,{size:{xs:12,sm:6},children:(0,h.jsx)(d.DateTimePicker,{label:t(`scheduler.startedAt`),value:(0,m.default)(b.range?.startedAt),onChange:e=>T(`range.startedAt`,e),disabled:a||n,slotProps:{textField:{size:`small`,fullWidth:!0}}})})]}),b.duration?.type===`WEEK`&&(0,h.jsx)(O,{value:b.repeat?.weekly?.days,onChange:e=>T(`repeat.weekly.days`,e),disabled:a,setOccurs:S,scheduler:b}),b.duration?.type===`MONTH`&&(0,h.jsx)(k,{value:b.repeat?.monthly,onChange:e=>T(`repeat.monthly`,e),onWeeklyChange:e=>T(`repeat.weekly.days`,e),disabled:a,setOccurs:S,scheduler:b}),b.duration?.type===`YEAR`&&(0,h.jsx)(A,{value:b.repeat?.yearly,onChange:e=>T(`repeat.yearly`,e),disabled:a,setOccurs:S,scheduler:b,repeatMonthly:b.repeat?.monthly,onMonthlyChange:e=>T(`repeat.monthly`,e),onWeeklyChange:e=>T(`repeat.weekly.days`,e)}),(0,h.jsxs)(u.Grid2,{container:!0,spacing:2,children:[(0,h.jsx)(u.Grid2,{size:{xs:12,sm:6},children:(0,h.jsxs)(u.FormControl,{fullWidth:!0,size:`small`,children:[(0,h.jsx)(u.InputLabel,{children:t(`scheduler.duration.end`)}),(0,h.jsx)(u.Select,{value:b.range?.endReason?.type||``,label:t(`scheduler.duration.end`),disabled:a,onChange:e=>T(`range.endReason.type`,e.target.value),children:[{label:t(`scheduler.duration.end.day`),value:c.CEndReasonTypes[0]},{label:t(`scheduler.duration.end.after`),value:c.CEndReasonTypes[1]},{label:t(`scheduler.duration.end.no`),value:c.CEndReasonTypes[2]}].map(e=>(0,h.jsx)(u.MenuItem,{value:e.value,children:e.label},e.value))})]})}),(0,h.jsxs)(u.Grid2,{size:{xs:12,sm:6},children:[b.range?.endReason?.type===c.CEndReasonTypes[0]&&(0,h.jsx)(j,{value:(0,m.default)(b.range?.endReason?.expiredAt),startedAt:(0,m.default)(b.range?.startedAt),onChange:e=>T(`range.endReason.expiredAt`,e),disabled:a}),b.range?.endReason?.type===c.CEndReasonTypes[1]&&(0,h.jsx)(M,{value:b.range?.endReason?.occurrences,onChange:e=>T(`range.endReason.occurrences`,e),disabled:a})]})]}),(0,h.jsx)(u.Typography,{variant:`body2`,sx:{fontStyle:`italic`,color:`text.secondary`},dangerouslySetInnerHTML:{__html:t(`scheduler.result`,{occurs:x,startAt:C??``})}})]})})},P=e=>{let{t,permissions:n}=(0,c.useSchedulerContext)(),{loading:r,className:i,isEdit:a,disabled:o,size:s=`small`,color:l=`primary`,icon:d=(0,h.jsx)(x.default,{fontSize:`small`}),type:f=`button`,variant:p=`contained`,onClick:m}=e;if(!(a?n.canUpdate:n.canCreate))return null;let g=t(a?`actions.update`:`actions.save`);return(0,h.jsx)(u.Button,{type:f,size:s,variant:p,className:i,disabled:o||r,startIcon:r?(0,h.jsx)(u.CircularProgress,{size:16,color:`inherit`}):d,onClick:m,color:l,children:g})},F=({schedulerType:e,disabled:t,onSuccess:n,setDirty:r,dirty:i,isCreating:a,setIsCreating:o,buttonProps:s})=>{let{t:d,loading:f,permissions:p,onCreate:m}=(0,c.useSchedulerContext)(),[g,_]=(0,l.useState)(!1),v=(0,l.useMemo)(()=>e===c.ESchedulerPrefix.SALE?c.DEFAULT_SALE_SCHEDULER:c.DEFAULT_DISCOUNT_SCHEDULER,[e]),[x,S]=(0,l.useState)(v);if(!p.canCreate)return null;let C=e=>{e.preventDefault(),e.stopPropagation(),S(v),_(!0)},w=()=>{_(!1),r(!1)},T=async()=>{try{o(!0);let t={id:`new-${Date.now()}`,...x,type:e,[c.CNsDiscount]:e===c.ESchedulerPrefix.SALE?null:x?.[c.CNsDiscount]};m&&await m(e,t),n?.(t),_(!1),r(!1)}catch(e){console.error(`Failed to save scheduler:`,e)}finally{o(!1)}};return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(u.Tooltip,{title:t?d(`scheduler.limited`,{limit:c.DEFAULT_SCHEDULERS_LIMIT}):``,children:(0,h.jsx)(`span`,{children:(0,h.jsx)(u.Button,{variant:`text`,size:`small`,...s,disabled:t||f,onClick:C,sx:{textTransform:`none`,p:0,minWidth:`auto`,...s?.sx},children:d(`scheduler`)})})}),(0,h.jsx)(u.Drawer,{anchor:`right`,open:g,onClose:w,PaperProps:{sx:{width:{xs:`100%`,sm:600},p:0}},children:(0,h.jsxs)(u.Box,{sx:{display:`flex`,flexDirection:`column`,height:`100%`},children:[(0,h.jsxs)(u.Box,{sx:{p:2,display:`flex`,alignItems:`center`,justifyContent:`space-between`},children:[(0,h.jsxs)(u.Box,{sx:{display:`flex`,alignItems:`center`,gap:1},children:[(0,h.jsx)(y.default,{color:`primary`}),(0,h.jsx)(u.Typography,{variant:`h6`,children:d(`scheduler`)})]}),(0,h.jsxs)(u.Box,{sx:{display:`flex`,alignItems:`center`,gap:1},children:[(0,h.jsx)(P,{loading:f||a,disabled:t||!i,onClick:T}),(0,h.jsx)(u.IconButton,{onClick:w,size:`small`,children:(0,h.jsx)(b.default,{})})]})]}),(0,h.jsx)(u.Divider,{}),(0,h.jsx)(u.Box,{sx:{p:3,flexGrow:1,overflowY:`auto`},children:(0,h.jsx)(N,{schedulerType:e,value:x,onChange:e=>{S(e),r(!0)},disabled:t})})]})})]})},I=e=>{let{t}=(0,c.useSchedulerContext)(),{selectedColumns:n=[],columnsList:r=[],onChange:i}=e;if(!r?.length)return(0,h.jsx)(h.Fragment,{});let a=t(`table.hideColumns`);return(0,h.jsxs)(u.FormControl,{sx:{m:1,minWidth:250},size:`small`,children:[(0,h.jsx)(u.InputLabel,{id:`hide-columns-label`,children:a}),(0,h.jsx)(u.Select,{labelId:`hide-columns-label`,id:`hide-columns-select`,multiple:!0,value:n,onChange:e=>{let t=e.target.value,n=typeof t==`string`?t.split(`,`):t;n.length<1||i?.(n)},input:(0,h.jsx)(u.OutlinedInput,{label:a}),renderValue:e=>e.map(e=>r.find(t=>t.value===e)?.label??e).join(`, `),sx:{maxHeight:40},children:r.map(e=>(0,h.jsxs)(u.MenuItem,{value:e.value,children:[(0,h.jsx)(u.Checkbox,{checked:n.indexOf(e.value)>-1,size:`small`}),(0,h.jsx)(u.ListItemText,{primary:e.label})]},e.value))})]})},L=e=>{let{loading:t,t:n}=(0,c.useSchedulerContext)(),{children:r,items:i=[],onRefresh:a}=e,[o,s]=(0,l.useState)(null),d=!!o,f=e=>{s(e.currentTarget)},p=()=>{s(null)};return(0,h.jsxs)(u.Box,{sx:{display:`flex`,alignItems:`center`,justifyContent:`flex-end`,gap:1,mb:1},children:[r,(0,h.jsx)(u.IconButton,{"aria-label":`more`,id:`toolbar-button`,"aria-controls":d?`toolbar-menu`:void 0,"aria-expanded":d?`true`:void 0,"aria-haspopup":`true`,onClick:f,size:`small`,children:t?(0,h.jsx)(u.CircularProgress,{size:20}):(0,h.jsx)(S.default,{})}),(0,h.jsxs)(u.Menu,{id:`toolbar-menu`,anchorEl:o,open:d,onClose:p,MenuListProps:{"aria-labelledby":`toolbar-button`},children:[i.map((e,t)=>(0,h.jsxs)(u.MenuItem,{onClick:()=>{e.onClick?.(),p()},children:[e.icon&&(0,h.jsx)(u.ListItemIcon,{children:e.icon}),(0,h.jsx)(u.ListItemText,{children:e.label})]},t)),i.length>0&&a&&(0,h.jsx)(u.Divider,{}),a&&(0,h.jsxs)(u.MenuItem,{onClick:()=>{a(),p()},children:[(0,h.jsx)(u.ListItemIcon,{children:(0,h.jsx)(C.default,{fontSize:`small`})}),(0,h.jsx)(u.ListItemText,{children:n(`toolbar.refresh`)})]})]})]})},R={ACTIVE:`success`,DEACTIVATED:`default`,DELETED:`error`,PROCESSING:`info`,PENDING:`warning`,APPROVED:`success`,PUBLISHED:`primary`},z=({status:e})=>(0,h.jsx)(u.Chip,{label:String(e),size:`small`,color:R[e]||`default`,variant:`outlined`}),B=e=>{let{t,permissions:n}=(0,c.useSchedulerContext)(),{entity:r,disabled:i,onDelete:a,showLabel:o=!1}=e,[s,d]=(0,l.useState)(!1);if(!r||!n.canDelete)return null;let f=e=>{e.stopPropagation(),d(!0)},p=e=>{e.stopPropagation(),d(!1)};return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(u.Tooltip,{title:t(`actions.delete`),children:(0,h.jsx)(`span`,{children:(0,h.jsxs)(u.IconButton,{color:`error`,size:`small`,onClick:f,disabled:i,children:[(0,h.jsx)(w.default,{fontSize:`small`}),o&&t(`actions.delete`)]})})}),(0,h.jsxs)(u.Dialog,{open:s,onClose:p,onClick:e=>e.stopPropagation(),children:[(0,h.jsx)(u.DialogTitle,{children:t(`actions.delete`)}),(0,h.jsx)(u.DialogContent,{children:(0,h.jsx)(u.DialogContentText,{children:t(`actions.confirm.delete`)})}),(0,h.jsxs)(u.DialogActions,{children:[(0,h.jsx)(u.Button,{onClick:p,size:`small`,children:t(`actions.cancel`)}),(0,h.jsx)(u.Button,{onClick:e=>{e.stopPropagation(),a?.(r),d(!1)},color:`error`,variant:`contained`,size:`small`,autoFocus:!0,children:t(`actions.delete`)})]})]})]})},V=e=>{let{t,permissions:n}=(0,c.useSchedulerContext)(),{entity:r,disabled:i,onEdit:a,showLabel:o=!1}=e;return!r||!n.canUpdate?null:(0,h.jsx)(u.Tooltip,{title:t(`actions.edit`),children:(0,h.jsx)(`span`,{children:(0,h.jsxs)(u.IconButton,{color:`primary`,size:`small`,onClick:e=>{e.stopPropagation(),a?.(r)},disabled:i,children:[(0,h.jsx)(T.default,{fontSize:`small`}),o&&t(`actions.edit`)]})})})},H=e=>(0,h.jsx)(u.Box,{sx:{display:`flex`,flexWrap:`wrap`,gap:.5},children:e?.days.map((e,t)=>(0,h.jsx)(u.Chip,{label:e,size:`small`,variant:`outlined`,color:`primary`},t))}),U=(e,t)=>e?.type===`PERIOD`?(0,h.jsx)(u.Box,{sx:{display:`flex`,flexWrap:`wrap`,gap:.5},children:t?.days.map((t,n)=>(0,h.jsx)(u.Chip,{label:`${e.weekDay} ${t}`,size:`small`,variant:`outlined`,color:`secondary`},n))}):(0,h.jsx)(u.Box,{sx:{display:`flex`,flexWrap:`wrap`,gap:.5},children:(0,h.jsx)(u.Chip,{label:e?.monthDay?.toString(),size:`small`,variant:`outlined`,color:`info`},`monthDay`)}),W=(e,t,n)=>(0,h.jsxs)(u.Box,{sx:{display:`flex`,flexDirection:`column`,gap:.5},children:[U(t,n),(0,h.jsx)(u.Box,{sx:{display:`flex`,flexWrap:`wrap`,gap:.5},children:e?.months?.map((e,t)=>(0,h.jsx)(u.Chip,{label:e,size:`small`,variant:`outlined`,color:`warning`},t))})]}),G=e=>{let{disabled:t,schedulerType:n,currency:r,t:i,onEdit:a,onDelete:o}=e;return[{id:`index`,key:`index`,label:`#`,minWidth:50},{id:`duration`,key:`duration`,label:i(`scheduler.meta.duration`),minWidth:120,format:e=>{let t=e;return`${t?.period} (${t?.type})`}},{id:`repeat`,key:`repeat`,label:i(`scheduler.duration`),minWidth:200,format:(e,t)=>{let{duration:n,repeat:r}=t,{weekly:i,monthly:a,yearly:o}=r;switch(n?.type){case`WEEK`:return H(i);case`MONTH`:return U(a,i);case`YEAR`:return W(o,a,i);default:return null}}},[c.ESchedulerPrefix.DISCOUNT,c.ESchedulerPrefix.TRIAL_DISCOUNT].includes(n)?{id:`discount`,key:`discount`,label:i(`scheduler.meta.duration`),minWidth:120,format:e=>{let t=e;return t?t.type===`PERCENT`?`${t.value}${c.CDiscountTypeValues[t.type]}`:(0,c.numberToCurrency)(t.value,r??`USD`):`—`}}:null,{id:`status`,key:`status`,label:i(`scheduler.status`),minWidth:120,align:`center`,concealable:!0,format:e=>(0,h.jsx)(z,{status:e})},{id:`updatedAt`,key:`updatedAt`,label:i(`scheduler.updatedAt`),minWidth:180,align:`center`,concealable:!0,format:e=>{let t=e;return(0,h.jsx)(`span`,{children:t?.updatedAt?(0,c.tsToLocaleDateTime)((0,m.default)(t.updatedAt).toDate()):`—`})}},a||o?{id:`actions`,key:`actions`,label:i(`table.actions`),minWidth:100,align:`center`,format:(e,n)=>(0,h.jsxs)(u.Box,{sx:{display:`flex`,justifyContent:`center`,gap:.5},children:[a&&(0,h.jsx)(V,{onEdit:a,disabled:t,entity:n}),o&&(0,h.jsx)(B,{onDelete:o,entity:n,disabled:t})]})}:null].filter(Boolean)},K=e=>e.map((e,t)=>({...e,key:e.id||t.toString(),index:t+1})),q=()=>({title:`#`,dataIndex:`index`,key:`index`,width:50}),J=e=>({title:e(`table.actions`),key:`actions`,width:100}),Y=e=>{let{type:t,title:n,disabled:r,readOnlyFields:i=[],currency:a,onRefresh:o}=e,{schedulers:s,loading:d,disabled:f,t:p,permissions:m,onUpdate:g,onDelete:_}=(0,c.useSchedulerContext)(),x=r??f,[S,C]=(0,l.useState)(new Set),[w,T]=(0,l.useState)(!1),[E,D]=(0,l.useState)(!1),[O,k]=(0,l.useState)(!1),[A,j]=(0,l.useState)(null),[M,R]=(0,l.useState)(0),[z,B]=(0,l.useState)(10),V=(0,l.useMemo)(()=>{let e=s[t]??[];return S.size>0&&(e=e.filter(e=>!e.id||!S.has(e.id))),K(e)},[s,t,S]),H=V.length>=c.DEFAULT_SCHEDULERS_LIMIT,U=(0,l.useCallback)(e=>{j(JSON.parse(JSON.stringify(e))),k(!0),T(!1)},[]),W=async()=>{if(!(!A||!g))try{await g(t,A),k(!1),j(null),T(!1),o?.()}catch(e){console.error(`Failed to update scheduler:`,e)}},q=(0,l.useCallback)(async e=>{if(e.id?.startsWith(`new-`)){C(t=>{let n=new Set(t);return e.id&&n.add(e.id),n});return}_&&e.id&&(await _(t,e.id),o?.())},[_,t,o]),{filteredColumns:J,columnsList:Y,selectedColumns:X,setSelectedColumns:Z}=(0,c.useColumnsToggle)((0,l.useMemo)(()=>G({disabled:x,schedulerType:t,entities:V,currency:a,t:p,onEdit:m.canUpdate?U:void 0,onDelete:m.canDelete?q:void 0}),[x,t,V,a,p,m,U,q])),Q=(e,t)=>{R(t)},ee=e=>{B(parseInt(e.target.value,10)),R(0)},$=V.slice(M*z,M*z+z);return(0,h.jsxs)(u.Paper,{sx:{width:`100%`,overflow:`hidden`,mb:2},children:[(0,h.jsx)(u.Box,{sx:{p:2,display:`flex`,alignItems:`center`,justifyContent:`flex-end`,gap:2},children:(0,h.jsx)(L,{onRefresh:o,items:m.canCreate&&!H?[{label:(0,h.jsx)(F,{setDirty:T,dirty:w,isCreating:E,setIsCreating:D,schedulerType:t,disabled:x||d||H||E,onSuccess:()=>o?.(),buttonProps:{startIcon:(0,h.jsx)(v.default,{})}}),onClick:()=>{}}]:[],children:(0,h.jsx)(I,{columnsList:Y,selectedColumns:X,onChange:Z})})}),(0,h.jsx)(u.TableContainer,{sx:{maxHeight:440},children:(0,h.jsxs)(u.Table,{stickyHeader:!0,"aria-label":`schedulers table`,size:`small`,children:[(0,h.jsx)(u.TableHead,{children:(0,h.jsx)(u.TableRow,{children:J.filter(e=>!e.hidden).map(e=>(0,h.jsx)(u.TableCell,{align:e.align,style:{minWidth:e.minWidth},children:e.label},e.id))})}),(0,h.jsxs)(u.TableBody,{children:[$.map(e=>(0,h.jsx)(u.TableRow,{hover:!0,role:`checkbox`,tabIndex:-1,children:J.filter(e=>!e.hidden).map(t=>{let n=t.id.includes(`.`)?t.id.split(`.`).reduce((e,t)=>e?.[t],e):e[t.id];return(0,h.jsx)(u.TableCell,{align:t.align,children:t.format?t.format(n,e):n},t.id)})},e.key)),$.length===0&&(0,h.jsx)(u.TableRow,{children:(0,h.jsx)(u.TableCell,{colSpan:J.length,align:`center`,sx:{py:3},children:(0,h.jsx)(u.Typography,{variant:`body2`,color:`text.secondary`,children:`No items found`})})})]})]})}),(0,h.jsx)(u.TablePagination,{rowsPerPageOptions:[5,10,25,100],component:`div`,count:V.length,rowsPerPage:z,page:M,onPageChange:Q,onRowsPerPageChange:ee}),(0,h.jsx)(u.Drawer,{anchor:`right`,open:O,onClose:()=>{k(!1),j(null)},PaperProps:{sx:{width:{xs:`100%`,sm:600},p:0}},children:(0,h.jsxs)(u.Box,{sx:{display:`flex`,flexDirection:`column`,height:`100%`},children:[(0,h.jsxs)(u.Box,{sx:{p:2,display:`flex`,alignItems:`center`,justifyContent:`space-between`},children:[(0,h.jsxs)(u.Box,{sx:{display:`flex`,alignItems:`center`,gap:1},children:[(0,h.jsx)(y.default,{color:`primary`}),(0,h.jsx)(u.Typography,{variant:`h6`,children:n??p(`scheduler`)})]}),(0,h.jsxs)(u.Box,{sx:{display:`flex`,alignItems:`center`,gap:1},children:[(0,h.jsx)(P,{isEdit:!0,loading:d,disabled:x||!w||E,onClick:W}),(0,h.jsx)(u.IconButton,{onClick:()=>k(!1),size:`small`,children:(0,h.jsx)(b.default,{})})]})]}),(0,h.jsx)(u.Divider,{}),(0,h.jsx)(u.Box,{sx:{p:3,flexGrow:1,overflowY:`auto`},children:O&&A&&(0,h.jsx)(N,{schedulerType:t,value:A,onChange:e=>{j(e),T(!0)},disabled:x,readOnlyFields:i})})]})})]})};exports.Scheduler=N,exports.SchedulerDrawerButton=F,exports.SchedulersList=Y,exports.actionField=J,exports.indexColumn=q,exports.indexable=K,Object.keys(c).forEach(function(e){e!==`default`&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return c[e]}})});
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`@teamco/ischeduler-core`),l=require(`react`);l=s(l);let u=require(`@mui/material`),d=require(`@mui/x-date-pickers/DateTimePicker`),f=require(`@mui/x-date-pickers/LocalizationProvider`),p=require(`@mui/x-date-pickers/AdapterDayjs`),m=require(`dayjs`);m=s(m);let h=require(`react/jsx-runtime`),g=require(`@mui/icons-material/CalendarMonth`);g=s(g);let _=require(`@mui/icons-material/Settings`);_=s(_);let v=require(`@mui/icons-material/Add`);v=s(v);let y=require(`@mui/icons-material/DateRange`);y=s(y);let b=require(`@mui/icons-material/Close`);b=s(b);let x=require(`@mui/icons-material/Save`);x=s(x);let S=require(`@mui/icons-material/MoreVert`);S=s(S);let C=require(`@mui/icons-material/Refresh`);C=s(C);let w=require(`@mui/icons-material/Delete`);w=s(w);let T=require(`@mui/icons-material/Edit`);T=s(T);var E=e=>{let{t}=(0,c.useSchedulerContext)(),{min:n=1,label:r,disabled:i,durationTypes:a=[],exclude:o=[],typeValue:s,periodValue:l,onTypeChange:d,onValueChange:f}=e;return(0,h.jsxs)(u.Box,{sx:{display:`flex`,gap:1,width:`100%`},children:[(0,h.jsxs)(u.FormControl,{fullWidth:!0,size:`small`,children:[(0,h.jsx)(u.InputLabel,{id:`duration-type-label`,children:t(`scheduler.meta.period`)}),(0,h.jsx)(u.Select,{labelId:`duration-type-label`,value:s||``,label:t(`scheduler.meta.period`),disabled:i,onChange:e=>d?.(e.target.value),children:a.filter(e=>!o.includes(e)).map(e=>(0,h.jsx)(u.MenuItem,{value:e,children:c.EDurationTypes[e]},String(e)))})]}),(0,h.jsx)(u.TextField,{fullWidth:!0,size:`small`,type:`number`,label:r,value:l??``,disabled:i,slotProps:{htmlInput:{min:n}},onChange:e=>f?.(parseInt(e.target.value,10))})]})},D=e=>{let{options:t,value:n=[],onChange:r,disabled:i,loading:a,label:o,error:s,helperText:c}=e;return(0,h.jsxs)(u.Box,{children:[o&&(0,h.jsx)(u.Typography,{variant:`caption`,color:s?`error`:`textSecondary`,sx:{mb:.5,display:`block`},children:o}),(0,h.jsx)(u.ToggleButtonGroup,{value:n,onChange:(e,t)=>{r?.(t??[])},disabled:i||a,size:`small`,exclusive:!1,sx:{flexWrap:`wrap`,gap:.5,"& .MuiToggleButtonGroup-grouped":{margin:0,border:`1px solid rgba(0, 0, 0, 0.12) !important`,borderRadius:`4px !important`}},children:t.map(e=>(0,h.jsx)(u.ToggleButton,{value:e.value,sx:{minWidth:40,px:1},children:e.label},e.key))}),c&&(0,h.jsx)(u.FormHelperText,{error:s,children:c})]})},O=e=>{let{t,loading:n}=(0,c.useSchedulerContext)(),{value:r=[],onChange:i,disabled:a,setOccurs:o,scheduler:s}=e,d=(0,l.useRef)(s);(0,l.useEffect)(()=>{d.current=s},[s]);let f=(0,l.useMemo)(()=>Object.keys(c.EDays).map(e=>t(`scheduler.weekdays.short.${c.EDays[e].toLowerCase()}`)),[t]),p=(0,l.useMemo)(()=>Object.keys(c.EDays).map(e=>t(`scheduler.weekdays.${c.EDays[e].toLowerCase()}`)),[t]),m=e=>e.map((t,n)=>e[(n+c.CFirstDayIdx)%7]),g=m(f),_=m(p),v=g.map((e,t)=>{let n=_[t],r=(0,c.getKeyFromEnum)(c.EDays,n);return{key:`${e}-${t}`,label:e,value:r}}),y=(0,l.useCallback)(e=>{if(i){let n=e;i(n);let r=d.current,a={...r,repeat:{...r.repeat,weekly:{days:n}}};(0,c.handleDurationValueChange)(a.duration,a,o,t)}},[i,o,t]);return(0,h.jsx)(u.Box,{children:(0,h.jsx)(D,{label:t(`scheduler.days`),options:v,value:r,onChange:y,disabled:a,loading:n})})},k=e=>{let{t,loading:n}=(0,c.useSchedulerContext)(),{value:r,onChange:i,onWeeklyChange:a,disabled:o,setOccurs:s,scheduler:d}=e,f=(0,l.useRef)(d);(0,l.useEffect)(()=>{f.current=d},[d]);let p=r?.type||`DAY`,m=(e,n)=>{if(n!==null&&i){let e={...r,type:n,...n===`PERIOD`&&!r?.weekDay?{weekDay:`FIRST`}:{}};i(e);let a=f.current,o={...a,repeat:{...a.repeat,monthly:e}};n===`DAY`?(0,c.handleSelectWeeklyDay)(o.duration.period,o,s,t):(0,c.handleDurationValueChange)(o.duration,o,s,t)}},v=e=>{if(i){let n={...r,monthDay:e};i(n);let a=f.current;(0,c.handleSelectWeeklyDay)(e,{...a,repeat:{...a.repeat,monthly:n}},s,t)}},y=(e,n)=>{if(n!==null&&i){let e={...r,weekDay:n};i(e);let a=f.current,o={...a,repeat:{...a.repeat,monthly:e}};(0,c.handleDurationValueChange)(o.duration,o,s,t)}},b=[{value:`FIRST`,label:t(`scheduler.day.first`)},{value:`SECOND`,label:t(`scheduler.day.second`)},{value:`THIRD`,label:t(`scheduler.day.third`)},{value:`FOURTH`,label:t(`scheduler.day.fourth`)},{value:`LAST`,label:t(`scheduler.day.last`)}];return(0,h.jsxs)(u.Box,{sx:{display:`flex`,flexDirection:`column`,gap:2},children:[(0,h.jsxs)(u.ToggleButtonGroup,{value:p,exclusive:!0,onChange:m,disabled:o||n,size:`small`,children:[(0,h.jsxs)(u.ToggleButton,{value:`DAY`,"aria-label":`day`,children:[(0,h.jsx)(g.default,{fontSize:`small`,sx:{mr:1}}),t(`scheduler.day`)]}),(0,h.jsxs)(u.ToggleButton,{value:`PERIOD`,"aria-label":`period`,children:[(0,h.jsx)(_.default,{fontSize:`small`,sx:{mr:1}}),t(`scheduler.meta.period`)]})]}),p===`DAY`?(0,h.jsx)(u.TextField,{label:t(`scheduler.day`),type:`number`,size:`small`,value:r?.monthDay??``,disabled:o||n,slotProps:{htmlInput:{min:1,max:31}},onChange:e=>v(parseInt(e.target.value,10)),sx:{width:120}}):(0,h.jsxs)(u.Box,{sx:{display:`flex`,flexDirection:`column`,gap:2},children:[(0,h.jsx)(u.ToggleButtonGroup,{value:r?.weekDay||``,exclusive:!0,onChange:y,disabled:o||n,size:`small`,sx:{flexWrap:`wrap`},children:b.map(e=>(0,h.jsx)(u.ToggleButton,{value:e.value,children:e.label},e.value))}),(0,h.jsx)(O,{value:d.repeat?.weekly?.days,onChange:e=>{a?.(e)},disabled:o,setOccurs:s,scheduler:d})]})]})},A=e=>{let{t,loading:n}=(0,c.useSchedulerContext)(),{value:r,onChange:i,disabled:a,setOccurs:o,scheduler:s,repeatMonthly:d,onMonthlyChange:f,onWeeklyChange:p}=e,m=(0,l.useRef)(s);(0,l.useEffect)(()=>{m.current=s},[s]);let g=(0,l.useMemo)(()=>Object.keys(c.EMonths).map(e=>t(`scheduler.months.${c.EMonths[e].toLowerCase()}`)),[t]),_=(0,l.useMemo)(()=>Object.keys(c.EMonths).map(e=>t(`scheduler.months.short.${c.EMonths[e].toLowerCase()}`)),[t]),v=Object.keys(c.EMonths).map((e,t)=>({key:`${e}-${t}`,label:(0,h.jsx)(u.Tooltip,{title:g[t],children:(0,h.jsx)(`span`,{children:_[t]})}),value:e}));return(0,h.jsxs)(u.Box,{sx:{display:`flex`,flexDirection:`column`,gap:3},children:[(0,h.jsx)(D,{label:t(`scheduler.months`),options:v,value:r?.months||[],onChange:e=>{if(i){let n=e,a={...r,months:n};i(a);let s=m.current,l={...s,repeat:{...s.repeat,yearly:a}};(0,c.handleDurationValueChange)(l.duration,l,o,t)}},disabled:a,loading:n}),(0,h.jsx)(k,{value:d,onChange:f,onWeeklyChange:p,disabled:a,setOccurs:o,scheduler:s})]})},j=e=>{let{disabled:t,value:n,startedAt:r,onChange:i}=e,{t:a}=(0,c.useSchedulerContext)(),o=r?(0,m.default)(r).add(1,`day`):(0,m.default)();return(0,h.jsx)(d.DateTimePicker,{label:a(`scheduler.duration.endDate`),value:n??null,onChange:i,disabled:t||!r,minDateTime:o,slotProps:{textField:{size:`small`,fullWidth:!0}}})},M=e=>{let{t}=(0,c.useSchedulerContext)(),{min:n=1,value:r,onChange:i,disabled:a=!1}=e;return(0,h.jsx)(u.TextField,{fullWidth:!0,size:`small`,type:`number`,label:t(`scheduler.occurrences`),value:r??``,disabled:a,slotProps:{htmlInput:{min:n}},onChange:e=>i?.(parseInt(e.target.value,10))})},N=e=>{let{t,loading:n}=(0,c.useSchedulerContext)(),{value:r,onChange:i,disabled:a=!1,durationTypes:o=Object.keys(c.EDurationTypes),discountTypes:s=Object.keys(c.EDiscountType),schedulerType:g}=e,_=g===c.ESchedulerPrefix.SALE?c.DEFAULT_SALE_SCHEDULER:c.DEFAULT_DISCOUNT_SCHEDULER,[v,y]=(0,l.useState)(()=>_),b=r??v,[x,S]=(0,l.useState)(`0`),[C,w]=(0,l.useState)(null);(0,l.useEffect)(()=>{b.range?.startedAt&&(0,c.handleChangeStartDate)((0,m.default)(b.range.startedAt),w),b.duration&&(0,c.handleDurationValueChange)(b.duration,b,S,t)},[r,t]);let T=(e,t)=>{let n=e.split(`.`),r=(e,t,n)=>{if(t.length===1)return{...e,[t[0]]:n};let[i,...a]=t;return{...e,[i]:r(e[i]??{},a,n)}},a=r(b,n,t);y(a),i?.(a)};return(0,h.jsx)(f.LocalizationProvider,{dateAdapter:p.AdapterDayjs,children:(0,h.jsxs)(u.Box,{sx:{display:`flex`,flexDirection:`column`,gap:3,py:2},children:[[c.ESchedulerPrefix.DISCOUNT,c.ESchedulerPrefix.TRIAL_DISCOUNT].includes(g)&&(0,h.jsx)(u.Grid2,{container:!0,spacing:2,children:(0,h.jsx)(u.Grid2,{size:{xs:12,sm:6},children:(0,h.jsxs)(u.Box,{sx:{display:`flex`,gap:1},children:[(0,h.jsxs)(u.FormControl,{fullWidth:!0,size:`small`,children:[(0,h.jsx)(u.InputLabel,{children:t(`scheduler.meta.duration`)}),(0,h.jsx)(u.Select,{value:b.discount?.type||``,label:t(`scheduler.meta.duration`),disabled:a||n,onChange:e=>T(`discount.type`,e.target.value),children:s.map(e=>(0,h.jsx)(u.MenuItem,{value:e,children:c.EDiscountType[e]},String(e)))})]}),(0,h.jsx)(u.TextField,{fullWidth:!0,size:`small`,type:`number`,label:t(`scheduler.meta.duration`),value:b.discount?.value||``,disabled:a||n,onChange:e=>T(`discount.value`,parseInt(e.target.value,10))})]})})}),(0,h.jsxs)(u.Grid2,{container:!0,spacing:2,children:[(0,h.jsx)(u.Grid2,{size:{xs:12,sm:6},children:(0,h.jsx)(E,{label:t(`scheduler.duration`),disabled:a||n,typeValue:b.duration?.type,periodValue:b.duration?.period,durationTypes:o,required:!0,onTypeChange:e=>T(`duration.type`,e),onValueChange:e=>T(`duration.period`,e)})}),(0,h.jsx)(u.Grid2,{size:{xs:12,sm:6},children:(0,h.jsx)(d.DateTimePicker,{label:t(`scheduler.startedAt`),value:(0,m.default)(b.range?.startedAt),onChange:e=>T(`range.startedAt`,e),disabled:a||n,slotProps:{textField:{size:`small`,fullWidth:!0}}})})]}),b.duration?.type===`WEEK`&&(0,h.jsx)(O,{value:b.repeat?.weekly?.days,onChange:e=>T(`repeat.weekly.days`,e),disabled:a,setOccurs:S,scheduler:b}),b.duration?.type===`MONTH`&&(0,h.jsx)(k,{value:b.repeat?.monthly,onChange:e=>T(`repeat.monthly`,e),onWeeklyChange:e=>T(`repeat.weekly.days`,e),disabled:a,setOccurs:S,scheduler:b}),b.duration?.type===`YEAR`&&(0,h.jsx)(A,{value:b.repeat?.yearly,onChange:e=>T(`repeat.yearly`,e),disabled:a,setOccurs:S,scheduler:b,repeatMonthly:b.repeat?.monthly,onMonthlyChange:e=>T(`repeat.monthly`,e),onWeeklyChange:e=>T(`repeat.weekly.days`,e)}),(0,h.jsxs)(u.Grid2,{container:!0,spacing:2,children:[(0,h.jsx)(u.Grid2,{size:{xs:12,sm:6},children:(0,h.jsxs)(u.FormControl,{fullWidth:!0,size:`small`,children:[(0,h.jsx)(u.InputLabel,{children:t(`scheduler.duration.end`)}),(0,h.jsx)(u.Select,{value:b.range?.endReason?.type||``,label:t(`scheduler.duration.end`),disabled:a,onChange:e=>T(`range.endReason.type`,e.target.value),children:[{label:t(`scheduler.duration.end.day`),value:c.CEndReasonTypes[0]},{label:t(`scheduler.duration.end.after`),value:c.CEndReasonTypes[1]},{label:t(`scheduler.duration.end.no`),value:c.CEndReasonTypes[2]}].map(e=>(0,h.jsx)(u.MenuItem,{value:e.value,children:e.label},e.value))})]})}),(0,h.jsxs)(u.Grid2,{size:{xs:12,sm:6},children:[b.range?.endReason?.type===c.CEndReasonTypes[0]&&(0,h.jsx)(j,{value:(0,m.default)(b.range?.endReason?.expiredAt),startedAt:(0,m.default)(b.range?.startedAt),onChange:e=>T(`range.endReason.expiredAt`,e),disabled:a}),b.range?.endReason?.type===c.CEndReasonTypes[1]&&(0,h.jsx)(M,{value:b.range?.endReason?.occurrences,onChange:e=>T(`range.endReason.occurrences`,e),disabled:a})]})]}),(0,h.jsx)(u.Typography,{variant:`body2`,sx:{fontStyle:`italic`,color:`text.secondary`},dangerouslySetInnerHTML:{__html:t(`scheduler.result`,{occurs:x,startAt:C??``})}})]})})},P=e=>{let{t,permissions:n}=(0,c.useSchedulerContext)(),{loading:r,className:i,isEdit:a,disabled:o,size:s=`small`,color:l=`primary`,icon:d=(0,h.jsx)(x.default,{fontSize:`small`}),type:f=`button`,variant:p=`contained`,onClick:m}=e;if(!(a?n.canUpdate:n.canCreate))return null;let g=t(a?`actions.update`:`actions.save`);return(0,h.jsx)(u.Button,{type:f,size:s,variant:p,className:i,disabled:o||r,startIcon:r?(0,h.jsx)(u.CircularProgress,{size:16,color:`inherit`}):d,onClick:m,color:l,children:g})},F=({schedulerType:e,disabled:t,onSuccess:n,setDirty:r,dirty:i,isCreating:a,setIsCreating:o,buttonProps:s,open:d,onOpenChange:f,showButton:p=!0})=>{let{t:m,loading:g,permissions:_,onCreate:v}=(0,c.useSchedulerContext)(),[x,S]=(0,l.useState)(!1),C=d===void 0?x:d,w=e=>{f?f(e):S(e)},T=(0,l.useMemo)(()=>e===c.ESchedulerPrefix.SALE?c.DEFAULT_SALE_SCHEDULER:c.DEFAULT_DISCOUNT_SCHEDULER,[e]),[E,D]=(0,l.useState)(T);if((0,l.useEffect)(()=>{C&&D(T)},[C,T]),!_.canCreate)return null;let O=()=>{w(!0)},k=()=>{w(!1),r(!1)},A=async()=>{try{o(!0);let t={id:`new-${Date.now()}`,...E,type:e,[c.CNsDiscount]:e===c.ESchedulerPrefix.SALE?null:E?.[c.CNsDiscount]};v&&await v(e,t),n?.(t),w(!1),r(!1)}catch(e){console.error(`Failed to save scheduler:`,e)}finally{o(!1)}};return(0,h.jsxs)(h.Fragment,{children:[p&&(0,h.jsx)(u.Tooltip,{title:t?m(`scheduler.limited`,{limit:c.DEFAULT_SCHEDULERS_LIMIT}):``,children:(0,h.jsx)(`span`,{children:(0,h.jsx)(u.Button,{variant:`text`,size:`small`,...s,disabled:t||g,onClick:O,sx:{textTransform:`none`,p:0,minWidth:`auto`,...s?.sx},children:m(`scheduler`)})})}),(0,h.jsx)(u.Drawer,{anchor:`right`,open:C,onClose:k,slotProps:{paper:{sx:{width:{xs:`100%`,sm:600},p:0}}},children:(0,h.jsxs)(u.Box,{sx:{display:`flex`,flexDirection:`column`,height:`100%`},children:[(0,h.jsxs)(u.Box,{sx:{p:2,display:`flex`,alignItems:`center`,justifyContent:`space-between`},children:[(0,h.jsxs)(u.Box,{sx:{display:`flex`,alignItems:`center`,gap:1},children:[(0,h.jsx)(y.default,{color:`primary`}),(0,h.jsx)(u.Typography,{variant:`h6`,children:m(`scheduler`)})]}),(0,h.jsxs)(u.Box,{sx:{display:`flex`,alignItems:`center`,gap:1},children:[(0,h.jsx)(P,{loading:g||a,disabled:t||!i,onClick:A}),(0,h.jsx)(u.IconButton,{onClick:k,size:`small`,children:(0,h.jsx)(b.default,{})})]})]}),(0,h.jsx)(u.Divider,{}),(0,h.jsx)(u.Box,{sx:{p:3,flexGrow:1,overflowY:`auto`},children:(0,h.jsx)(N,{schedulerType:e,value:E,onChange:e=>{D(e),r(!0)},disabled:t})})]})})]})},I=e=>{let{t}=(0,c.useSchedulerContext)(),{selectedColumns:n=[],columnsList:r=[],onChange:i}=e;if(!r?.length)return(0,h.jsx)(h.Fragment,{});let a=t(`table.hideColumns`);return(0,h.jsxs)(u.FormControl,{sx:{m:1,minWidth:250},size:`small`,children:[(0,h.jsx)(u.InputLabel,{id:`hide-columns-label`,children:a}),(0,h.jsx)(u.Select,{labelId:`hide-columns-label`,id:`hide-columns-select`,multiple:!0,value:n,onChange:e=>{let t=e.target.value,n=typeof t==`string`?t.split(`,`):t;n.length<1||i?.(n)},input:(0,h.jsx)(u.OutlinedInput,{label:a}),renderValue:e=>e.map(e=>r.find(t=>t.value===e)?.label??e).join(`, `),sx:{maxHeight:40},children:r.map(e=>(0,h.jsxs)(u.MenuItem,{value:e.value,children:[(0,h.jsx)(u.Checkbox,{checked:n.indexOf(e.value)>-1,size:`small`}),(0,h.jsx)(u.ListItemText,{primary:e.label})]},e.value))})]})},L=e=>{let{loading:t,t:n}=(0,c.useSchedulerContext)(),{children:r,items:i=[],onRefresh:a}=e,[o,s]=(0,l.useState)(null),d=!!o,f=e=>{s(e.currentTarget)},p=()=>{s(null)};return(0,h.jsxs)(u.Box,{sx:{display:`flex`,alignItems:`center`,justifyContent:`flex-end`,gap:1,mb:1},children:[r,(0,h.jsx)(u.IconButton,{"aria-label":`more`,id:`toolbar-button`,"aria-controls":d?`toolbar-menu`:void 0,"aria-expanded":d?`true`:void 0,"aria-haspopup":`true`,onClick:f,size:`small`,children:t?(0,h.jsx)(u.CircularProgress,{size:20}):(0,h.jsx)(S.default,{})}),(0,h.jsxs)(u.Menu,{id:`toolbar-menu`,anchorEl:o,open:d,onClose:p,slotProps:{list:{"aria-labelledby":`toolbar-button`}},children:[i.map((e,t)=>(0,h.jsxs)(u.MenuItem,{onClick:()=>{e.onClick&&e.onClick(),p()},children:[e.icon&&(0,h.jsx)(u.ListItemIcon,{children:e.icon}),typeof e.label==`string`?(0,h.jsx)(u.ListItemText,{children:e.label}):(0,h.jsx)(u.Box,{sx:{flexGrow:1,display:`flex`},children:e.label})]},t)),i.length>0&&a&&(0,h.jsx)(u.Divider,{}),a&&(0,h.jsxs)(u.MenuItem,{onClick:()=>{a(),p()},children:[(0,h.jsx)(u.ListItemIcon,{children:(0,h.jsx)(C.default,{fontSize:`small`})}),(0,h.jsx)(u.ListItemText,{children:n(`toolbar.refresh`)})]})]})]})},R={ACTIVE:`success`,DEACTIVATED:`default`,DELETED:`error`,PROCESSING:`info`,PENDING:`warning`,APPROVED:`success`,PUBLISHED:`primary`},z=({status:e})=>(0,h.jsx)(u.Chip,{label:String(e),size:`small`,color:R[e]||`default`,variant:`outlined`}),B=e=>{let{t,permissions:n}=(0,c.useSchedulerContext)(),{entity:r,disabled:i,onDelete:a,showLabel:o=!1}=e,[s,d]=(0,l.useState)(!1);if(!r||!n.canDelete)return null;let f=e=>{e.stopPropagation(),d(!0)},p=e=>{e.stopPropagation(),d(!1)};return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(u.Tooltip,{title:t(`actions.delete`),children:(0,h.jsx)(`span`,{children:(0,h.jsxs)(u.IconButton,{color:`error`,size:`small`,onClick:f,disabled:i,children:[(0,h.jsx)(w.default,{fontSize:`small`}),o&&t(`actions.delete`)]})})}),(0,h.jsxs)(u.Dialog,{open:s,onClose:p,onClick:e=>e.stopPropagation(),children:[(0,h.jsx)(u.DialogTitle,{children:t(`actions.delete`)}),(0,h.jsx)(u.DialogContent,{children:(0,h.jsx)(u.DialogContentText,{children:t(`actions.confirm.delete`)})}),(0,h.jsxs)(u.DialogActions,{children:[(0,h.jsx)(u.Button,{onClick:p,size:`small`,children:t(`actions.cancel`)}),(0,h.jsx)(u.Button,{onClick:e=>{e.stopPropagation(),a?.(r),d(!1)},color:`error`,variant:`contained`,size:`small`,autoFocus:!0,children:t(`actions.delete`)})]})]})]})},V=e=>{let{t,permissions:n}=(0,c.useSchedulerContext)(),{entity:r,disabled:i,onEdit:a,showLabel:o=!1}=e;return!r||!n.canUpdate?null:(0,h.jsx)(u.Tooltip,{title:t(`actions.edit`),children:(0,h.jsx)(`span`,{children:(0,h.jsxs)(u.IconButton,{color:`primary`,size:`small`,onClick:e=>{e.stopPropagation(),a?.(r)},disabled:i,children:[(0,h.jsx)(T.default,{fontSize:`small`}),o&&t(`actions.edit`)]})})})},H=e=>(0,h.jsx)(u.Box,{sx:{display:`flex`,flexWrap:`wrap`,gap:.5},children:e?.days.map((e,t)=>(0,h.jsx)(u.Chip,{label:e,size:`small`,variant:`outlined`,color:`primary`},t))}),U=(e,t)=>e?.type===`PERIOD`?(0,h.jsx)(u.Box,{sx:{display:`flex`,flexWrap:`wrap`,gap:.5},children:t?.days.map((t,n)=>(0,h.jsx)(u.Chip,{label:`${e.weekDay} ${t}`,size:`small`,variant:`outlined`,color:`secondary`},n))}):(0,h.jsx)(u.Box,{sx:{display:`flex`,flexWrap:`wrap`,gap:.5},children:(0,h.jsx)(u.Chip,{label:e?.monthDay?.toString(),size:`small`,variant:`outlined`,color:`info`},`monthDay`)}),W=(e,t,n)=>(0,h.jsxs)(u.Box,{sx:{display:`flex`,flexDirection:`column`,gap:.5},children:[U(t,n),(0,h.jsx)(u.Box,{sx:{display:`flex`,flexWrap:`wrap`,gap:.5},children:e?.months?.map((e,t)=>(0,h.jsx)(u.Chip,{label:e,size:`small`,variant:`outlined`,color:`warning`},t))})]}),G=e=>{let{disabled:t,schedulerType:n,currency:r,t:i,onEdit:a,onDelete:o}=e;return[{id:`index`,key:`index`,label:`#`,minWidth:50},{id:`duration`,key:`duration`,label:i(`scheduler.meta.duration`),minWidth:120,format:e=>{let t=e;return`${t?.period} (${t?.type})`}},{id:`repeat`,key:`repeat`,label:i(`scheduler.duration`),minWidth:200,format:(e,t)=>{let{duration:n,repeat:r}=t,{weekly:i,monthly:a,yearly:o}=r;switch(n?.type){case`WEEK`:return H(i);case`MONTH`:return U(a,i);case`YEAR`:return W(o,a,i);default:return null}}},[c.ESchedulerPrefix.DISCOUNT,c.ESchedulerPrefix.TRIAL_DISCOUNT].includes(n)?{id:`discount`,key:`discount`,label:i(`scheduler.meta.duration`),minWidth:120,format:e=>{let t=e;return t?t.type===`PERCENT`?`${t.value}${c.CDiscountTypeValues[t.type]}`:(0,c.numberToCurrency)(t.value,r??`USD`):`—`}}:null,{id:`status`,key:`status`,label:i(`scheduler.status`),minWidth:120,align:`center`,concealable:!0,format:e=>(0,h.jsx)(z,{status:e})},{id:`updatedAt`,key:`updatedAt`,label:i(`scheduler.updatedAt`),minWidth:180,align:`center`,concealable:!0,format:e=>{let t=e;return(0,h.jsx)(`span`,{children:t?.updatedAt?(0,c.tsToLocaleDateTime)((0,m.default)(t.updatedAt).toDate()):`—`})}},a||o?{id:`actions`,key:`actions`,label:i(`table.actions`),minWidth:100,align:`center`,format:(e,n)=>(0,h.jsxs)(u.Box,{sx:{display:`flex`,justifyContent:`center`,gap:.5},children:[a&&(0,h.jsx)(V,{onEdit:a,disabled:t,entity:n}),o&&(0,h.jsx)(B,{onDelete:o,entity:n,disabled:t})]})}:null].filter(Boolean)},K=e=>e.map((e,t)=>({...e,key:e.id||t.toString(),index:t+1})),q=()=>({title:`#`,dataIndex:`index`,key:`index`,width:50}),J=e=>({title:e(`table.actions`),key:`actions`,width:100}),Y=e=>{let{type:t,title:n,disabled:r,readOnlyFields:i=[],currency:a,onRefresh:o}=e,{schedulers:s,loading:d,disabled:f,t:p,permissions:m,onUpdate:g,onDelete:_}=(0,c.useSchedulerContext)(),x=r??f,[S,C]=(0,l.useState)(new Set),[w,T]=(0,l.useState)(!1),[E,D]=(0,l.useState)(!1),[O,k]=(0,l.useState)(!1),[A,j]=(0,l.useState)(!1),[M,R]=(0,l.useState)(!1),[z,B]=(0,l.useState)(null),[V,H]=(0,l.useState)(0),[U,W]=(0,l.useState)(10),q=(0,l.useMemo)(()=>{let e=s[t]??[];return S.size>0&&(e=e.filter(e=>!e.id||!S.has(e.id))),K(e)},[s,t,S]),J=q.length>=c.DEFAULT_SCHEDULERS_LIMIT,Y=(0,l.useCallback)(e=>{B(JSON.parse(JSON.stringify(e))),R(!0),D(!1)},[]),X=async()=>{if(!(!z||!g))try{await g(t,z),R(!1),B(null),D(!1),o?.()}catch(e){console.error(`Failed to update scheduler:`,e)}},Z=(0,l.useCallback)(async e=>{if(e.id?.startsWith(`new-`)){C(t=>{let n=new Set(t);return e.id&&n.add(e.id),n});return}_&&e.id&&(await _(t,e.id),o?.())},[_,t,o]),{filteredColumns:Q,columnsList:ee,selectedColumns:te,setSelectedColumns:ne}=(0,c.useColumnsToggle)((0,l.useMemo)(()=>G({disabled:x,schedulerType:t,entities:q,currency:a,t:p,onEdit:m.canUpdate?Y:void 0,onDelete:m.canDelete?Z:void 0}),[x,t,q,a,p,m,Y,Z])),re=(e,t)=>{H(t)},ie=e=>{W(parseInt(e.target.value,10)),H(0)},$=q.slice(V*U,V*U+U);return(0,h.jsxs)(u.Paper,{sx:{width:`100%`,overflow:`hidden`,mb:2},children:[(0,h.jsx)(u.Box,{sx:{p:2,display:`flex`,alignItems:`center`,justifyContent:`flex-end`,gap:2},children:(0,h.jsx)(L,{onRefresh:o,items:m.canCreate&&!J?[{label:p(`scheduler`),icon:(0,h.jsx)(v.default,{}),onClick:()=>j(!0)}]:[],children:(0,h.jsx)(I,{columnsList:ee,selectedColumns:te,onChange:ne})})}),(0,h.jsx)(F,{open:A,onOpenChange:j,showButton:!1,schedulerType:t,setDirty:T,dirty:w,isCreating:O,setIsCreating:k,onSuccess:()=>o?.()}),(0,h.jsx)(u.TableContainer,{sx:{maxHeight:440},children:(0,h.jsxs)(u.Table,{stickyHeader:!0,"aria-label":`schedulers table`,size:`small`,children:[(0,h.jsx)(u.TableHead,{children:(0,h.jsx)(u.TableRow,{children:Q.filter(e=>!e.hidden).map(e=>(0,h.jsx)(u.TableCell,{align:e.align,style:{minWidth:e.minWidth},children:e.label},e.id))})}),(0,h.jsxs)(u.TableBody,{children:[$.map(e=>(0,h.jsx)(u.TableRow,{hover:!0,role:`checkbox`,tabIndex:-1,children:Q.filter(e=>!e.hidden).map(t=>{let n=t.id.includes(`.`)?t.id.split(`.`).reduce((e,t)=>e?.[t],e):e[t.id];return(0,h.jsx)(u.TableCell,{align:t.align,children:t.format?t.format(n,e):n},t.id)})},e.key)),$.length===0&&(0,h.jsx)(u.TableRow,{children:(0,h.jsx)(u.TableCell,{colSpan:Q.length,align:`center`,sx:{py:3},children:(0,h.jsx)(u.Typography,{variant:`body2`,color:`text.secondary`,children:`No items found`})})})]})]})}),(0,h.jsx)(u.TablePagination,{rowsPerPageOptions:[5,10,25,100],component:`div`,count:q.length,rowsPerPage:U,page:V,onPageChange:re,onRowsPerPageChange:ie}),(0,h.jsx)(u.Drawer,{anchor:`right`,open:M,onClose:()=>{R(!1),B(null)},slotProps:{paper:{sx:{width:{xs:`100%`,sm:600},p:0}}},children:(0,h.jsxs)(u.Box,{sx:{display:`flex`,flexDirection:`column`,height:`100%`},children:[(0,h.jsxs)(u.Box,{sx:{p:2,display:`flex`,alignItems:`center`,justifyContent:`space-between`},children:[(0,h.jsxs)(u.Box,{sx:{display:`flex`,alignItems:`center`,gap:1},children:[(0,h.jsx)(y.default,{color:`primary`}),(0,h.jsx)(u.Typography,{variant:`h6`,children:n??p(`scheduler`)})]}),(0,h.jsxs)(u.Box,{sx:{display:`flex`,alignItems:`center`,gap:1},children:[(0,h.jsx)(P,{isEdit:!0,loading:d,disabled:x||!E||O,onClick:X}),(0,h.jsx)(u.IconButton,{onClick:()=>R(!1),size:`small`,children:(0,h.jsx)(b.default,{})})]})]}),(0,h.jsx)(u.Divider,{}),(0,h.jsx)(u.Box,{sx:{p:3,flexGrow:1,overflowY:`auto`},children:M&&z&&(0,h.jsx)(N,{schedulerType:t,value:z,onChange:e=>{B(e),D(!0)},disabled:x,readOnlyFields:i})})]})})]})};exports.Scheduler=N,exports.SchedulerDrawerButton=F,exports.SchedulersList=Y,exports.actionField=J,exports.indexColumn=q,exports.indexable=K,Object.keys(c).forEach(function(e){e!==`default`&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return c[e]}})});
package/dist/index.es.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { CDiscountTypeValues as e, CEndReasonTypes as t, CFirstDayIdx as n, CNsDiscount as r, DEFAULT_DISCOUNT_SCHEDULER as i, DEFAULT_SALE_SCHEDULER as a, DEFAULT_SCHEDULERS_LIMIT as o, EDays as s, EDiscountType as c, EDurationTypes as l, EMonths as u, ESchedulerPrefix as d, getKeyFromEnum as f, handleChangeStartDate as p, handleDurationValueChange as m, handleSelectWeeklyDay as h, numberToCurrency as g, tsToLocaleDateTime as _, useColumnsToggle as v, useSchedulerContext as y } from "@teamco/ischeduler-core";
2
2
  import { useCallback as b, useEffect as x, useMemo as S, useRef as C, useState as w } from "react";
3
- import { Box as T, Button as E, Checkbox as D, Chip as O, CircularProgress as k, Dialog as A, DialogActions as j, DialogContent as M, DialogContentText as N, DialogTitle as P, Divider as F, Drawer as ee, FormControl as I, FormHelperText as L, Grid2 as R, IconButton as z, InputLabel as B, ListItemIcon as te, ListItemText as V, Menu as H, MenuItem as U, OutlinedInput as ne, Paper as re, Select as W, Table as ie, TableBody as ae, TableCell as oe, TableContainer as se, TableHead as ce, TablePagination as le, TableRow as G, TextField as K, ToggleButton as q, ToggleButtonGroup as J, Tooltip as Y, Typography as X } from "@mui/material";
3
+ import { Box as T, Button as E, Checkbox as D, Chip as O, CircularProgress as k, Dialog as A, DialogActions as j, DialogContent as M, DialogContentText as N, DialogTitle as P, Divider as F, Drawer as ee, FormControl as I, FormHelperText as L, Grid2 as R, IconButton as z, InputLabel as B, ListItemIcon as V, ListItemText as H, Menu as te, MenuItem as U, OutlinedInput as ne, Paper as re, Select as W, Table as ie, TableBody as ae, TableCell as oe, TableContainer as se, TableHead as ce, TablePagination as le, TableRow as G, TextField as K, ToggleButton as q, ToggleButtonGroup as J, Tooltip as Y, Typography as X } from "@mui/material";
4
4
  import { DateTimePicker as ue } from "@mui/x-date-pickers/DateTimePicker";
5
5
  import { LocalizationProvider as de } from "@mui/x-date-pickers/LocalizationProvider";
6
6
  import { AdapterDayjs as fe } from "@mui/x-date-pickers/AdapterDayjs";
@@ -565,56 +565,60 @@ var we = (e) => {
565
565
  color: c,
566
566
  children: p
567
567
  });
568
- }, Ne = ({ schedulerType: e, disabled: t, onSuccess: n, setDirty: s, dirty: c, isCreating: l, setIsCreating: u, buttonProps: f }) => {
569
- let { t: p, loading: m, permissions: h, onCreate: g } = y(), [_, v] = w(!1), b = S(() => e === d.SALE ? a : i, [e]), [x, C] = w(b);
570
- if (!h.canCreate) return null;
571
- let D = (e) => {
572
- e.preventDefault(), e.stopPropagation(), C(b), v(!0);
573
- }, O = () => {
574
- v(!1), s(!1);
575
- }, k = async () => {
568
+ }, Ne = ({ schedulerType: e, disabled: t, onSuccess: n, setDirty: s, dirty: c, isCreating: l, setIsCreating: u, buttonProps: f, open: p, onOpenChange: m, showButton: h = !0 }) => {
569
+ let { t: g, loading: _, permissions: v, onCreate: b } = y(), [C, D] = w(!1), O = p === void 0 ? C : p, k = (e) => {
570
+ m ? m(e) : D(e);
571
+ }, A = S(() => e === d.SALE ? a : i, [e]), [j, M] = w(A);
572
+ if (x(() => {
573
+ O && M(A);
574
+ }, [O, A]), !v.canCreate) return null;
575
+ let N = () => {
576
+ k(!0);
577
+ }, P = () => {
578
+ k(!1), s(!1);
579
+ }, I = async () => {
576
580
  try {
577
581
  u(!0);
578
582
  let t = {
579
583
  id: `new-${Date.now()}`,
580
- ...x,
584
+ ...j,
581
585
  type: e,
582
- [r]: e === d.SALE ? null : x?.[r]
586
+ [r]: e === d.SALE ? null : j?.[r]
583
587
  };
584
- g && await g(e, t), n?.(t), v(!1), s(!1);
588
+ b && await b(e, t), n?.(t), k(!1), s(!1);
585
589
  } catch (e) {
586
590
  console.error("Failed to save scheduler:", e);
587
591
  } finally {
588
592
  u(!1);
589
593
  }
590
594
  };
591
- return /* @__PURE__ */ $(pe, { children: [/* @__PURE__ */ Q(Y, {
592
- title: t ? p("scheduler.limited", { limit: o }) : "",
595
+ return /* @__PURE__ */ $(pe, { children: [h && /* @__PURE__ */ Q(Y, {
596
+ title: t ? g("scheduler.limited", { limit: o }) : "",
593
597
  children: /* @__PURE__ */ Q("span", { children: /* @__PURE__ */ Q(E, {
594
598
  variant: "text",
595
599
  size: "small",
596
600
  ...f,
597
- disabled: t || m,
598
- onClick: D,
601
+ disabled: t || _,
602
+ onClick: N,
599
603
  sx: {
600
604
  textTransform: "none",
601
605
  p: 0,
602
606
  minWidth: "auto",
603
607
  ...f?.sx
604
608
  },
605
- children: p("scheduler")
609
+ children: g("scheduler")
606
610
  }) })
607
611
  }), /* @__PURE__ */ Q(ee, {
608
612
  anchor: "right",
609
- open: _,
610
- onClose: O,
611
- PaperProps: { sx: {
613
+ open: O,
614
+ onClose: P,
615
+ slotProps: { paper: { sx: {
612
616
  width: {
613
617
  xs: "100%",
614
618
  sm: 600
615
619
  },
616
620
  p: 0
617
- } },
621
+ } } },
618
622
  children: /* @__PURE__ */ $(T, {
619
623
  sx: {
620
624
  display: "flex",
@@ -637,7 +641,7 @@ var we = (e) => {
637
641
  },
638
642
  children: [/* @__PURE__ */ Q(_e, { color: "primary" }), /* @__PURE__ */ Q(X, {
639
643
  variant: "h6",
640
- children: p("scheduler")
644
+ children: g("scheduler")
641
645
  })]
642
646
  }), /* @__PURE__ */ $(T, {
643
647
  sx: {
@@ -646,11 +650,11 @@ var we = (e) => {
646
650
  gap: 1
647
651
  },
648
652
  children: [/* @__PURE__ */ Q(Me, {
649
- loading: m || l,
653
+ loading: _ || l,
650
654
  disabled: t || !c,
651
- onClick: k
655
+ onClick: I
652
656
  }), /* @__PURE__ */ Q(z, {
653
- onClick: O,
657
+ onClick: P,
654
658
  size: "small",
655
659
  children: /* @__PURE__ */ Q(ve, {})
656
660
  })]
@@ -665,9 +669,9 @@ var we = (e) => {
665
669
  },
666
670
  children: /* @__PURE__ */ Q(je, {
667
671
  schedulerType: e,
668
- value: x,
672
+ value: j,
669
673
  onChange: (e) => {
670
- C(e), s(!0);
674
+ M(e), s(!0);
671
675
  },
672
676
  disabled: t
673
677
  })
@@ -705,7 +709,7 @@ var we = (e) => {
705
709
  children: [/* @__PURE__ */ Q(D, {
706
710
  checked: n.indexOf(e.value) > -1,
707
711
  size: "small"
708
- }), /* @__PURE__ */ Q(V, { primary: e.label })]
712
+ }), /* @__PURE__ */ Q(H, { primary: e.label })]
709
713
  }, e.value))
710
714
  })]
711
715
  });
@@ -735,25 +739,31 @@ var we = (e) => {
735
739
  size: "small",
736
740
  children: t ? /* @__PURE__ */ Q(k, { size: 20 }) : /* @__PURE__ */ Q(be, {})
737
741
  }),
738
- /* @__PURE__ */ $(H, {
742
+ /* @__PURE__ */ $(te, {
739
743
  id: "toolbar-menu",
740
744
  anchorEl: o,
741
745
  open: c,
742
746
  onClose: u,
743
- MenuListProps: { "aria-labelledby": "toolbar-button" },
747
+ slotProps: { list: { "aria-labelledby": "toolbar-button" } },
744
748
  children: [
745
749
  i.map((e, t) => /* @__PURE__ */ $(U, {
746
750
  onClick: () => {
747
- e.onClick?.(), u();
751
+ e.onClick && e.onClick(), u();
748
752
  },
749
- children: [e.icon && /* @__PURE__ */ Q(te, { children: e.icon }), /* @__PURE__ */ Q(V, { children: e.label })]
753
+ children: [e.icon && /* @__PURE__ */ Q(V, { children: e.icon }), typeof e.label == "string" ? /* @__PURE__ */ Q(H, { children: e.label }) : /* @__PURE__ */ Q(T, {
754
+ sx: {
755
+ flexGrow: 1,
756
+ display: "flex"
757
+ },
758
+ children: e.label
759
+ })]
750
760
  }, t)),
751
761
  i.length > 0 && a && /* @__PURE__ */ Q(F, {}),
752
762
  a && /* @__PURE__ */ $(U, {
753
763
  onClick: () => {
754
764
  a(), u();
755
765
  },
756
- children: [/* @__PURE__ */ Q(te, { children: /* @__PURE__ */ Q(xe, { fontSize: "small" }) }), /* @__PURE__ */ Q(V, { children: n("toolbar.refresh") })]
766
+ children: [/* @__PURE__ */ Q(V, { children: /* @__PURE__ */ Q(xe, { fontSize: "small" }) }), /* @__PURE__ */ Q(H, { children: n("toolbar.refresh") })]
757
767
  })
758
768
  ]
759
769
  })
@@ -984,22 +994,22 @@ var we = (e) => {
984
994
  key: "actions",
985
995
  width: 100
986
996
  }), qe = (e) => {
987
- let { type: t, title: n, disabled: r, readOnlyFields: i = [], currency: a, onRefresh: s } = e, { schedulers: c, loading: l, disabled: u, t: d, permissions: f, onUpdate: p, onDelete: m } = y(), h = r ?? u, [g, _] = w(/* @__PURE__ */ new Set()), [x, C] = w(!1), [E, D] = w(!1), [O, k] = w(!1), [A, j] = w(null), [M, N] = w(0), [P, I] = w(10), L = S(() => {
997
+ let { type: t, title: n, disabled: r, readOnlyFields: i = [], currency: a, onRefresh: s } = e, { schedulers: c, loading: l, disabled: u, t: d, permissions: f, onUpdate: p, onDelete: m } = y(), h = r ?? u, [g, _] = w(/* @__PURE__ */ new Set()), [x, C] = w(!1), [E, D] = w(!1), [O, k] = w(!1), [A, j] = w(!1), [M, N] = w(!1), [P, I] = w(null), [L, R] = w(0), [B, V] = w(10), H = S(() => {
988
998
  let e = c[t] ?? [];
989
999
  return g.size > 0 && (e = e.filter((e) => !e.id || !g.has(e.id))), We(e);
990
1000
  }, [
991
1001
  c,
992
1002
  t,
993
1003
  g
994
- ]), R = L.length >= o, B = b((e) => {
995
- j(JSON.parse(JSON.stringify(e))), k(!0), C(!1);
996
- }, []), te = async () => {
997
- if (!(!A || !p)) try {
998
- await p(t, A), k(!1), j(null), C(!1), s?.();
1004
+ ]), te = H.length >= o, U = b((e) => {
1005
+ I(JSON.parse(JSON.stringify(e))), N(!0), D(!1);
1006
+ }, []), ne = async () => {
1007
+ if (!(!P || !p)) try {
1008
+ await p(t, P), N(!1), I(null), D(!1), s?.();
999
1009
  } catch (e) {
1000
1010
  console.error("Failed to update scheduler:", e);
1001
1011
  }
1002
- }, V = b(async (e) => {
1012
+ }, W = b(async (e) => {
1003
1013
  if (e.id?.startsWith("new-")) {
1004
1014
  _((t) => {
1005
1015
  let n = new Set(t);
@@ -1012,28 +1022,28 @@ var we = (e) => {
1012
1022
  m,
1013
1023
  t,
1014
1024
  s
1015
- ]), { filteredColumns: H, columnsList: U, selectedColumns: ne, setSelectedColumns: W } = v(S(() => Ue({
1025
+ ]), { filteredColumns: K, columnsList: q, selectedColumns: J, setSelectedColumns: Y } = v(S(() => Ue({
1016
1026
  disabled: h,
1017
1027
  schedulerType: t,
1018
- entities: L,
1028
+ entities: H,
1019
1029
  currency: a,
1020
1030
  t: d,
1021
- onEdit: f.canUpdate ? B : void 0,
1022
- onDelete: f.canDelete ? V : void 0
1031
+ onEdit: f.canUpdate ? U : void 0,
1032
+ onDelete: f.canDelete ? W : void 0
1023
1033
  }), [
1024
1034
  h,
1025
1035
  t,
1026
- L,
1036
+ H,
1027
1037
  a,
1028
1038
  d,
1029
1039
  f,
1030
- B,
1031
- V
1032
- ])), K = (e, t) => {
1033
- N(t);
1034
- }, q = (e) => {
1035
- I(parseInt(e.target.value, 10)), N(0);
1036
- }, J = L.slice(M * P, M * P + P);
1040
+ U,
1041
+ W
1042
+ ])), ue = (e, t) => {
1043
+ R(t);
1044
+ }, de = (e) => {
1045
+ V(parseInt(e.target.value, 10)), R(0);
1046
+ }, fe = H.slice(L * B, L * B + B);
1037
1047
  return /* @__PURE__ */ $(re, {
1038
1048
  sx: {
1039
1049
  width: "100%",
@@ -1051,49 +1061,52 @@ var we = (e) => {
1051
1061
  },
1052
1062
  children: /* @__PURE__ */ Q(Fe, {
1053
1063
  onRefresh: s,
1054
- items: f.canCreate && !R ? [{
1055
- label: /* @__PURE__ */ Q(Ne, {
1056
- setDirty: C,
1057
- dirty: x,
1058
- isCreating: E,
1059
- setIsCreating: D,
1060
- schedulerType: t,
1061
- disabled: h || l || R || E,
1062
- onSuccess: () => s?.(),
1063
- buttonProps: { startIcon: /* @__PURE__ */ Q(ge, {}) }
1064
- }),
1065
- onClick: () => {}
1064
+ items: f.canCreate && !te ? [{
1065
+ label: d("scheduler"),
1066
+ icon: /* @__PURE__ */ Q(ge, {}),
1067
+ onClick: () => j(!0)
1066
1068
  }] : [],
1067
1069
  children: /* @__PURE__ */ Q(Pe, {
1068
- columnsList: U,
1069
- selectedColumns: ne,
1070
- onChange: W
1070
+ columnsList: q,
1071
+ selectedColumns: J,
1072
+ onChange: Y
1071
1073
  })
1072
1074
  })
1073
1075
  }),
1076
+ /* @__PURE__ */ Q(Ne, {
1077
+ open: A,
1078
+ onOpenChange: j,
1079
+ showButton: !1,
1080
+ schedulerType: t,
1081
+ setDirty: C,
1082
+ dirty: x,
1083
+ isCreating: O,
1084
+ setIsCreating: k,
1085
+ onSuccess: () => s?.()
1086
+ }),
1074
1087
  /* @__PURE__ */ Q(se, {
1075
1088
  sx: { maxHeight: 440 },
1076
1089
  children: /* @__PURE__ */ $(ie, {
1077
1090
  stickyHeader: !0,
1078
1091
  "aria-label": "schedulers table",
1079
1092
  size: "small",
1080
- children: [/* @__PURE__ */ Q(ce, { children: /* @__PURE__ */ Q(G, { children: H.filter((e) => !e.hidden).map((e) => /* @__PURE__ */ Q(oe, {
1093
+ children: [/* @__PURE__ */ Q(ce, { children: /* @__PURE__ */ Q(G, { children: K.filter((e) => !e.hidden).map((e) => /* @__PURE__ */ Q(oe, {
1081
1094
  align: e.align,
1082
1095
  style: { minWidth: e.minWidth },
1083
1096
  children: e.label
1084
- }, e.id)) }) }), /* @__PURE__ */ $(ae, { children: [J.map((e) => /* @__PURE__ */ Q(G, {
1097
+ }, e.id)) }) }), /* @__PURE__ */ $(ae, { children: [fe.map((e) => /* @__PURE__ */ Q(G, {
1085
1098
  hover: !0,
1086
1099
  role: "checkbox",
1087
1100
  tabIndex: -1,
1088
- children: H.filter((e) => !e.hidden).map((t) => {
1101
+ children: K.filter((e) => !e.hidden).map((t) => {
1089
1102
  let n = t.id.includes(".") ? t.id.split(".").reduce((e, t) => e?.[t], e) : e[t.id];
1090
1103
  return /* @__PURE__ */ Q(oe, {
1091
1104
  align: t.align,
1092
1105
  children: t.format ? t.format(n, e) : n
1093
1106
  }, t.id);
1094
1107
  })
1095
- }, e.key)), J.length === 0 && /* @__PURE__ */ Q(G, { children: /* @__PURE__ */ Q(oe, {
1096
- colSpan: H.length,
1108
+ }, e.key)), fe.length === 0 && /* @__PURE__ */ Q(G, { children: /* @__PURE__ */ Q(oe, {
1109
+ colSpan: K.length,
1097
1110
  align: "center",
1098
1111
  sx: { py: 3 },
1099
1112
  children: /* @__PURE__ */ Q(X, {
@@ -1112,25 +1125,25 @@ var we = (e) => {
1112
1125
  100
1113
1126
  ],
1114
1127
  component: "div",
1115
- count: L.length,
1116
- rowsPerPage: P,
1117
- page: M,
1118
- onPageChange: K,
1119
- onRowsPerPageChange: q
1128
+ count: H.length,
1129
+ rowsPerPage: B,
1130
+ page: L,
1131
+ onPageChange: ue,
1132
+ onRowsPerPageChange: de
1120
1133
  }),
1121
1134
  /* @__PURE__ */ Q(ee, {
1122
1135
  anchor: "right",
1123
- open: O,
1136
+ open: M,
1124
1137
  onClose: () => {
1125
- k(!1), j(null);
1138
+ N(!1), I(null);
1126
1139
  },
1127
- PaperProps: { sx: {
1140
+ slotProps: { paper: { sx: {
1128
1141
  width: {
1129
1142
  xs: "100%",
1130
1143
  sm: 600
1131
1144
  },
1132
1145
  p: 0
1133
- } },
1146
+ } } },
1134
1147
  children: /* @__PURE__ */ $(T, {
1135
1148
  sx: {
1136
1149
  display: "flex",
@@ -1164,10 +1177,10 @@ var we = (e) => {
1164
1177
  children: [/* @__PURE__ */ Q(Me, {
1165
1178
  isEdit: !0,
1166
1179
  loading: l,
1167
- disabled: h || !x || E,
1168
- onClick: te
1180
+ disabled: h || !E || O,
1181
+ onClick: ne
1169
1182
  }), /* @__PURE__ */ Q(z, {
1170
- onClick: () => k(!1),
1183
+ onClick: () => N(!1),
1171
1184
  size: "small",
1172
1185
  children: /* @__PURE__ */ Q(ve, {})
1173
1186
  })]
@@ -1180,11 +1193,11 @@ var we = (e) => {
1180
1193
  flexGrow: 1,
1181
1194
  overflowY: "auto"
1182
1195
  },
1183
- children: O && A && /* @__PURE__ */ Q(je, {
1196
+ children: M && P && /* @__PURE__ */ Q(je, {
1184
1197
  schedulerType: t,
1185
- value: A,
1198
+ value: P,
1186
1199
  onChange: (e) => {
1187
- j(e), C(!0);
1200
+ I(e), D(!0);
1188
1201
  },
1189
1202
  disabled: h,
1190
1203
  readOnlyFields: i
@@ -10,6 +10,9 @@ export declare type SchedulerDrawerButtonProps = {
10
10
  isCreating: boolean;
11
11
  setIsCreating: (isCreating: boolean) => void;
12
12
  buttonProps?: Partial<ButtonProps>;
13
+ open?: boolean;
14
+ onOpenChange?: (open: boolean) => void;
15
+ showButton?: boolean;
13
16
  };
14
17
  export declare const SchedulerDrawerButton: React.FC<SchedulerDrawerButtonProps>;
15
18
  //# sourceMappingURL=SchedulerDrawerButton.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SchedulerDrawerButton.d.ts","sourceRoot":"","sources":["SchedulerDrawerButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4B,MAAM,OAAO,CAAC;AACjD,OAAO,EAQL,WAAW,EACZ,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,gBAAgB,EAChB,UAAU,EAKX,MAAM,yBAAyB,CAAC;AAKjC,oBAAY,0BAA0B,GAAG;IACvC,aAAa,EAAE,gBAAgB,CAAC;IAChC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,CAAC,SAAS,EAAE,UAAU,KAAK,IAAI,CAAC;IAC5C,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACnC,KAAK,EAAE,OAAO,CAAC;IACf,UAAU,EAAE,OAAO,CAAC;IACpB,aAAa,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,IAAI,CAAC;IAC7C,WAAW,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;CACpC,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAAC,0BAA0B,CAwHtE,CAAC"}
1
+ {"version":3,"file":"SchedulerDrawerButton.d.ts","sourceRoot":"","sources":["SchedulerDrawerButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAC5D,OAAO,EAQL,WAAW,EACZ,MAAM,eAAe,CAAC;AAGvB,OAAO,EAEL,gBAAgB,EAChB,UAAU,EAKX,MAAM,yBAAyB,CAAC;AAKjC,oBAAY,0BAA0B,GAAG;IACvC,aAAa,EAAE,gBAAgB,CAAC;IAChC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,CAAC,SAAS,EAAE,UAAU,KAAK,IAAI,CAAC;IAC5C,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACnC,KAAK,EAAE,OAAO,CAAC;IACf,UAAU,EAAE,OAAO,CAAC;IACpB,aAAa,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,IAAI,CAAC;IAC7C,WAAW,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IAEnC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACvC,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAAC,0BAA0B,CA8ItE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"SchedulersList.d.ts","sourceRoot":"","sources":["SchedulersList.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAyC,MAAM,OAAO,CAAC;AA2B9D,OAAO,EAGL,gBAAgB,EAChB,SAAS,EAGV,MAAM,yBAAyB,CAAC;AAEjC,oBAAY,mBAAmB,GAAG;IAChC,IAAI,EAAE,gBAAgB,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,OAAO,SAAS,CAAC;IAClC,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAuOxD,CAAC"}
1
+ {"version":3,"file":"SchedulersList.d.ts","sourceRoot":"","sources":["SchedulersList.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAyC,MAAM,OAAO,CAAC;AA2B9D,OAAO,EAGL,gBAAgB,EAChB,SAAS,EAGV,MAAM,yBAAyB,CAAC;AAEjC,oBAAY,mBAAmB,GAAG;IAChC,IAAI,EAAE,gBAAgB,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,OAAO,SAAS,CAAC;IAClC,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAwRxD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"Toolbar.d.ts","sourceRoot":"","sources":["Toolbar.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAMxC,aAAK,YAAY,GAAG;IAClB,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AAEF,aAAK,aAAa,GAAG;IACnB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,KAAK,CAAC,EAAE,YAAY,EAAE,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CA4D3C,CAAC"}
1
+ {"version":3,"file":"Toolbar.d.ts","sourceRoot":"","sources":["Toolbar.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAexC,aAAK,YAAY,GAAG;IAClB,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AAEF,aAAK,aAAa,GAAG;IACnB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,KAAK,CAAC,EAAE,YAAY,EAAE,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CAiF3C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamco/ischeduler-mui",
3
- "version": "2.0.9",
3
+ "version": "2.0.11",
4
4
  "description": "iScheduler UI components for React + MUI (Material UI)",
5
5
  "license": "MIT",
6
6
  "repository": {