import{j as r,a as t,c as i,F as P,Z as X,l as ne,r as k,f as oe,u as se}from"./provider-jGJDpSsD.js";import{D as A}from"./divider-DgjyvJzD.js";import{S as z}from"./switch-B6Yusz5j.js";import{T as b}from"./typography-D5FAW5Sb.js";import"./index.esm2017-RCKYhhsE.js";import{d as w,b as ae}from"./index-BVE0rL7V.js";import{N as I}from"./notification-service-Cr2tQu20.js";import{u as $}from"./useTranslation-CtY5AHSk.js";import{B as T}from"./button-DGOdsXw0.js";import{A as _}from"./auxiliary-button-1QByv9FD.js";import{B as ee}from"./button-icon-CnvuPCRK.js";import{j as re,g as ce,i as le}from"./responsive-JY1roPos.js";import{ab as de,ac as pe,ad as ge,ae as fe,p as he,q as ue,C as me}from"./icons-e83Zchnl.js";import{I as xe}from"./input-BWFU-BgJ.js";import{g as ye,A as be}from"./use-app-path-BUM05-P1.js";import{u as Y}from"./hooks-Uy2SV-Ot.js";import{u as ve}from"./useMutation-Ci3MrUiP.js";import{u as G}from"./useQuery-aJojuJxG.js";import{d as Ce}from"./index-DB8v_Xz6.js";import{$ as ke,a as q,c as J,b as we}from"./index-CN7DgADU.js";import{E as Ie}from"./error-banner-BQb0KRuh.js";import{P as Se}from"./pagination-D8hP9pqP.js";import{S as te}from"./spinner-2-DFs9Uutz.js";import{b as Be,d as Pe,e as $e,$ as Ee}from"./index-MfOHwliC.js";import{D as Re}from"./datetime-HslA5HLw.js";const F=e=>{const n=w(I);return[n.getPreference(e),o=>{n.setPreference(e,o)}]},Le=({locale:e="ar",readStatus:n=null})=>{var u;const s=w(I),{error:a,isError:o,refetch:l,data:g,isSuccess:x,isInitialLoading:f,isLoading:h,isFetching:y}=G(["get-infinite-notifications"],()=>s.fetchNotification({locale:e,page:s.getPage("infiniteScroll"),readStatus:n}).then(C=>{const v=C;return s.setPaginationMeta(v.data.meta),s.setNotifications(v.data.notificationMessages),s.setPage(s.getPage("infiniteScroll")+1,"infiniteScroll"),v}),{refetchOnMount:!1,refetchOnReconnect:!1,refetchOnWindowFocus:!1,retry:!1});return{data:((u=g==null?void 0:g.data)==null?void 0:u.notificationMessages)??[],error:a,isError:o,isFetching:y,isInitialLoading:f,isLoading:h,isSuccess:x,refetch:l}},Me=({page:e,locale:n="ar",readStatus:s=null})=>{var y;const a=w(I),{data:o,error:l,isError:g,isLoading:x,refetch:f,isFetching:h}=G(["get-paginated-notifications",e,n],()=>a.fetchNotification({locale:n,page:e+1,readStatus:s}),{onSuccess:u=>{a.setPaginationMeta(u.data.meta)},refetchOnMount:!0,refetchOnReconnect:!1,refetchOnWindowFocus:!1,retry:!1});return{data:((y=o==null?void 0:o.data)==null?void 0:y.notificationMessages.map(u=>({...u,props:{...u.props,isRead:u.props.isRead==="true"}})))??[],error:l,isError:g,isFetching:h,isLoading:x,refetch:f}},Ne=()=>{const e=w(I),{isError:n,isLoading:s,mutateAsync:a}=ve([],()=>e.markAllRead(!0));return{isError:n,isLoading:s,mutate:a}},ie=()=>{var a;const e=w(I),{refetch:n,data:s}=G(["get-notifications-count"],()=>e.fetchNotificationCount(),{enabled:!1,onSuccess:o=>{e.setNotificationCount(o.data.unreadCount)},retry:!1});return{data:(a=s==null?void 0:s.data)==null?void 0:a.unreadCount,refetch:n}},We={menuItem:e=>i({":hover":{background:e.colors.background.secondary},alignItems:"center",cursor:"pointer",display:"flex",div:{alignItems:"baseline",display:"flex",gap:16,svg:{height:"24px",width:"24px"}},justifyContent:"space-between",listStyleType:"none",paddingBlock:e.spaces.md,paddingInline:e.spaces.lg,textTransform:"uppercase"})},Z=({prefixIcon:e,ctrlIcon:n,text:s,onClick:a,typographyVariant:o,...l})=>r("li",{css:We.menuItem,onClick:a,...l,children:[r("div",{children:[e,t(b,{variant:o??"h6",children:s})]}),n]}),E={item:i({alignItems:"center",display:"flex",flexDirection:"row",justifyContent:"space-between"}),menuItem:e=>i({":hover":{background:"none",cursor:"default"},...e.typography.subtitleS,color:e.colors.grey[900],paddingBlock:e.spaces.md1,paddingInline:0,textTransform:"none"})},pt=({typographyVariant:e="subtitleS"})=>{const{t:n}=$(void 0,{keyPrefix:"pages.salesAdvisor.notification"}),[s,a]=F("emailNotification"),[o,l]=F("smsNotification"),[g,x]=F("pushNotification"),f={typographyVariant:e};return r(P,{children:[r("div",{css:E.item,children:[t(Z,{text:n("push"),css:E.menuItem,...f}),t(z,{checked:g,onCheckedChange:h=>x(h),size:"xl"})]}),t(A,{}),r("div",{css:E.item,children:[t(Z,{text:n("email"),css:E.menuItem,...f}),t(z,{checked:s,onCheckedChange:h=>a(h),size:"xl"})]}),t(A,{}),r("div",{css:E.item,children:[t(Z,{text:n("sms"),css:E.menuItem,...f}),t(z,{checked:o,onCheckedChange:h=>l(h),size:"xl"})]}),t(A,{})]})},Ae="data:image/svg+xml,%3csvg%20width='72'%20height='68'%20viewBox='0%200%2072%2068'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cellipse%20cx='36'%20cy='62'%20rx='36'%20ry='6'%20fill='%23F8E7E5'/%3e%3cpath%20fill-rule='evenodd'%20clip-rule='evenodd'%20d='M27.0423%2023.0433C27.8234%2022.2623%2029.0897%2022.2623%2029.8707%2023.0433L35.999%2029.1716L42.1273%2023.0433C42.9083%2022.2623%2044.1746%2022.2623%2044.9557%2023.0433C45.7367%2023.8244%2045.7367%2025.0907%2044.9557%2025.8717L38.8274%2032L44.9557%2038.1283C45.7367%2038.9093%2045.7367%2040.1756%2044.9557%2040.9567C44.1746%2041.7377%2042.9083%2041.7377%2042.1273%2040.9567L35.999%2034.8284L29.8707%2040.9567C29.0897%2041.7377%2027.8234%2041.7377%2027.0423%2040.9567C26.2613%2040.1756%2026.2613%2038.9093%2027.0423%2038.1283L33.1706%2032L27.0423%2025.8717C26.2613%2025.0907%2026.2613%2023.8244%2027.0423%2023.0433Z'%20fill='%23787878'/%3e%3cpath%20fill-rule='evenodd'%20clip-rule='evenodd'%20d='M36%207.33398C22.377%207.33398%2011.3333%2018.3776%2011.3333%2032.0007C11.3333%2045.6237%2022.377%2056.6673%2036%2056.6673C49.623%2056.6673%2060.6667%2045.6237%2060.6667%2032.0007C60.6667%2018.3776%2049.623%207.33398%2036%207.33398ZM7.33334%2032.0007C7.33334%2016.1685%2020.1678%203.33398%2036%203.33398C51.8322%203.33398%2064.6667%2016.1685%2064.6667%2032.0007C64.6667%2047.8328%2051.8322%2060.6673%2036%2060.6673C20.1678%2060.6673%207.33334%2047.8328%207.33334%2032.0007Z'%20fill='%23787878'/%3e%3c/svg%3e",Te="data:image/svg+xml,%3csvg%20width='88'%20height='84'%20viewBox='0%200%2088%2084'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cellipse%20cx='44'%20cy='74'%20rx='44'%20ry='10'%20fill='%23ECF2FF'/%3e%3cpath%20fill-rule='evenodd'%20clip-rule='evenodd'%20d='M25.5656%2039.8989C26.5419%2038.9226%2028.1248%2038.9226%2029.1012%2039.8989L37.3334%2048.1312L58.899%2026.5656C59.8753%2025.5893%2061.4582%2025.5893%2062.4345%2026.5656C63.4108%2027.5419%2063.4108%2029.1248%2062.4345%2030.1011L39.1012%2053.4345C38.1248%2054.4108%2036.5419%2054.4108%2035.5656%2053.4345L25.5656%2043.4345C24.5893%2042.4581%2024.5893%2040.8752%2025.5656%2039.8989Z'%20fill='%23787878'/%3e%3cpath%20fill-rule='evenodd'%20clip-rule='evenodd'%20d='M43.9998%209.16669C26.9711%209.16669%2013.1665%2022.9712%2013.1665%2040C13.1665%2057.0288%2026.9711%2070.8334%2043.9998%2070.8334C61.0286%2070.8334%2074.8332%2057.0288%2074.8332%2040C74.8332%2022.9712%2061.0286%209.16669%2043.9998%209.16669ZM8.1665%2040C8.1665%2020.2098%2024.2096%204.16669%2043.9998%204.16669C63.79%204.16669%2079.8332%2020.2098%2079.8332%2040C79.8332%2059.7902%2063.79%2075.8334%2043.9998%2075.8334C24.2096%2075.8334%208.1665%2059.7902%208.1665%2040Z'%20fill='%23787878'/%3e%3c/svg%3e",m={button:e=>i({...e.typography.captionM,marginBlockStart:e.spaces.lg,width:"330px"}),container:i({alignItems:"center",display:"flex",flexDirection:"column",height:"156px",justifyContent:"center"}),emptyStateHeading:e=>i({color:e.colors.grey[800],marginBlockStart:e.spaces.lg}),image:()=>i({height:"68px",width:"72px"}),primaryWrapper:i({alignItems:"center",display:"flex",flexDirection:"column",width:"100%"}),spinner:i({animation:`${X} 2s infinite linear`}),spinnerWrapper:i({display:"flex",justifyContent:"center"}),stateWrapper:i({alignItems:"center",display:"flex",flexDirection:"column",justifyContent:"center",textAlign:"center",width:"350px"}),text:e=>i({color:e.colors.grey[900],marginBlockStart:e.spaces.sm,textAlign:"center"}),typo:e=>i({color:e.colors.grey[900],marginBlockStart:e.spaces.sm})},De=({loading:e,children:n})=>{const{t:s}=$(void 0,{keyPrefix:"pages.salesAdvisor.notification"});return t(P,{children:e?r("div",{css:m.stateWrapper,children:[t("div",{css:m.spinnerWrapper,children:t("img",{src:te,height:68,width:68,css:m.spinner,"data-testid":"spinner"})}),t(b,{variant:"subtitleL",css:m.emptyStateHeading,children:s("loading")}),t(b,{variant:"subtitleS",css:m.typo,children:s("wait")})]}):n})},je=({data:e,children:n})=>{const{t:s}=$(void 0,{keyPrefix:"pages.salesAdvisor.notification"});return t(P,{children:e.length?n:r("div",{css:m.container,children:[t("img",{src:Te,alt:"check",css:m.image}),t(b,{variant:"subtitleL",css:m.emptyStateHeading,children:s("caughtUp")}),t(b,{variant:"subtitleS",css:m.typo,children:s("allRead")})]})})},Oe=({isError:e,children:n,refetch:s})=>{const{t:a}=$(void 0,{keyPrefix:"pages.salesAdvisor.notification"});return t(P,{children:e?r("div",{css:m.stateWrapper,children:[t("img",{src:Ae,alt:"check",css:m.image}),t(b,{variant:"subtitleL",css:m.emptyStateHeading,children:a("unavailable")}),t(b,{variant:"subtitleS",css:m.typo,children:a("unableToLoad")}),t(T,{size:"md",css:m.button,onClick:()=>s(),variant:"secondary",children:a("refresh")})]}):n})},Q=({data:e,loading:n,refetch:s,children:a,isError:o,hub:l=!1})=>{const g=!e.length||n||o;return t("div",{css:[m.primaryWrapper,l&&{height:"410px",justifyContent:g?"center":"none"}],children:t(De,{loading:n,children:t(je,{data:e,children:t(Oe,{isError:o,refetch:s,children:a})})})})},p={arrow:e=>i({fill:e.colors.common.white}),button:e=>i({height:e.spaces.xl,padding:0}),buttonIcon:e=>i({height:e.spaces.xl,width:e.spaces.xl}),contentWrapper:e=>i({display:"flex",flexDirection:"column",gap:e.spaces.xs2,justifyContent:"space-between",marginInlineStart:e.spaces.sm}),data:e=>i({color:e.colors.grey[600]}),description:i({display:"flex",flexDirection:"column"}),divider:e=>i({marginBlock:e.spaces.sm}),dot:e=>i({background:ne,borderRadius:e.borderRadius.xl2,height:e.spaces.xs3,position:"absolute",width:e.spaces.xs3}),eyeIcon:i({transform:"rotate(-180deg)"}),icon:e=>i({color:e.colors.grey[700]}),popoverContentWrapper:e=>i({background:e.colors.common.white,borderRadius:"4px",boxShadow:"0px 0px 8px 0px #0000001F",paddingBlock:"17px",paddingInline:"12px"}),primaryWrapper:i({position:"relative",width:"100%"}),readButton:e=>i({"&:hover":{borderBottom:`2px solid ${e.colors.button.tertiary.active}`,color:e.colors.button.tertiary.hoverText,marginBlockEnd:0},marginBlockEnd:0}),spacer:i({flex:1}),textEllipse:i({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",width:"355px"}),typography:e=>i({color:e.colors.grey[900]}),wrapper:i({display:"flex"})},V=({body:e,props:{triggeredAt:n,isRead:s,eventId:a},title:o,onMarkRead:l,truncateText:g})=>{const{t:x}=$(void 0,{keyPrefix:"pages.salesAdvisor.notification"}),f=w(I),{refetch:h}=ie(),[y,u]=k.useState(!1),C=v=>Re.fromISO(v).toFormat("LLL dd h:mm a");return r("div",{css:p.primaryWrapper,children:[!s&&t("div",{css:p.dot}),r("div",{css:p.wrapper,children:[r("div",{css:p.contentWrapper,children:[t(b,{variant:"subtitleS",isBold:!0,css:[p.typography,p.textEllipse],children:o}),t(b,{variant:"bodyS",css:[p.typography,g&&p.textEllipse],children:e}),t(b,{variant:"captionS",css:p.data,children:C(n)})]}),t("div",{css:p.spacer}),r(Be,{open:y,onOpenChange:u,children:[t(Pe,{asChild:!0,children:t(ee,{css:p.buttonIcon,size:"sm",children:t(de,{css:p.icon,width:30,height:24})})}),t(Ee,{side:"bottom",align:"end",css:p.popoverContentWrapper,children:r(P,{children:[t(_,{prefixIcon:s?t(ge,{css:p.eyeIcon,width:20,height:20}):t(pe,{css:p.eyeIcon,width:20,height:20}),css:p.readButton,onClick:()=>{f.markRead({eventIds:[a],read:!s}).then(()=>{l(),h()})},children:x(s?"markUnRead":"markRead")}),t($e,{css:p.arrow})]})})]})]}),t(A,{css:p.divider})]},a)},M={content:e=>i({"::-webkit-scrollbar":{backgroundColor:e.colors.grey[100],borderRadius:e.spaces.xs4,width:e.spaces.xs3},"::-webkit-scrollbar-thumb":{background:e.colors.grey[500],borderRadius:e.spaces.xs2},marginBlockEnd:e.spaces.lg,maxHeight:"410px",paddingRight:e.spaces.sm}),spinner:i({animation:`${X} 2s infinite linear`}),spinnerWrapper:i({display:"flex",justifyContent:"center"}),wrapper:i({alignItems:"center",display:"flex",flexDirection:"column"})},K=({isFullScreen:e=!1,markAllReadStatus:n,readStatus:s=null})=>{var U;const{i18n:a}=$(),o=w(I),l=k.useRef(null),[g,x]=k.useState(0),f=a.resolvedLanguage,{data:h,refetch:y,isError:u,isFetching:C}=Le({locale:f,readStatus:s}),{data:v,refetch:R,isLoading:D,isError:S,isFetching:N}=Me({locale:f,page:g,readStatus:s}),L=d=>{var B;d[0].isIntersecting&&o.getPage("infiniteScroll")<=((B=o.getPaginationMeta())==null?void 0:B.pageCount)&&!C&&y()};k.useEffect(()=>{const d={root:null,rootMargin:"0px",threshold:1},B=new IntersectionObserver(L,d);return l.current&&B.observe(l.current),()=>{l.current&&B.unobserve(l.current)}},[L]),k.useEffect(()=>{n&&R()},[n]),k.useEffect(()=>{o.emptyNotifications(),o.setPage(1,"infiniteScroll"),y()},[f]);const W=(d,B)=>{o.toggleRead(d,B),R()},j=u||!o.getNotifications().length,O=t("div",{id:"notification-data",css:[M.wrapper,M.content,j?{overflowY:"hidden"}:{overflowY:"scroll"}],children:r(Q,{data:h,isError:u,loading:!o.getNotifications().length&&C,refetch:y,hub:!0,children:[o.getNotifications().map(({...d})=>t(V,{onMarkRead:()=>{W(d.props.eventId,!d.props.isRead)},...d,truncateText:!e},d.props.eventId)),o.getNotifications().length&&C&&t("div",{css:M.spinnerWrapper,children:t("img",{src:te,height:30,width:30,css:M.spinner,"data-testid":"spinner"})}),t("div",{ref:l})]})}),H=t("div",{id:"notification-data",css:M.wrapper,children:r(Q,{data:v,loading:D||N,isError:S,refetch:R,children:[v.map(({...d})=>t(V,{truncateText:!e,onMarkRead:()=>{W(d.props.eventId,!d.props.isRead)},...d},d.props.eventId)),t(Se,{totalPageCount:((U=o==null?void 0:o.getPaginationMeta())==null?void 0:U.pageCount)??1,onSelectPage:d=>{x(d),o.setPage(d,"pageBased")},currentPage:g})]})});return t(P,{children:e?H:O})},c={actions:e=>i({alignItems:"center",display:"flex",gap:e.spaces.md}),button:e=>i({...e.typography.captionM,height:e.spaces.xl4,width:"fit-content"}),buttonIcon:e=>i({height:e.spaces.xl,marginBlockStart:e.spaces.xs3,width:e.spaces.xl}),buttonWrapper:i({display:"flex",justifyContent:"center",width:"100%"}),clearIcon:i({cursor:"pointer"}),dialogBackButton:e=>i({...e.typography.captionM,marginBlockEnd:e.spaces.xs3,width:"100%"}),dialogConfirmButton:e=>i({...e.typography.captionM,marginBlockEnd:e.spaces.md,textTransform:"uppercase",width:"100%"}),dialogHeading:i({marginBlockEnd:"44px"}),dialogRoot:e=>i({alignItems:"center",display:"flex",paddingBlock:e.spaces.xl3,paddingInline:e.spaces.lg,width:"500px"}),eyeIcon:i({transform:"rotate(-180deg)"}),icon:i({color:oe,position:"absolute",top:"4px"}),iconWrapper:e=>i({height:e.spaces.lg,position:"relative",width:e.spaces.lg}),readButton:e=>i({...e.typography.captionM,"&:hover":{borderBottom:`2px solid ${e.colors.button.tertiary.active}`,color:e.colors.button.tertiary.hoverText,marginBlockEnd:-2},height:e.spaces.lg,marginBlockEnd:0,marginBlockStart:e.spaces.xs4}),search:e=>i({...e.typography.bodyS,background:e.colors.common.white,boxShadow:e.shadows.md1,height:"44px",marginBlockEnd:e.spaces.md1,marginBlockStart:e.spaces.lg}),searchIcon:e=>i({marginRight:e.spaces.sm}),searchLayout:i({display:"flex",flexDirection:"column"}),tabContent:e=>i({flexGrow:1,outline:"none",paddingTop:e.spaces.md}),tabList:i({"& button":{background:"transparent",border:"none"},display:"flex",flexShrink:0}),tabRoot:i({display:"flex",flexDirection:"column",marginTop:"-16px",width:"100%"}),tabTrigger:e=>i({"&[data-state=active]":{borderBottomWidth:"2px",boxShadow:"inset 0 -1px 0 0 currentColor, 0 .05px 0 0 currentColor",color:e.colors.primary.main},alignItems:"center",color:e.colors.grey[500],cursor:"pointer",display:"flex",fontSize:"16px",fontWeight:e.typography.fontWeightBold,height:"45px",justifyContent:"center",lineHeight:"18px",marginRight:e.spaces.sm,paddingInline:"8px",textTransform:"uppercase",userSelect:"none"}),triggerWrapper:e=>i({display:"flex",justifyContent:"space-between",paddingRight:e.spaces.lg,width:"100%"})},gt=({setCurrentState:e,isFullScreen:n=!1})=>{const[s]=Y("NotificationSearch"),a=se(),{t:o,i18n:l}=$(void 0,{keyPrefix:"pages.salesAdvisor.notification"}),g=ae(),[x]=Y("NotificationPreferences"),[f,h]=k.useState(!1),y=w(I),{refetch:u}=ie(),C=l.resolvedLanguage==="ar",{isError:v,mutate:R}=Ne(),[D,S]=k.useState(!1),[N,L]=k.useState(""),W=()=>L(""),j=async H=>{L(H.target.value)},O=()=>t(P,{children:N.length>0&&t(me,{onClick:W,css:c.clearIcon,size:20})});return t(Ce,{dir:C?"rtl":"ltr",children:r(we,{css:c.tabRoot,defaultValue:"all",children:[r("div",{css:c.searchLayout,children:[t(Ie,{trigger:v,description:o("readError"),top:n?"-40":"20"}),r("div",{css:c.triggerWrapper,children:[r(ke,{css:c.tabList,"aria-label":"Manage your account",children:[t(q,{css:c.tabTrigger,value:"all",children:o("all")}),t(q,{css:c.tabTrigger,value:"un-read",children:o("unRead")})]}),r("div",{css:c.actions,children:[t(_,{prefixIcon:t(fe,{css:c.eyeIcon,width:n?24:18,height:n?24:18}),css:[c.readButton,n&&{...a.typography.captionM}],onClick:()=>S(!0),children:o("markAllRead")}),!n&&x&&t(ee,{css:c.buttonIcon,size:"sm",children:t(he,{onClick:()=>e&&e("preferences"),css:c.icon,width:18,height:24})}),r(re,{open:D,onClose:()=>S(!1),children:[t(ce,{onClick:()=>S(!1)}),r(le,{css:c.dialogRoot,dismissOnOutsideClick:!1,children:[t(b,{css:c.dialogHeading,variant:"bodyL",isBold:!0,children:`${o("markAllRead")}?`}),t(T,{css:c.dialogConfirmButton,onClick:async()=>{await R(),y.toggleAllRead(),S(!1),h(!0),u()},variant:"primary",children:o("confirm")}),t(T,{css:c.dialogBackButton,onClick:()=>S(!1),variant:"secondary",children:o("goBack")})]})]})]})]}),n&&s&&t(xe,{prefix:t(ue,{size:16,css:c.searchIcon}),value:N,onChange:j,placeholder:"Search",suffix:O(),css:c.search})]}),t(J,{css:c.tabContent,value:"all",children:t(K,{isFullScreen:n,markAllReadStatus:f})}),t(J,{css:c.tabContent,value:"un-read",children:t(K,{isFullScreen:n,markAllReadStatus:f,readStatus:"false"})}),!n&&t("div",{css:c.buttonWrapper,children:t(T,{size:"lg",variant:"secondary",css:c.button,onClick:()=>g(ye(be.salesAdvisorNotificationList)),children:o("viewAll")})})]})})};i({width:"100%"}),i({alignItems:"center",display:"flex",flexDirection:"column",height:"156px",justifyContent:"center",marginBlock:"80px"});export{Te as C,Z as M,pt as N,gt as a,Le as b,Me as c,ie as u};
