@edusight/notification-widget 1.0.28 → 1.0.29
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/components-B9Z6HsnI.cjs +70 -0
- package/dist/{components-ytSNU0U3.cjs.map → components-B9Z6HsnI.cjs.map} +1 -1
- package/dist/{components-BJ465mfK.js → components-DgV3nlCC.js} +214 -199
- package/dist/{components-BJ465mfK.js.map → components-DgV3nlCC.js.map} +1 -1
- package/dist/hooks-CggRWw6Q.cjs +2 -0
- package/dist/hooks-CggRWw6Q.cjs.map +1 -0
- package/dist/hooks-Cv5k48VE.js +159 -0
- package/dist/hooks-Cv5k48VE.js.map +1 -0
- package/dist/index.cjs.js +2 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +241 -177
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/dist/components-ytSNU0U3.cjs +0 -72
- package/dist/hooks-CACL0Qzv.cjs +0 -2
- package/dist/hooks-CACL0Qzv.cjs.map +0 -1
- package/dist/hooks-DQflK_dw.js +0 -160
- package/dist/hooks-DQflK_dw.js.map +0 -1
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";const u=require("react"),e=require("react/jsx-runtime");var q={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},D=u.createContext&&u.createContext(q),se=["attr","size","title"];function ne(t,r){if(t==null)return{};var a=ie(t,r),s,n;if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(t);for(n=0;n<l.length;n++)s=l[n],!(r.indexOf(s)>=0)&&Object.prototype.propertyIsEnumerable.call(t,s)&&(a[s]=t[s])}return a}function ie(t,r){if(t==null)return{};var a={};for(var s in t)if(Object.prototype.hasOwnProperty.call(t,s)){if(r.indexOf(s)>=0)continue;a[s]=t[s]}return a}function M(){return M=Object.assign?Object.assign.bind():function(t){for(var r=1;r<arguments.length;r++){var a=arguments[r];for(var s in a)Object.prototype.hasOwnProperty.call(a,s)&&(t[s]=a[s])}return t},M.apply(this,arguments)}function V(t,r){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);r&&(s=s.filter(function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable})),a.push.apply(a,s)}return a}function z(t){for(var r=1;r<arguments.length;r++){var a=arguments[r]!=null?arguments[r]:{};r%2?V(Object(a),!0).forEach(function(s){le(t,s,a[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):V(Object(a)).forEach(function(s){Object.defineProperty(t,s,Object.getOwnPropertyDescriptor(a,s))})}return t}function le(t,r,a){return r=oe(r),r in t?Object.defineProperty(t,r,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[r]=a,t}function oe(t){var r=de(t,"string");return typeof r=="symbol"?r:r+""}function de(t,r){if(typeof t!="object"||!t)return t;var a=t[Symbol.toPrimitive];if(a!==void 0){var s=a.call(t,r);if(typeof s!="object")return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(t)}function G(t){return t&&t.map((r,a)=>u.createElement(r.tag,z({key:a},r.attr),G(r.child)))}function w(t){return r=>u.createElement(ce,M({attr:z({},t.attr)},r),G(t.child))}function ce(t){var r=a=>{var{attr:s,size:n,title:l}=t,h=ne(t,se),f=n||a.size||"1em",m;return a.className&&(m=a.className),t.className&&(m=(m?m+" ":"")+t.className),u.createElement("svg",M({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},a.attr,s,h,{className:m,style:z(z({color:t.color||a.color},a.style),t.style),height:f,width:f,xmlns:"http://www.w3.org/2000/svg"}),l&&u.createElement("title",null,l),t.children)};return D!==void 0?u.createElement(D.Consumer,null,a=>r(a)):r(q)}function ue(t){return w({attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M257 120.471c7.083 0 23.911 4.479 23.911 4.479 45.589 10.447 77.678 52.439 77.678 99.85V352.412l9.321 9.364 7.788 7.823H136.302l7.788-7.823 9.321-9.364V224.8c0-47.41 32.089-89.403 77.678-99.85 0 0 18.043-4.479 23.911-4.479M256 48c-17.602 0-31.059 13.518-31.059 31.2v14.559c-59.015 13.523-103.53 67.601-103.53 131.041v114.4L80 380.8v20.8h352v-20.8l-41.411-41.6V224.8c0-63.44-44.516-117.518-103.53-131.041V79.2c0-17.682-13.457-31.2-31.059-31.2zm41.411 374.4h-82.823c0 22.881 18.633 41.6 41.412 41.6s41.411-18.719 41.411-41.6z"},child:[]}]})(t)}const he=({unreadCount:t,onClick:r,size:a,className:s="",disabled:n=!1})=>{const l=o=>o===0?"":o>99?"99+":o.toString(),h=o=>{n||(o.key==="Enter"||o.key===" ")&&(o.preventDefault(),r())},f=l(t),m=t>0;return e.jsxs("button",{type:"button",className:`
|
|
2
|
+
relative inline-flex items-center justify-center
|
|
3
|
+
rounded-full
|
|
4
|
+
text-[var(--widget-text-secondary)] hover:text-[var(--widget-text)]
|
|
5
|
+
bg-transparent hover:bg-[var(--widget-bg-hover)]
|
|
6
|
+
border-0 cursor-pointer
|
|
7
|
+
transition-colors duration-300
|
|
8
|
+
focus:outline-none focus:ring-1 focus:ring-[var(--widget-primary)] focus:ring-offset-1
|
|
9
|
+
disabled:opacity-70 disabled:cursor-not-allowed
|
|
10
|
+
w-10 h-10
|
|
11
|
+
${s}
|
|
12
|
+
`,onClick:r,onKeyDown:h,disabled:n,"aria-label":m?`Notifications (${t} unread)`:"Notifications","aria-expanded":!1,"aria-haspopup":"dialog","data-testid":"bell-component",children:[e.jsxs("div",{className:"relative inline-flex items-center justify-center",children:[e.jsx(ue,{className:"w-6 h-6"}),m&&e.jsx("span",{className:`\r
|
|
13
|
+
absolute\r
|
|
14
|
+
flex items-center justify-center\r
|
|
15
|
+
w-[16px] h-[16px]\r
|
|
16
|
+
text-[10px] font-bold leading-none\r
|
|
17
|
+
text-white bg-red-500\r
|
|
18
|
+
rounded-full\r
|
|
19
|
+
border border-white dark:border-gray-900\r
|
|
20
|
+
shadow-sm\r
|
|
21
|
+
pointer-events-none\r
|
|
22
|
+
`,"aria-hidden":"true","data-testid":"unread-badge",style:{marginTop:"-25px",marginRight:"-25px"},children:f})]}),e.jsx("span",{className:"sr-only",children:m?`${t} unread notifications`:"No unread notifications"})]})};function L(t){return w({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"},child:[]}]})(t)}function me(t){return w({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"},child:[]}]})(t)}function xe(t){return w({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z"},child:[]},{tag:"path",attr:{d:"M12.5 7H11v6l5.25 3.15.75-1.23-4.5-2.67z"},child:[]}]})(t)}function fe(t){return w({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M15.5 14h-.79l-.28-.27A6.471 6.471 0 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"},child:[]}]})(t)}function Y(t){return w({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0V0z"},child:[]},{tag:"path",attr:{d:"M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58a.49.49 0 0 0 .12-.61l-1.92-3.32a.488.488 0 0 0-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54a.484.484 0 0 0-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.09.63-.09.94s.02.64.07.94l-2.03 1.58a.49.49 0 0 0-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6z"},child:[]}]})(t)}function ge(t){return w({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"},child:[]}]})(t)}function pe(t){return w({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z"},child:[]}]})(t)}function ve(t){return w({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 4-8 5-8-5V6l8 5 8-5v2z"},child:[]}]})(t)}function J(t){return w({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"m20.54 5.23-1.39-1.68C18.88 3.21 18.47 3 18 3H6c-.47 0-.88.21-1.16.55L3.46 5.23C3.17 5.57 3 6.02 3 6.5V19c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V6.5c0-.48-.17-.93-.46-1.27zM12 17.5 6.5 12H10v-2h4v2h3.5L12 17.5zM5.12 5l.81-1h12l.94 1H5.12z"},child:[]}]})(t)}function be(t){return w({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z"},child:[]},{tag:"path",attr:{d:"M12.5 7H11v6l5.25 3.15.75-1.23-4.5-2.67z"},child:[]}]})(t)}function we(t){return w({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M17 1.01 7 1c-1.1 0-2 .9-2 2v18c0 1.1.9 2 2 2h10c1.1 0 2-.9 2-2V3c0-1.1-.9-1.99-2-1.99zM17 19H7V5h10v14z"},child:[]}]})(t)}function ye(t){return w({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"m21.41 11.58-9-9C12.05 2.22 11.55 2 11 2H4c-1.1 0-2 .9-2 2v7c0 .55.22 1.05.59 1.42l9 9c.36.36.86.58 1.41.58.55 0 1.05-.22 1.41-.59l7-7c.37-.36.59-.86.59-1.41 0-.55-.23-1.06-.59-1.42zM5.5 7C4.67 7 4 6.33 4 5.5S4.67 4 5.5 4 7 4.67 7 5.5 6.33 7 5.5 7z"},child:[]}]})(t)}function je(t){return w({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z"},child:[]}]})(t)}function Q(t){return w({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"},child:[]}]})(t)}function _(t){return w({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"m12 8-6 6 1.41 1.41L12 10.83l4.59 4.58L18 14z"},child:[]}]})(t)}function I(t){return w({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M16.59 8.59 12 13.17 7.41 8.59 6 10l6 6 6-6z"},child:[]}]})(t)}function Ne(t){return w({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M17.65 6.35A7.958 7.958 0 0 0 12 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08A5.99 5.99 0 0 1 12 18c-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z"},child:[]}]})(t)}function ke(t){return w({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M20 2H4c-1.1 0-1.99.9-1.99 2L2 22l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zM9 11H7V9h2v2zm4 0h-2V9h2v2zm4 0h-2V9h2v2z"},child:[]}]})(t)}function F(t){return w({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{d:"M12 22c1.1 0 2-.9 2-2h-4a2 2 0 0 0 2 2zm6-6v-5c0-3.07-1.64-5.64-4.5-6.32V4c0-.83-.67-1.5-1.5-1.5s-1.5.67-1.5 1.5v.68C7.63 5.36 6 7.92 6 11v5l-2 2v1h16v-1l-2-2z"},child:[]}]})(t)}function Ce(t){return w({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M19 5v14H5V5h14m0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z"},child:[]},{tag:"path",attr:{d:"M14 17H7v-2h7v2zm3-4H7v-2h10v2zm0-4H7V7h10v2z"},child:[]}]})(t)}function X(t){return w({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0V0z"},child:[]},{tag:"path",attr:{d:"M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 14H4V8l8 5 8-5v10zm-8-7L4 6h16l-8 5z"},child:[]}]})(t)}const A=({content:t,children:r,position:a="top",delay:s=200})=>{const[n,l]=u.useState(!1),[h,f]=u.useState({x:0,y:0}),m=u.useRef(null),o=u.useRef(null),y=()=>{m.current&&clearTimeout(m.current),m.current=setTimeout(()=>{if(o.current){const p=o.current.getBoundingClientRect();let i=0,c=0;switch(a){case"top":i=p.left+p.width/2,c=p.top-8;break;case"bottom":i=p.left+p.width/2,c=p.bottom+8;break;case"left":i=p.left-8,c=p.top+p.height/2;break;case"right":i=p.right+8,c=p.top+p.height/2;break}f({x:i,y:c}),l(!0)}},s)},d=()=>{m.current&&clearTimeout(m.current),l(!1)};u.useEffect(()=>()=>{m.current&&clearTimeout(m.current)},[]);const v={top:"-translate-x-1/2 -translate-y-full",bottom:"-translate-x-1/2 translate-y-0",left:"-translate-x-full -translate-y-1/2",right:"translate-x-0 -translate-y-1/2"};return e.jsxs(e.Fragment,{children:[e.jsx("div",{ref:o,onMouseEnter:y,onMouseLeave:d,className:"inline-flex",children:r}),n&&e.jsx("div",{className:`
|
|
23
|
+
fixed z-50 px-2 py-1 text-xs font-medium text-white rounded-md pointer-events-none
|
|
24
|
+
bg-[var(--widget-text)] shadow-lg
|
|
25
|
+
${v[a]}
|
|
26
|
+
animate-in fade-in-0 zoom-in-95 duration-200
|
|
27
|
+
`,style:{left:`${h.x}px`,top:`${h.y}px`},children:t})]})},Me=t=>{if(Number.isNaN(t.getTime()))return"Long ago";const s=new Date().getTime()-t.getTime(),n=Math.floor(s/6e4),l=Math.floor(s/36e5),h=Math.floor(s/864e5);return n<1?"Just now":n<60?`${n}m ago`:l<24?`${l}h ago`:h<7?`${h}d ago`:t.toLocaleDateString()},O=({type:t,className:r})=>{const a=r||"w-4 h-4";switch(t){case"mark_read":return e.jsx(L,{className:a});case"snooze":return e.jsx(be,{className:a});case"archive":return e.jsx(J,{className:a});default:return null}},Z=({notification:t,onActionClick:r,onSelectionChange:a,isSelected:s=!1})=>{const[n,l]=u.useState(!1),h=Number.isNaN(t.timestamp.getTime()),f=h?void 0:t.timestamp.toISOString(),m=Me(t.timestamp),o=d=>{r&&r(t.id,d),l(!1)},y=()=>{a&&a(!s)};return e.jsxs("div",{className:`
|
|
28
|
+
relative group flex items-start gap-3 px-4 py-3 border-b border-border-light
|
|
29
|
+
transition-all duration-200
|
|
30
|
+
bg-widget-background hover:bg-widget-hover
|
|
31
|
+
${s?"bg-widget-primary-light":""}
|
|
32
|
+
`,onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),"data-testid":"notification-item","data-notification-id":t.id,children:[a&&e.jsx("div",{className:"flex-shrink-0 pt-0.5",children:e.jsx("input",{type:"checkbox",checked:s,onChange:y,className:"w-4 h-4 text-[var(--widget-primary)] border-[var(--widget-border)] rounded cursor-pointer focus:ring-2 focus:ring-[var(--widget-primary)] focus:ring-offset-0","aria-label":`Select notification: ${t.subject}`})}),e.jsx("div",{className:"flex-shrink-0",children:t.avatar?e.jsx("img",{src:t.avatar,alt:"",className:"w-10 h-10 rounded-full object-cover border border-border","aria-hidden":"true",loading:"lazy"}):e.jsx("div",{className:"w-10 h-10 rounded-full bg-gradient-to-br from-widget-primary to-widget-primary-hover flex items-center justify-center shadow-sm",children:e.jsx("span",{className:"text-white font-semibold text-base",children:t.subject.charAt(0).toUpperCase()})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2 mb-0.5",children:[e.jsx("h3",{className:`text-sm leading-5 text-[var(--widget-text)] ${t.isRead?"font-medium":"font-semibold"}`,children:t.subject}),!t.isRead&&e.jsx("div",{className:"flex-shrink-0 mt-1.5 ml-1",children:e.jsx("div",{className:"w-2 h-2 rounded-full bg-unread-indicator shadow-sm","aria-label":"Unread",role:"img"})})]}),e.jsx("p",{className:"text-sm text-[var(--widget-text-secondary)] line-clamp-2 leading-relaxed mb-2",children:t.body}),t.actions&&t.actions.length>0&&e.jsx("div",{className:"flex items-center gap-2 mb-2",children:t.actions.map((d,v)=>e.jsx("button",{onClick:p=>{p.stopPropagation(),o(d)},className:`
|
|
33
|
+
px-3 py-1.5 rounded-md text-sm font-medium transition-colors
|
|
34
|
+
${v===0?"bg-[var(--widget-primary)] text-white hover:bg-[var(--widget-primary-hover)] shadow-sm":"bg-transparent text-[var(--widget-text-secondary)] hover:bg-[var(--widget-bg-hover)] border border-[var(--widget-border)]"}
|
|
35
|
+
`,children:d.label},v))}),e.jsxs("div",{className:"flex items-center justify-between min-h-[20px]",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("time",{className:"text-xs text-[var(--widget-text-tertiary)]",dateTime:f,children:m})}),e.jsxs("div",{className:`flex items-center gap-1 transition-opacity duration-200 ${n?"opacity-100":"opacity-0"}`,onClick:d=>d.stopPropagation(),children:[e.jsx(A,{content:"Mark as read",position:"top",children:e.jsx("button",{className:"inline-flex items-center justify-center w-7 h-7 rounded-md text-[var(--widget-text-secondary)] hover:text-[var(--widget-text)] hover:bg-[var(--widget-bg-hover)] transition-colors",onClick:()=>o({type:"mark_read",label:"Mark as read",handler:async()=>{}}),"aria-label":"Mark as read",children:e.jsx(O,{type:"mark_read"})})}),e.jsx(A,{content:"Snooze",position:"top",children:e.jsx("button",{className:"inline-flex items-center justify-center w-7 h-7 rounded-md text-[var(--widget-text-secondary)] hover:text-[var(--widget-text)] hover:bg-[var(--widget-bg-hover)] transition-colors",onClick:()=>o({type:"custom",label:"Snooze",handler:async()=>{}}),"aria-label":"Snooze",children:e.jsx(O,{type:"snooze"})})}),e.jsx(A,{content:"Archive",position:"top",children:e.jsx("button",{className:"inline-flex items-center justify-center w-7 h-7 rounded-md text-[var(--widget-text-secondary)] hover:text-[var(--widget-text)] hover:bg-[var(--widget-bg-hover)] transition-colors",onClick:()=>o({type:"archive",label:"Archive",handler:async()=>{}}),"aria-label":"Archive",children:e.jsx(O,{type:"archive"})})})]})]})]}),e.jsxs("div",{className:"sr-only",children:["Notification from ",h?"Unknown time":t.timestamp.toLocaleString(),".",t.isRead?"Read":"Unread",".",t.isArchived?"Archived":"Active","."]})]})},W=({count:t=3})=>e.jsx(e.Fragment,{children:Array.from({length:t}).map((r,a)=>e.jsxs("div",{className:"flex items-start gap-3 px-4 py-3 border-b border-border-light animate-pulse",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("div",{className:"w-10 h-10 rounded-full bg-widget-hover"})}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("div",{className:"h-4 w-3/4 rounded bg-widget-hover"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"h-3 w-full rounded bg-widget-hover"}),e.jsx("div",{className:"h-3 w-5/6 rounded bg-widget-hover"})]}),e.jsx("div",{className:"h-3 w-16 rounded bg-widget-hover"})]}),e.jsx("div",{className:"flex-shrink-0",children:e.jsx("div",{className:"w-2 h-2 rounded-full bg-widget-hover"})})]},a))}),K=({title:t="No Items",description:r="There are no items to display",icon:a})=>e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 px-4",children:[a&&e.jsx("div",{className:"mb-4 text-gray-300",children:a}),e.jsx("p",{className:"text-sm text-text-gray-300 text-center",children:r})]}),ze=({selectedNotifications:t,onMarkAllAsRead:r,onMarkAllAsUnread:a,onArchiveAll:s,onDeleteAll:n,onClearSelection:l,className:h=""})=>{const[f,m]=u.useState(!1),[o,y]=u.useState(null),d=t.length,v=async(p,i)=>{if(d!==0){m(!0),y(null);try{const c=await p(t);y(c),c.success&&l()}catch(c){y({success:!1,processedCount:0,failedCount:d,errors:[{notificationId:"",error:c}]})}finally{m(!1)}}};return d===0?null:e.jsxs("div",{className:`border-t border-border bg-widget-primary-light p-2 ${h}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-sm font-medium text-widget-primary",children:[d," notification",d!==1?"s":""," selected"]}),o&&!o.success&&e.jsxs("span",{className:"text-xs text-[var(--widget-error)]",children:[o.failedCount," failed"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>v(r),disabled:f,className:"inline-flex items-center px-2 py-1 text-xs font-medium text-blue-700 bg-white border border-blue-300 rounded hover:bg-blue-50 focus:outline-none focus:ring-2 focus:ring-blue-500 disabled:opacity-50 disabled:cursor-not-allowed transition-colors","data-testid":"bulk-mark-read",children:[e.jsx(L,{className:"mr-1 w-4 h-4"}),"Mark Read"]}),e.jsxs("button",{type:"button",onClick:()=>v(a),disabled:f,className:"inline-flex items-center px-2 py-1 text-xs font-medium text-blue-700 bg-white border border-blue-300 rounded hover:bg-blue-50 focus:outline-none focus:ring-2 focus:ring-blue-500 disabled:opacity-50 disabled:cursor-not-allowed transition-colors","data-testid":"bulk-mark-unread",children:[e.jsx(X,{className:"mr-1 w-4 h-4"}),"Mark Unread"]}),e.jsxs("button",{type:"button",onClick:()=>v(s),disabled:f,className:"inline-flex items-center px-2 py-1 text-xs font-medium text-text-secondary bg-white border border-border rounded hover:bg-widget-hover focus:outline-none focus:ring-2 focus:ring-text-secondary disabled:opacity-50 disabled:cursor-not-allowed transition-colors","data-testid":"bulk-archive",children:[e.jsx(J,{className:"mr-1 w-4 h-4"}),"Archive"]}),e.jsxs("button",{type:"button",onClick:()=>{window.confirm(`Are you sure you want to delete ${d} notification${d!==1?"s":""}? This action cannot be undone.`)&&v(n)},disabled:f,className:"inline-flex items-center px-2 py-1 text-xs font-medium text-[var(--widget-error)] bg-white border border-[var(--widget-error)]/30 rounded hover:bg-[var(--widget-error)]/10 focus:outline-none focus:ring-2 focus:ring-[var(--widget-error)] disabled:opacity-50 disabled:cursor-not-allowed transition-colors","data-testid":"bulk-delete",children:[e.jsx(me,{className:"mr-1 w-4 h-4"}),"Delete"]}),e.jsx("button",{type:"button",onClick:l,disabled:f,className:"inline-flex items-center px-1 py-1 text-xs font-medium text-text-secondary hover:text-text-primary focus:outline-none focus:ring-2 focus:ring-text-secondary disabled:opacity-50 disabled:cursor-not-allowed transition-colors","data-testid":"clear-selection","aria-label":"Clear selection",children:e.jsx(Q,{className:"w-5 h-5"})})]})]}),f&&e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-[var(--widget-primary)]"}),e.jsx("span",{className:"text-xs text-[var(--widget-primary)]",children:"Processing..."})]}),o&&e.jsx("div",{className:"mt-2",children:o.success?e.jsxs("div",{className:"text-xs text-[var(--widget-success)]",children:["Successfully processed ",o.processedCount," notification",o.processedCount!==1?"s":""]}):e.jsxs("div",{className:"text-xs text-[var(--widget-error)]",children:[o.processedCount>0&&e.jsxs("span",{children:["Processed ",o.processedCount,", "]}),"Failed to process ",o.failedCount," notification",o.failedCount!==1?"s":""]})})]})},Se=({notifications:t,isLoading:r=!1,error:a,onNotificationAction:s,selectedNotifications:n=[],onSelectionChange:l,onSelectAll:h,onLoadMore:f,hasMore:m=!1,className:o=""})=>{const y=u.useRef(null),d=u.useRef(null),[v,p]=u.useState(!1);u.useEffect(()=>{if(!(!f||!m||v))return y.current=new IntersectionObserver(x=>{x[0].isIntersecting&&m&&!v&&(p(!0),f(),setTimeout(()=>p(!1),500))},{root:null,rootMargin:"100px",threshold:.1}),d.current&&y.current.observe(d.current),()=>{y.current&&y.current.disconnect()}},[f,m,v]);const i=u.useCallback(async(x,g)=>{try{g.handler&&await g.handler(x),s&&g.type&&s(x,g)}catch{}},[s]),c=u.useCallback((x,g)=>{l&&l(x,g)},[l]);return r&&t.length===0?e.jsx("div",{className:`flex flex-col h-full bg-widget-background ${o}`,children:e.jsx(W,{count:5})}):a?e.jsx("div",{className:`flex flex-col h-full bg-widget-background ${o}`,children:e.jsx("div",{className:"flex items-center justify-center flex-1 py-12",children:e.jsx(K,{title:"Error Loading Notifications",description:"Failed to load notifications. Please try again.",icon:e.jsx("svg",{className:"w-12 h-12 text-[var(--widget-error)]",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4v.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})})})}):t.length===0?e.jsx("div",{className:`flex flex-col h-full bg-widget-background ${o}`,children:e.jsx("div",{className:"flex items-center justify-center flex-1 py-12",children:e.jsx(K,{title:"No Notifications",description:"You're all caught up! No notifications to display.",icon:e.jsx("svg",{className:"w-12 h-12 text-[var(--widget-text-tertiary)]",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-2.586a1 1 0 00-.707.293l-2.414 2.414a1 1 0 01-.707.293h-3.172a1 1 0 01-.707-.293l-2.414-2.414A1 1 0 006.586 13H4"})})})})}):e.jsxs("div",{className:`flex flex-col h-full ${o}`,children:[h&&s&&e.jsx(ze,{selectedNotifications:n,onMarkAllAsRead:async x=>{try{for(const g of x)s(g,{type:"mark_read",label:"Mark as read",handler:async()=>{}});return{success:!0,processedCount:x.length,failedCount:0,errors:[]}}catch(g){return{success:!1,processedCount:0,failedCount:x.length,errors:[{notificationId:"",error:g}]}}},onMarkAllAsUnread:async x=>{try{for(const g of x)s(g,{type:"mark_unread",label:"Mark as unread",handler:async()=>{}});return{success:!0,processedCount:x.length,failedCount:0,errors:[]}}catch(g){return{success:!1,processedCount:0,failedCount:x.length,errors:[{notificationId:"",error:g}]}}},onArchiveAll:async x=>{try{for(const g of x)s(g,{type:"archive",label:"Archive",handler:async()=>{}});return{success:!0,processedCount:x.length,failedCount:0,errors:[]}}catch(g){return{success:!1,processedCount:0,failedCount:x.length,errors:[{notificationId:"",error:g}]}}},onDeleteAll:async x=>{try{for(const g of x)s(g,{type:"delete",label:"Delete",handler:async()=>{}});return{success:!0,processedCount:x.length,failedCount:0,errors:[]}}catch(g){return{success:!1,processedCount:0,failedCount:x.length,errors:[{notificationId:"",error:g}]}}},onClearSelection:()=>h(!1)}),e.jsx("div",{className:"flex-1",children:e.jsxs("div",{children:[t.map(x=>e.jsx(Z,{notification:x,onActionClick:i,isSelected:n.includes(x.id),onSelectionChange:l?g=>c(x.id,g):void 0},x.id)),m&&e.jsx("div",{ref:d,className:"py-2",children:v&&e.jsx(W,{count:3})})]})})]})},Ee=({notifications:t,activeTab:r,onTabChange:a,size:s="medium",className:n=""})=>{const l=u.useMemo(()=>{const h=t.length,f=t.filter(d=>!d.isRead).length,m=new Map;t.forEach(d=>{d.tags.forEach(v=>{m.set(v,(m.get(v)||0)+1)})});const o=[{id:"all",label:"All",count:h,icon:e.jsx(Ce,{className:"w-4 h-4"})},{id:"unread",label:"Unread",count:f,icon:e.jsx(X,{className:"w-4 h-4"})}],y=Array.from(m.entries()).sort(([,d],[,v])=>v-d).slice(0,5).map(([d,v])=>({id:`tag:${d}`,label:d,count:v,icon:e.jsx(ye,{className:"w-4 h-4"})}));return[...o,...y]},[t]);return e.jsx("div",{className:`
|
|
36
|
+
flex items-center gap-1 overflow-x-auto widget-scrollbar border-b border-[var(--widget-border)] px-2 py-1.5
|
|
37
|
+
${n}
|
|
38
|
+
`,style:{backgroundColor:"var(--widget-background)"},role:"tablist",children:l.map(h=>{const f=r===h.id;return e.jsxs("button",{onClick:()=>a(h.id),className:`
|
|
39
|
+
flex items-center gap-2 px-3 py-1.5 rounded-full text-sm font-medium transition-all whitespace-nowrap outline-none focus:ring-2 focus:ring-offset-1
|
|
40
|
+
${f?"shadow-sm":"tab-inactive"}
|
|
41
|
+
`,style:f?{backgroundColor:"var(--widget-primary)",color:"#ffffff"}:{color:"var(--widget-text-secondary)"},role:"tab","aria-selected":f,"data-testid":`tab-${h.id}`,children:[h.icon&&e.jsx("span",{style:{color:f?"#ffffff":"var(--widget-text-tertiary)"},children:h.icon}),e.jsx("span",{children:h.label}),h.count!==void 0&&h.count>0&&e.jsxs("span",{className:"ml-1 text-[10px] font-semibold",style:{color:f?"#ffffff":"var(--widget-text-tertiary)"},children:["(",h.count>99?"99+":h.count,")"]})]},h.id)})})},k=({id:t,label:r,checked:a,onChange:s,disabled:n=!1,icon:l})=>e.jsxs("div",{className:"flex items-center justify-between py-2.5",children:[r&&e.jsxs("label",{htmlFor:t,className:"flex items-center gap-2 text-sm font-medium text-text-primary cursor-pointer",children:[l&&e.jsx("span",{className:"text-widget-primary",children:l}),e.jsx("span",{children:r})]}),e.jsx("button",{type:"button",id:t,role:"switch","aria-checked":a,disabled:n,className:`
|
|
42
|
+
relative inline-flex h-5 w-9 flex-shrink-0 rounded-full border-2 border-transparent
|
|
43
|
+
transition-colors duration-200 ease-in-out
|
|
44
|
+
focus:outline-none focus:ring-2 focus:ring-widget-primary focus:ring-offset-2
|
|
45
|
+
${a?"bg-widget-primary":"bg-gray-300 dark:bg-gray-600"}
|
|
46
|
+
${n?"opacity-50 cursor-not-allowed":"cursor-pointer"}
|
|
47
|
+
`,onClick:()=>!n&&s(!a),children:e.jsx("span",{className:`
|
|
48
|
+
pointer-events-none inline-block h-4 w-4 transform rounded-full bg-white shadow-md ring-0
|
|
49
|
+
transition duration-200 ease-in-out
|
|
50
|
+
${a?"translate-x-4":"translate-x-0"}
|
|
51
|
+
`})})]}),He=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],ee=({preferences:t,onPreferenceChange:r,isLoading:a})=>{const[s,n]=u.useState({global:!0,schedule:!1}),[l,h]=u.useState({}),f=i=>{n(c=>({...c,[i]:!c[i]}))},m=i=>{h(c=>({...c,[i]:!c[i]}))},o=(i,c)=>{r(`channels.${i}`,c)},y=(i,c)=>{r(`subscriptions.${i}.enabled`,c)},d=(i,c,x)=>{r(`subscriptions.${i}.channels.${c}`,x)},v=i=>{const c=[...t.deliverySchedule.weekdays];c[i]=!c[i],r("deliverySchedule.weekdays",c)},p=i=>{switch(i){case"email":return e.jsx(ve,{className:"w-4 h-4"});case"push":return e.jsx(F,{className:"w-4 h-4"});case"sms":return e.jsx(ke,{className:"w-4 h-4"});case"inApp":return e.jsx(we,{className:"w-4 h-4"});default:return null}};return e.jsxs("div",{className:"h-full overflow-y-auto widget-scrollbar p-2",style:{backgroundColor:"var(--widget-background)"},"data-testid":"preferences-view",children:[a&&e.jsx("div",{className:"absolute inset-0 bg-[var(--widget-bg)]/75 backdrop-blur-sm flex items-center justify-center z-10",children:e.jsx("div",{className:"w-8 h-8 border-2 border-[var(--widget-primary)] border-t-transparent rounded-full animate-spin"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"border border-[var(--widget-border)] rounded-lg overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>f("global"),className:"w-full flex items-center justify-between px-2 py-1.5 bg-[var(--widget-bg-secondary)] hover:bg-[var(--widget-bg-hover)] transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{className:"w-5 h-5 text-widget-primary"}),e.jsx("span",{className:"font-semibold text-sm text-text-primary",children:"Global Preferences"})]}),s.global?e.jsx(_,{className:"w-5 h-5 text-text-secondary"}):e.jsx(I,{className:"w-5 h-5 text-text-secondary"})]}),s.global&&e.jsxs("div",{className:"px-2 pb-1.5 divide-y divide-border-light",style:{backgroundColor:"var(--widget-background)"},children:[e.jsx(k,{id:"channel-email",label:"Email",icon:p("email"),checked:t.channels.email,onChange:i=>o("email",i),disabled:a}),e.jsx(k,{id:"channel-inapp",label:"In-App",icon:p("inApp"),checked:t.channels.inApp,onChange:i=>o("inApp",i),disabled:a}),e.jsx(k,{id:"channel-push",label:"Push",icon:p("push"),checked:t.channels.push,onChange:i=>o("push",i),disabled:a})]})]}),e.jsxs("div",{className:"border border-[var(--widget-border)] rounded-lg overflow-hidden",style:{backgroundColor:"var(--widget-background)"},children:[e.jsxs("button",{type:"button",onClick:()=>f("schedule"),className:"w-full flex items-center justify-between px-2 py-1.5 bg-[var(--widget-bg-secondary)] hover:bg-[var(--widget-bg-hover)] transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xe,{className:"w-5 h-5 text-widget-primary"}),e.jsx("span",{className:"font-semibold text-sm text-text-primary",children:"Schedule"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(k,{id:"schedule-enabled",checked:s.schedule,onChange:()=>{},disabled:a}),e.jsx("div",{className:`transition-transform duration-200 ${s.schedule?"rotate-180":""}`,"aria-hidden":"true",children:e.jsx(I,{className:"w-5 h-5 text-text-secondary"})})]})]}),s.schedule&&e.jsxs("div",{className:"px-2 py-1.5 space-y-2 animate-in slide-in-from-top-2 duration-200",style:{backgroundColor:"var(--widget-background)"},children:[e.jsx("div",{className:"text-sm text-[var(--widget-text-secondary)]",children:"Allow notifications between:"}),e.jsxs("div",{className:"grid grid-cols-[auto_1fr_auto_auto] gap-x-4 gap-y-3 items-center",children:[e.jsx("div",{className:"col-span-2 text-xs font-semibold text-[var(--widget-text-tertiary)] pl-1",children:"Days"}),e.jsx("div",{className:"text-xs font-semibold text-[var(--widget-text-tertiary)] w-[88px]",children:"From"}),e.jsx("div",{className:"text-xs font-semibold text-[var(--widget-text-tertiary)] w-[88px]",children:"To"}),He.map((i,c)=>{const x=t.deliverySchedule.weekdays[c];return e.jsxs(u.Fragment,{children:[e.jsx("div",{className:"flex items-center h-8",children:e.jsx(k,{id:`day-${c}`,checked:x,onChange:()=>v(c),disabled:a})}),e.jsx("div",{className:`text-sm ${x?"text-text-primary":"text-text-tertiary"}`,children:i}),e.jsx("div",{className:"w-[88px]",children:e.jsx("input",{type:"time",className:"w-full px-2 py-1 bg-widget-background border border-border rounded text-sm text-text-primary focus:outline-none focus:ring-1 focus:ring-widget-primary disabled:opacity-50 disabled:bg-widget-hover",value:t.deliverySchedule.quietHours.start,onChange:g=>r("deliverySchedule.quietHours.start",g.target.value),disabled:a||!x})}),e.jsx("div",{className:"w-[88px]",children:e.jsx("input",{type:"time",className:"w-full px-2 py-1 bg-widget-background border border-border rounded text-sm text-text-primary focus:outline-none focus:ring-1 focus:ring-widget-primary disabled:opacity-50 disabled:bg-widget-hover",value:t.deliverySchedule.quietHours.end,onChange:g=>r("deliverySchedule.quietHours.end",g.target.value),disabled:a||!x})})]},i)})]})]})]}),t.subscriptions.length>0&&t.subscriptions.map(i=>e.jsxs("div",{className:"border border-[var(--widget-border)] rounded-lg overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>m(i.workflowId),className:"w-full flex items-center justify-between px-2 py-1.5 bg-[var(--widget-bg-secondary)] hover:bg-[var(--widget-bg-hover)] transition-colors",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"text-sm font-medium text-text-primary",children:i.name})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(k,{id:`workflow-${i.workflowId}`,checked:i.enabled,onChange:c=>y(i.workflowId,c),disabled:a}),l[i.workflowId]?e.jsx(_,{className:"w-5 h-5 text-text-secondary"}):e.jsx(I,{className:"w-5 h-5 text-text-secondary"})]})]}),l[i.workflowId]&&i.enabled&&e.jsxs("div",{className:"px-2 pb-1.5 divide-y divide-border-light",style:{backgroundColor:"var(--widget-background)"},children:[e.jsx(k,{id:`sub-${i.workflowId}-inapp`,label:"In-App",icon:p("inApp"),checked:i.channels.inApp,onChange:c=>d(i.workflowId,"inApp",c),disabled:a}),e.jsx(k,{id:`sub-${i.workflowId}-push`,label:"Push",icon:p("push"),checked:i.channels.push,onChange:c=>d(i.workflowId,"push",c),disabled:a})]})]},i.workflowId))]})]})};class $ extends u.Component{constructor(r){super(r),this.state={hasError:!1,error:null}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,a){const{componentName:s="Unknown Component",onError:n}=this.props;n&&n(r,a)}render(){return this.state.hasError?this.props.fallback?this.props.fallback:e.jsx("div",{className:"p-2 text-sm text-gray-500 bg-gray-50 border border-gray-200 rounded","data-testid":"component-error-fallback",children:e.jsxs("span",{children:["Unable to load ",this.props.componentName||"component"]})}):this.props.children}}const Te=({onRetry:t,error:r})=>e.jsxs("div",{className:"p-3 text-center","data-testid":"notifications-fallback",children:[e.jsx("div",{className:"text-[var(--widget-text-tertiary)] mb-2",children:e.jsx(L,{className:"w-12 h-12 mx-auto"})}),e.jsx("p",{className:"text-sm text-[var(--widget-text-secondary)] mb-3",children:r?"Failed to load notifications":"No notifications available"}),t&&e.jsx("button",{type:"button",className:"text-sm text-[var(--widget-primary)] hover:text-[var(--widget-primary-hover)] font-medium transition-colors",onClick:t,children:"Try again"})]}),U=({onRetry:t,onBack:r})=>e.jsxs("div",{className:"p-3 text-center","data-testid":"preferences-fallback",children:[e.jsx("div",{className:"text-[var(--widget-text-tertiary)] mb-2",children:e.jsx(Y,{className:"w-12 h-12 mx-auto"})}),e.jsx("p",{className:"text-sm text-[var(--widget-text-secondary)] mb-3",children:"Unable to load preferences"}),e.jsxs("div",{className:"space-x-2",children:[t&&e.jsx("button",{type:"button",className:"text-sm text-[var(--widget-primary)] hover:text-[var(--widget-primary-hover)] font-medium transition-colors",onClick:t,children:"Try again"}),r&&e.jsx("button",{type:"button",className:"text-sm text-[var(--widget-text-secondary)] hover:text-[var(--widget-text)] font-medium transition-colors",onClick:r,children:"Back"})]})]}),Ie=({onRetry:t,error:r})=>e.jsxs("div",{className:"p-3 text-center bg-[var(--widget-warning)]/10 border border-[var(--widget-warning)]/20 rounded-lg","data-testid":"sdk-connection-fallback",children:[e.jsx("div",{className:"text-[var(--widget-warning)] mb-2",children:e.jsx(pe,{className:"w-12 h-12 mx-auto"})}),e.jsx("p",{className:"text-sm text-[var(--widget-warning)] mb-3 font-medium",children:"Connection to notification service failed"}),r&&process.env.NODE_ENV==="development"&&e.jsx("p",{className:"text-xs text-[var(--widget-warning)] mb-3 font-mono opacity-80",children:r}),t&&e.jsx("button",{type:"button",className:"text-sm font-medium bg-[var(--widget-warning)]/20 text-[var(--widget-warning)] hover:bg-[var(--widget-warning)]/30 px-3 py-1 rounded transition-colors",onClick:t,children:"Retry connection"})]}),Ae=({message:t="Loading..."})=>e.jsxs("div",{className:"p-3 text-center","data-testid":"loading-fallback",children:[e.jsx("div",{className:"w-6 h-6 border-2 border-[var(--widget-primary)] border-t-transparent rounded-full animate-spin mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-[var(--widget-text-secondary)]",children:t})]}),Oe=(t,r)=>{switch(r){case"all":return t;case"unread":return t.filter(a=>!a.isRead);default:if(r.startsWith("tag:")){const a=r.substring(4);return t.filter(s=>s.tags.includes(a))}return t}},$e=(t,r)=>{if(!r.trim())return t;const a=r.toLowerCase().trim();return t.filter(s=>{const n=s.subject.toLowerCase(),l=s.body.toLowerCase(),h=s.tags.join(" ").toLowerCase();return n.includes(a)||l.includes(a)||h.includes(a)})},Le=(t,r)=>{const a=[...t];switch(r){case"newest":return a.sort((s,n)=>n.timestamp.getTime()-s.timestamp.getTime());case"oldest":return a.sort((s,n)=>s.timestamp.getTime()-n.timestamp.getTime());case"unread-first":return a.sort((s,n)=>s.isRead===n.isRead?n.timestamp.getTime()-s.timestamp.getTime():s.isRead?1:-1);case"read-first":return a.sort((s,n)=>s.isRead===n.isRead?n.timestamp.getTime()-s.timestamp.getTime():s.isRead?-1:1);default:return a}},Re=(t,r,a,s="newest")=>{let n=t;return n=Oe(n,r),a&&(n=$e(n,a)),n=Le(n,s),n},Be=({isOpen:t,onClose:r,position:a,currentView:s,onViewChange:n,notifications:l,onNotificationAction:h,preferences:f,onPreferenceChange:m,isPreferencesLoading:o=!1,size:y="medium"})=>{const d=u.useRef(null),v=u.useRef(null),[p,i]=u.useState("all"),[c,x]=u.useState([]),[g,S]=u.useState(""),R=u.useCallback(()=>{const b=window.__notificationSDK?.config,j=window.__notificationSDK?.client;if(!b||!j)return null;const{tenantId:N,environmentId:C,subscriberId:P}=b;return!N||!C||!P?null:{client:j,tenantId:N,environmentId:C,subscriberId:P}},[]),te=u.useCallback(async b=>{const j=R();if(!j)return{success:!1,processedCount:0,failedCount:b.length,errors:[]};try{for(const N of b)await j.client.inbox.markAsRead(N,j.tenantId,j.environmentId,j.subscriberId);return{success:!0,processedCount:b.length,failedCount:0,errors:[]}}catch(N){return{success:!1,processedCount:0,failedCount:b.length,errors:[{notificationId:"",error:N}]}}},[R]),re=u.useMemo(()=>Re(l,p,g),[l,p,g]),E=u.useCallback(b=>{d.current&&!d.current.contains(b.target)&&r()},[r]),H=u.useCallback(b=>{b.key==="Escape"&&r()},[r]),T=u.useCallback(b=>{if(!(!t||!d.current)&&b.key==="Tab"){const j=d.current.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');if(j.length===0)return;const N=j[0],C=j[j.length-1];b.shiftKey?document.activeElement===N&&(C.focus(),b.preventDefault()):document.activeElement===C&&(N.focus(),b.preventDefault())}},[t]);if(u.useEffect(()=>(t?(v.current=document.activeElement,document.addEventListener("mousedown",E),document.addEventListener("keydown",H),document.addEventListener("keydown",T),setTimeout(()=>{d.current?.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')?.focus()},0)):(v.current&&v.current.focus(),i("all"),x([]),S("")),()=>{document.removeEventListener("mousedown",E),document.removeEventListener("keydown",H),document.removeEventListener("keydown",T)}),[t,E,H,T]),!t)return null;const ae={left:"left-0 origin-top-left",right:"right-0 origin-top-right"},B=l.filter(b=>!b.isRead).length;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 bg-black/20 backdrop-blur-sm z-40 md:hidden transition-opacity duration-200","aria-hidden":"true",onClick:r}),e.jsxs("div",{ref:d,className:`
|
|
52
|
+
absolute top-full mt-2 ${ae[a]}
|
|
53
|
+
w-[var(--widget-popover-width,400px)] max-h-[var(--widget-popover-max-height,580px)]
|
|
54
|
+
border border-[var(--widget-border)] rounded-2xl overflow-hidden
|
|
55
|
+
shadow-[var(--widget-shadow-xl)]
|
|
56
|
+
z-50 flex flex-col
|
|
57
|
+
animate-in fade-in-0 zoom-in-95 duration-200
|
|
58
|
+
max-sm:fixed max-sm:inset-x-4 max-sm:top-16 max-sm:bottom-4
|
|
59
|
+
max-sm:w-auto max-sm:max-w-none max-sm:max-h-[calc(100vh-120px)]
|
|
60
|
+
`,style:{backgroundColor:"var(--widget-background)"},role:"dialog","aria-modal":"true","aria-label":"Notifications","data-testid":"inbox-popover",children:[e.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between px-4 py-3 border-b border-[var(--widget-border)]",style:{backgroundColor:"var(--widget-background)"},children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("h2",{className:"text-base font-semibold",style:{color:"var(--widget-text)"},children:s==="notifications"?"Notifications":"Preferences"})}),e.jsxs("div",{className:"flex items-center gap-1",children:[s==="notifications"&&e.jsx("button",{type:"button",className:"inline-flex items-center justify-center w-6 h-6 rounded-lg text-[var(--widget-text-secondary)] hover:text-[var(--widget-text)] hover:bg-[var(--widget-bg-hover)] transition-colors",onClick:()=>n("preferences"),"aria-label":"Open preferences","data-testid":"preferences-button",children:e.jsx(Y,{className:"w-4 h-4"})}),s==="preferences"&&e.jsx("button",{type:"button",className:"inline-flex items-center justify-center w-6 h-6 rounded-lg text-[var(--widget-text-secondary)] hover:text-[var(--widget-text)] hover:bg-[var(--widget-bg-hover)] transition-colors",onClick:()=>n("notifications"),"aria-label":"Back to notifications","data-testid":"back-button",children:e.jsx(je,{className:"w-5 h-5"})}),e.jsx("button",{type:"button",className:"inline-flex items-center justify-center w-6 h-6 rounded-lg text-[var(--widget-text-secondary)] hover:text-[var(--widget-text)] hover:bg-[var(--widget-bg-hover)] transition-colors",onClick:r,"aria-label":"Close notifications","data-testid":"close-button",children:e.jsx(Q,{className:"w-5 h-5"})})]})]}),s==="notifications"?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex-shrink-0 px-4 py-2.5 border-b border-[var(--widget-border)]",style:{backgroundColor:"var(--widget-background)"},children:e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:e.jsx(fe,{className:"w-5 h-5 text-[var(--widget-text-tertiary)]"})}),e.jsx("input",{type:"text",className:`\r
|
|
61
|
+
w-full pl-10 pr-3 py-1 \r
|
|
62
|
+
bg-[var(--widget-bg-secondary)] \r
|
|
63
|
+
border border-[var(--widget-border)] \r
|
|
64
|
+
rounded-lg \r
|
|
65
|
+
text-sm text-[var(--widget-text)] \r
|
|
66
|
+
placeholder:text-[var(--widget-text-tertiary)]\r
|
|
67
|
+
focus:outline-none focus:ring-2 focus:ring-[var(--widget-primary)] focus:border-transparent\r
|
|
68
|
+
transition-colors\r
|
|
69
|
+
`,placeholder:"Search notifications...",value:g,onChange:b=>S(b.target.value),"aria-label":"Search notifications"})]})}),e.jsx(Ee,{notifications:l,activeTab:p,onTabChange:b=>i(b),size:y}),e.jsx("div",{className:"flex-1 overflow-y-auto widget-scrollbar",style:{backgroundColor:"var(--widget-background)",maxHeight:"calc(var(--widget-popover-max-height) - 200px)"},children:e.jsx($,{fallback:e.jsx(Te,{}),children:e.jsx(Se,{notifications:re,onNotificationAction:h})})}),B>0&&e.jsx("div",{className:"flex-shrink-0 px-4 py-2.5 border-t border-[var(--widget-border)]",style:{backgroundColor:"var(--widget-bg-hover)"},children:e.jsx("button",{type:"button",className:"w-full px-4 py-2 text-sm font-medium text-[var(--widget-primary)] hover:text-[var(--widget-primary-hover)] hover:bg-[var(--widget-primary-light)] rounded-lg transition-colors",onClick:()=>{const b=l.filter(j=>!j.isRead).map(j=>j.id);te(b)},"aria-label":`Mark all ${B} notifications as read`,children:"Mark all as read"})})]}):e.jsx("div",{className:"flex-1 overflow-y-auto widget-scrollbar",children:e.jsx($,{fallback:e.jsx(U,{}),children:f&&m?e.jsx(ee,{preferences:f,onPreferenceChange:m,isLoading:o,onBack:()=>n("notifications")}):e.jsx(U,{})})})]})]})};exports.BellComponent=he;exports.ComponentErrorBoundary=$;exports.InboxPopover=Be;exports.LoadingFallback=Ae;exports.MdError=ge;exports.MdRefresh=Ne;exports.NotificationItem=Z;exports.PreferencesView=ee;exports.SDKConnectionFallback=Ie;
|
|
70
|
+
//# sourceMappingURL=components-B9Z6HsnI.cjs.map
|