1import{v4 as xe,dE as he,f2 as Ne,fW as ge,v5 as be,em as X,hI as ye,de as Ie,dQ as je,ff as Ae,hF as Te,eo as we,v6 as Ee,sN as ie,bG as q,bJ as ne,eK as Ce,C as E,j as t,c as K,eL as oe,eM as re,eN as ce,eP as le,a1 as ve,Y as R,cJ as Se,aM as ke,er as Oe,I as k,aw as Q,aG as V,x,om as Re,rU as De,fd as Fe,fe as J,$ as _e,a0 as Me,a5 as Ke,a6 as Pe,tu as Le,oE as $e,bc as de,bq as Be,dG as Ue,tt as Ge,f as Ve,v7 as Ye,v8 as We,K as ze,eT as He,se as ue,gZ as z,g_ as B,rG as Xe,rH as qe,rI as Y,rJ as Qe,eb as Je,dT as Ze,bC as et,dg as tt,v9 as st,b8 as at,oa as it,va as nt,vb as ot,Z as rt}from"./app-6As101UE.js";import{h as ct}from"./feature-bookkeeping-wIj2I1Ll.js";import{a as lt}from"./feature-invoicing-D4JB9_1C.js";import{u as dt,a as ut}from"./setAtPassword.generated-D2KzVT4y.js";import"./bookkeeping-rules-gHnoycun.js";import"./feature-auth-B1L7RaGf.js";import"./accountant-invite-token-Bo8fib0o.js";import"./recharts-Drl9pjbz.js";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},s=new e.Error().stack;s&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[s]="61503711-b0b0-4eca-83e4-f5fbf03a45d5",e._sentryDebugIdIdentifier="sentry-dbid-61503711-b0b0-4eca-83e4-f5fbf03a45d5")}catch{}})();const _={DIVERGENCIA:"divergencia",ALERT:"alert",NOTIFICATION:"notification",COMMUNICATION:"communication",MESSAGE:"message"},ft={[_.DIVERGENCIA]:{labelKey:"atNotifications.kind.divergencia.title",descKey:"atNotifications.kind.divergencia.desc",Icon:X,iconWrap:"bg-[#FFC850]/10",iconColor:"text-[#E39C00]",badge:"bg-[#FFC850]/10 text-[#B8860B]"},[_.ALERT]:{labelKey:"atNotifications.kind.alert.title",descKey:"atNotifications.kind.alert.desc",Icon:ie,iconWrap:"bg-[#438BFA]/10",iconColor:"text-[#438BFA]",badge:"bg-[#438BFA]/10 text-[#2b6fd6]"},[_.NOTIFICATION]:{labelKey:"atNotifications.kind.notification.title",descKey:"atNotifications.kind.notification.desc",Icon:Ee,iconWrap:"bg-[#E03652]/10",iconColor:"text-[#E03652]",badge:"bg-[#E03652]/10 text-[#c22b45]"},[_.COMMUNICATION]:{labelKey:"atNotifications.kind.communication.title",descKey:"atNotifications.kind.communication.desc",Icon:we,iconWrap:"bg-[#8B5CF6]/10",iconColor:"text-[#8B5CF6]",badge:"bg-[#8B5CF6]/10 text-[#7143d1]"},[_.MESSAGE]:{labelKey:"atNotifications.kind.message.title",descKey:"atNotifications.kind.message.desc",Icon:Te,iconWrap:"bg-[#34C759]/10",iconColor:"text-[#2a9d48]",badge:"bg-[#34C759]/10 text-[#22833c]"}},mt={labelKey:"at.notifications.title",descKey:"",Icon:X,iconWrap:"bg-[#F7F6F4]",iconColor:"text-muted-foreground",badge:"bg-[#F7F6F4] text-muted-foreground"},pt=2160*60*60*1e3,xt=10080*60*1e3,b={IUC:"iuc",IRS:"irs",IVA:"iva",IMI:"imi",FINE:"fine",DIVERGENCIA:"divergencia",EFATURA:"efatura",PAYMENT:"payment"},ht=[{group:b.IUC,labelKey:"atNotifications.topic.iuc",Icon:xe},{group:b.IRS,labelKey:"atNotifications.topic.irs",Icon:he},{group:b.IVA,labelKey:"atNotifications.topic.iva",Icon:Ne},{group:b.IMI,labelKey:"atNotifications.topic.imi",Icon:ge},{group:b.FINE,labelKey:"atNotifications.topic.fine",Icon:be},{group:b.DIVERGENCIA,labelKey:"atNotifications.topic.divergencia",Icon:X},{group:b.EFATURA,labelKey:"atNotifications.topic.efatura",Icon:ye},{group:b.PAYMENT,labelKey:"atNotifications.topic.payment",Icon:Ie}],Nt={IUC:b.IUC,DECLARATION_STATUS:b.IRS,IRS_PAYMENT:b.IRS,IRS_ANALYSIS:b.IRS,IVA:b.IVA,IMI:b.IMI,FINE:b.FINE,DIVERGENCIA:b.DIVERGENCIA,EFATURA:b.EFATURA,PAYMENT:b.PAYMENT,OTHER:b.PAYMENT},gt=new Set(["DIVERGENCIA_RESOLVED","INFO_NOTICE","PAYMENT_PLAN","IVA_AUTOMATIC","IRC_ASSESSMENT"]),H=new Set(["PHISHING_WARNING","PORTAL_ADHESION_NUDGE","DEBITO_DIRETO_MARKETING","ACTIVITY_WELCOME","INBOX_POINTER"]),U={key:"info",labelKey:"atNotifications.section.info",Icon:je},G={key:"other",labelKey:"atNotifications.section.other",Icon:Ae},bt={AT_INVALID_CREDENTIALS:"atNotifications.access.errorWrongPassword",AT_OTP_REQUIRED:"atNotifications.access.errorOtp",AT_MAIN_PASSWORD_MISSING:"atNotifications.access.errorNoPassword"},yt="atNotifications.access.errorGeneric",It=e=>ft[e]??mt;function D(e){if(!e)return null;if(typeof e=="string"){const a=e.match(/^(\d{4})-(\d{2})-(\d{2})$/);if(a){const n=new Date(Number(a[1]),Number(a[2])-1,Number(a[3]));return Number.isNaN(n.getTime())?null:n}const i=new Date(e.replace(" ","T"));return Number.isNaN(i.getTime())?null:i}const s=new Date(e);return Number.isNaN(s.getTime())?null:s}function P(e){var s;return((s=D(e.date)??D(e.createdAt))==null?void 0:s.getTime())??0}function jt(e){return[...e].sort((s,a)=>P(a)-P(s))}function At(e){const s=D(e);
1return s?s.toLocaleString(q.language,{dateStyle:"short",timeStyle:"short"}):e?String(e):""}function fe(e){const s=D(e);return s?ne(s).locale(q.language).format("D MMMM YYYY"):e?String(e):""}function me(e){const s=D(e);return s?ne(s).locale(q.language).format("D MMMM YYYY"):e?String(e):""}function Tt(e,s=Date.now()){const a=D(e);return a?a.getTime()-s<xt:!1}function wt(e,s=Date.now()){return!!e.read&&P(e)<s-pt}const M=e=>e&&bt[e]||yt;function Et(e){if(!e)return null;const s=e.match(/^(\d{4})(\d{2})([TM])?$/);if(!s)return e;const[,a,i,n]=s;return n==="T"?`${a} · T${i}`:`${i}/${a}`}function Ct(e){const s=[e.matricula,e.amount!=null?Ce(e.amount):null,Et(e.fiscalPeriod),e.infraction].filter(a=>!!a);return s.length?s.join(" · "):null}function pe(e,s){const a=e.computedDeadline??e.deadline??null,i=Ct(e),n=e.read?[]:[e.dedupKey];if(!e.noticeType)return{notification:e,title:e.title??"",summary:e.body||null,action:null,deadline:a,unreadDedupKeys:n};const r=`atNotifications.notice.${e.noticeType}`,m=s(`${r}.action`);return{notification:e,title:s(`${r}.title`),summary:i,action:m||null,deadline:a,unreadDedupKeys:n}}function Z(e){const s=`unique:${e.dedupKey}`;if(e.processNumber)return`proc:${e.processNumber}`;if(!e.noticeType)return s;const a=e.submittedAt&&/\d{2}:\d{2}/.test(e.submittedAt)?e.submittedAt:null,i=[e.matricula,e.amount,e.fiscalPeriod,e.infraction,a].filter(r=>r!=null&&r!=="");if(!i.length)return s;const n=e.computedDeadline??e.deadline??"";return[e.noticeType,...i,n].join("|")}function vt(e,s){const a=e.escalation??0,i=s.escalation??0;return a!==i?a>i:P(e)>P(s)}function St(e,s,a={}){var I;const{includeOutdated:i=!1,includeDuplicates:n=!1,nowMs:r=Date.now()}=a,m=new Map,d=new Map;for(const f of e){if(f.noticeType&&H.has(f.noticeType))continue;const c=Z(f);if(!f.read){const C=d.get(c);C?C.push(f.dedupKey):d.set(c,[f.dedupKey])}const y=m.get(c);(!y||vt(f,y))&&m.set(c,f)}const N=new Map,o=[],l=[];let p=0,u=0;for(const f of e){const c=f.noticeType;if(c&&H.has(c))continue;const y=Z(f),C=((I=m.get(y))==null?void 0:I.dedupKey)===f.dedupKey;if(!C&&(u+=1,!n)||wt(f,r)&&(p+=1,!i))continue;const j=d.get(y)??[],g=C&&j.length?{...f,read:!1}:f,A=pe(g,s);if(C&&(A.unreadDedupKeys=j),!c){l.push(A);continue}if(gt.has(c)){o.push(A);continue}const T=Nt[f.topic];if(!T){o.push(A);continue}const v=N.get(T);v?v.push(A):N.set(T,[A])}return{groups:ht.map(f=>({...f,rows:N.get(f.group)??[]})).filter(f=>f.rows.length>0),info:o,other:l,outdatedCount:p,duplicateCount:u}}function W(e){const s=i=>i.some(n=>!n.notification.read),a=e.groups.map(i=>({key:i.group,hasUnread:s(i.rows)}));return e.info.length&&a.push({key:U.key,hasUnread:s(e.info)}),e.other.length&&a.push({key:G.key,hasUnread:s(e.other)}),a}const kt=({kind:e})=>{const{t:s}=E(),a=It(e),{Icon:i}=a,n=a.descKey?s(a.descKey):"",r=t.jsxs("span",{className:K("inline-flex w-fit cursor-help items-center gap-1.5 whitespace-nowrap rounded-full px-2.5 py-1 text-xs font-medium",a.badge),children:[t.jsx(i,{className:K("h-3.5 w-3.5",a.iconColor)}),s(a.labelKey)]});return n?t.jsx(oe,{delayDuration:150,children:t.jsxs(re,{children:[t.jsx(ce,{asChild:!0,children:r}),t.jsx(le,{side:"top",className:"max-w-xs",children:n})]})}):r},ee=2500,Ot=e=>{const s=[e.title,e.description||e.body].filter(Boolean).join(". ");return s.length<=ee?s:`${s.slice(0,ee-1)}â¦`},Rt=e=>{const s=[`kind: ${e.kind}`,e.noticeType?`noticeType: ${e.noticeType}`:null,`topic: ${e.topic}`,`severity: ${e.severity}`].filter(Boolean).join(", "),a=[e.date?`portal date: ${e.date}`:null,e.deadline?`portal deadline: ${e.deadline}`:null,e.computedDeadline?`estimated statutory deadline: ${e.computedDeadline}`:null].filter(Boolean).join(", "),i=[e.amount!=null?`amount: ${e.amount}`:null,e.fiscalPeriod?`fiscal period: ${e.fiscalPeriod}`:null,e.matricula?`vehicle plate: ${e.matricula}`:null,e.processNumber?`process number: ${e.processNumber}`:null,e.infraction?`infraction: ${e.infraction}`:null,e.referencia?`payment reference: ${e.referencia}`:null,e.submittedAt?`refers to the filing submitted at: ${e.submittedAt}`:null].filter(Boolean).join(", "),n=[e.status?`status: ${e.status}`:null,e.finePaid?"the fine appears already paid (matched a settled payment)":null,e.dismissed?"the user marked it resolved":null].filter(
1Boolean).join("; ");return[`AT notification the user opened on the AT-notifications page (dedupKey: ${e.dedupKey}).`,s?`Classification: ${s}`:null,a?`Dates: ${a}`:null,i?`Parsed facts: ${i}`:null,n?`State: ${n}`:null,"Verify it with query_at_notifications (use the dedupKey) before answering."].filter(Boolean).join(` 2`)},Dt=({notification:e,open:s,onOpenChange:a})=>{const{t:i}=E(),n=ve(),r=e?pe(e,i):null,m=()=>{e&&(k.atNotifications.askedAi({noticeType:e.noticeType}),lt({text:i("welcome.audit.askAi.message",{text:Ot(e)}),context:Rt(e),newConversation:!0}),a(!1),n("/ai-accountant"))},d=()=>{k.atNotifications.openedPortal({noticeType:e==null?void 0:e.noticeType})},N=e&&r?t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex gap-2",children:[r.deadline&&t.jsxs("div",{className:"min-w-0 flex-1 rounded-xl bg-[#F7F6F4] px-3 py-2",children:[t.jsx("span",{className:"block text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:i("atNotifications.table.deadline")}),t.jsx("span",{className:"block truncate text-sm font-semibold text-[#E03652]",children:me(r.deadline)})]}),t.jsxs("div",{className:"min-w-0 flex-1 rounded-xl bg-[#F7F6F4] px-3 py-2",children:[t.jsx("span",{className:"block text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:i("atNotifications.table.date")}),t.jsx("span",{className:"block truncate text-sm font-semibold text-foreground",children:fe(e.date??e.createdAt)})]})]}),t.jsx(R,{variant:"fizPrime",fullWidth:!0,leftSection:t.jsx(Se,{className:"h-4 w-4"}),onClick:m,children:i("welcome.audit.askAi")})]}):void 0;return t.jsx(ke,{open:s,onOpenChange:a,title:i("atNotifications.detail.title"),footer:N,children:e&&r&&t.jsxs("div",{className:"space-y-4",children:[t.jsx(kt,{kind:e.kind}),t.jsxs("div",{children:[t.jsx("h3",{className:"text-lg font-semibold text-foreground",children:r.title}),e.title&&e.title!==r.title&&t.jsx("p",{className:"mt-0.5 text-sm text-muted-foreground",children:e.title}),r.summary&&t.jsx("p",{className:"mt-0.5 text-xs text-muted-foreground",children:r.summary})]}),r.action&&t.jsxs("div",{className:"rounded-xl border border-[#FFC850]/40 bg-[#fff9e1] px-3 py-2.5",children:[t.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wide text-[#B8860B]",children:i("atNotifications.table.action")}),t.jsx("p",{className:"mt-0.5 text-sm text-foreground",children:r.action})]}),t.jsxs("div",{children:[t.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:i("atNotifications.detail.description")}),t.jsx("p",{className:"mt-1 whitespace-pre-line text-sm text-foreground",children:e.description||e.body||i("atNotifications.detail.noDescription")})]}),e.status&&t.jsxs("div",{className:"rounded-xl bg-[#F7F6F4] px-3 py-2",children:[t.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:i("atNotifications.table.status")}),t.jsx("p",{className:"mt-0.5 text-sm font-semibold text-foreground",children:e.status})]}),e.link&&t.jsx("a",{href:e.link,target:"_blank",rel:"noopener noreferrer",className:"block",onClick:d,children:t.jsx(R,{variant:"fizSecondary",fullWidth:!0,leftSection:t.jsx(Oe,{className:"h-4 w-4"}),children:i("atNotifications.detail.openPortal")})})]})})},Ft=2e3,_t=960*1e3,Mt=({onLoaded:e}={})=>{const s=Q(V),[a,i]=x.useState(null),[n,r]=x.useState(""),[m,d]=x.useState(!1),N=x.useRef(e);N.current=e;const[o]=Re(),l=De(),{data:p,error:u,stopPolling:S}=Fe({variables:{taskId:a??""},skip:!a,pollInterval:Ft,fetchPolicy:"network-only",notifyOnNetworkStatusChange:!0}),I=x.useRef(S);I.current=S;const f=x.useRef(l.resetOtp);f.current=l.resetOtp;const c=x.useCallback(g=>{I.current(),i(null),f.current(),r(g)},[]);x.useEffect(()=>{var v,O;const g=p==null?void 0:p.backgroundTaskData;if(!a||!g)return;const A=g.status===J.Completed,T=g.status===J.Failed;if(!(!A&&!T)){if(T||g.error){c(M((v=g.error)==null?void 0:v.type));return}c(""),(O=N.current)==null||O.call(N)}},[p,a,c]),x.useEffect(()=>{!u||!a||c(M(void 0))},[u,a,c]),x.useEffect(()=>{if(!a)return;const g=setTimeout(()=>c(M(void 0)),_t);return()=>clearTimeout(g)},[a,c]);const y=x.useRef(!1),C=x.useCallback(async()=>{var A,T,v,O;if(!(s!=null&&s.id)||a||y.current)return;y.current=!0,r("");const g=`${s.id}-atnotif-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;l.startSession(g);try{const L=await o({variables:{id:s.id,notificationsOnly:!0,sessionId:g}}),$=(T=(A=L.data)==null?void 0:A.syncAtData)==null?void 0:T.taskId;if($){const F=(O=(v=L.data)==null?void 0:v.syncAtData)==null?void 0:O.sessionId;F&&F!==g&&l.startSession(F),i($)}else c(M(void 0))}catch{c(M(void 0))}finally{y.current=!1}},[s==null?void 0:s.id,a,l,o,c]),j=x.useCallback(async g=>{d(!0);try{return await l.submitOtp(g)}finally{d(!1)}},[l]);return{start:C,isLoading:!!a,showOtpField:l.showOtpField,submitOtp:j,isSubmittingOtp:m,errorKey:n}},Kt=e=>_e().shape({password:Me().required(e("validation.required"))}),te=()=>{},Pt=({onSubmitPassword:e,isLoading:s})=>{const{t:a}=E();return t.jsx(Ke,{initialValues:{password:""},validationSchema:Kt(a),onSubmit:async({password:i})=>e(i),children:({isSubmitting:i})=>t.jsxs(Pe,{className:"flex max-w-xl flex-col gap-3 sm:flex-row sm:items-start",children:[t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx(Le,{fieldName:"password",label:a("atCredentials.yourPassword"),placeholder:a("atCredentials.passwordPlaceholder"),saved:!1,editing:!1,onStartEditing:te,onCancelEditing:te})}),t.jsx(R,{type:"submit",variant:"fizPrime",size:"medium",disabled:s||i,className:"w-full sm:w-auto",children:a("atNotifications.access.connectAction")})]})})},Lt=({isLoading:e,showOtpField:s,submitOtp:a,isSubmittingOtp:i,errorKey:n})=>{const{t:r}=E();return!e&&!n?null:t.jsxs("div",{className:"mt-4 space-y-3",children:[e&&s&&t.jsx($e,{otpFor:"A",onSubmit:a,isSubmitting:i}),e&&!s&&t.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[t.jsx(de,{color:"#E39C00",size:16}),r("atNotifications.access.loading")]}),!e&&n&&t.jsx("p",{className:"text-sm text-[#E03652]",children:r(n)})]})},$t=({onLoaded:e})=>{const{t:s}=E(),a=Q(V),i=(a==null?void 0:a.taxPayerNumber)||"",{data:n,refetch:r}
2=dt({variables:{nif:i},skip:!i,fetchPolicy:"cache-and-network"}),[m]=ut(),d=Mt({onLoaded:()=>{e(),r()}});x.useEffect(()=>{d.errorKey&&r()},[d.errorKey,r]);const N=n==null?void 0:n.atPasswordStatus;if(!i||!N)return null;const o=!N.exists||N.verified===!1;if(!o&&N.otpRequired!==!0)return null;const l=async p=>{try{await m({variables:{input:{kind:Ge.Main,nif:i,password:p}}}),await d.start()}catch(u){Ve.error(u instanceof Error?u.message:s("atCredentials.passwordSaveFailed"),{position:"top-right"})}};return t.jsx("div",{className:"rounded-2xl border border-[#FFE09B] bg-[#fff9e1]/50 p-4 sm:p-5",children:t.jsxs("div",{className:"flex items-start gap-3",children:[t.jsx("div",{className:"rounded-xl bg-white p-2 shadow-sm",children:t.jsx(Be,{className:"h-5 w-5 text-[#E39C00]"})}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("p",{className:"text-sm font-semibold text-foreground",children:s(o?"atNotifications.access.connectTitle":"atNotifications.access.otpTitle")}),t.jsx("p",{className:"mt-0.5 text-sm text-muted-foreground",children:s(o?"atNotifications.access.connectDesc":"atNotifications.access.otpDesc")}),o?t.jsx("div",{className:"mt-4",children:t.jsx(Pt,{onSubmitPassword:l,isLoading:d.isLoading})}):!d.isLoading&&t.jsx("div",{className:"mt-4",children:t.jsx(R,{variant:"fizPrime",size:"medium",leftSection:t.jsx(Ue,{className:"h-4 w-4"}),onClick:()=>void d.start(),className:"w-full sm:w-auto",children:s("atNotifications.access.loadAction")})}),t.jsx(Lt,{isLoading:d.isLoading,showOtpField:d.showOtpField,submitOtp:d.submitOtp,isSubmittingOtp:d.isSubmittingOtp,errorKey:d.errorKey})]})]})})},se=({variant:e})=>{const{t:s}=E();return e==="empty"?t.jsxs("div",{className:"flex flex-col items-center justify-center rounded-2xl border border-border bg-card px-6 py-12 text-center",children:[t.jsx("div",{className:"rounded-2xl bg-[#F7F6F4] p-3",children:t.jsx(Ye,{className:"h-6 w-6 text-muted-foreground"})}),t.jsx("h3",{className:"mt-3 text-base font-semibold text-foreground",children:s("atNotifications.empty.title")}),t.jsx("p",{className:"mt-1 max-w-sm text-sm text-muted-foreground",children:s("atNotifications.empty.desc")})]}):t.jsxs("div",{className:"flex flex-col items-center justify-center rounded-2xl border border-border bg-card px-6 py-12 text-center",children:[t.jsx("div",{className:"rounded-2xl bg-[#FFC850]/10 p-3",children:t.jsx(We,{className:"h-6 w-6 text-[#E39C00]"})}),t.jsx("h3",{className:"mt-3 text-base font-semibold text-foreground",children:s("atNotifications.empty.connectTitle")}),t.jsx("p",{className:"mt-1 max-w-sm text-sm text-muted-foreground",children:s("atNotifications.empty.connectDesc")}),t.jsx(ze,{to:"/settings/at",className:"mt-4",children:t.jsx(R,{variant:"fizPrime",size:"small",leftSection:t.jsx(He,{className:"h-4 w-4"}),children:s("atNotifications.empty.connectAction")})})]})},Bt=()=>{const{t:e}=E();return t.jsx("div",{className:"overflow-hidden rounded-3xl border border-[#FFE09B] bg-gradient-to-br from-[#fff9e1] via-[#fff4d6] to-white p-6 sm:p-8",children:t.jsxs("div",{className:"flex items-start gap-4",children:[t.jsx("div",{className:"hidden rounded-2xl bg-white/70 p-3 shadow-sm sm:block",children:t.jsx(ue,{className:"h-7 w-7 text-[#E39C00]"})}),t.jsxs("div",{className:"flex-1",children:[t.jsx("h2",{className:"text-xl font-bold text-foreground sm:text-2xl",children:e("atNotifications.hero.title")}),t.jsx("p",{className:"mt-1 max-w-2xl text-sm text-muted-foreground sm:text-base",children:e("atNotifications.hero.subtitle")})]})]})})},Ut=({deadline:e})=>t.jsxs("span",{className:K("inline-flex w-fit items-center gap-1 whitespace-nowrap rounded-full px-2.5 py-1 text-xs font-medium",Tt(e)?"bg-[#E03652]/10 text-[#E03652]":"bg-[#FFC850]/20 text-[#B8860B]"),children:[t.jsx(ie,{className:"h-3.5 w-3.5"}),me(e)]}),Gt=({row:e,onRowClick:s})=>{const{t:a}=E(),{notification:i}=e;return t.jsxs(z,{role:"button",tabIndex:0,"aria-label":e.title||void 0,onClick:()=>s(e),onKeyDown:n=>{(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),s(e))},className:K("cursor-pointer border-border focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[#FFC850]",!i.read&&"bg-[#fff9e1]/60"),children:[t.jsx(B,{className:"py-3 pl-16 pr-4 align-top",children:t.jsxs("div",{className:"min-w-0",children:[t.jsxs("p",{className:K("text-foreground",i.read?"font-normal":"font-medium"),children:[!i.read&&t.jsxs("span",{className:"sr-only",children:[a("atNotifications.unread")," "]}),e.title]}),e.summary&&t.jsx("p",{className:"mt-0.5 line-clamp-2 text-sm text-muted-foreground",children:e.summary}),e.deadline&&t.jsx("div",{className:"mt-1.5",children:t.jsx(Ut,{deadline:e.deadline})})]})}),t.jsx(B,{className:"px-4 py-3 align-top",children:e.action?t.jsx("span",{className:"text-sm text-foreground",children:e.action}):t.jsx("span",{className:"text-muted-foreground",children:"â"})}),t.jsx(B,{className:"hidden whitespace-nowrap px-4 py-3 align-top text-sm text-muted-foreground sm:table-cell",children:fe(i.date??i.createdAt)})]})},Vt=3,Yt=({sections:e,onRowClick:s})=>{const{t:a}=E(),[i,n]=x.useState(()=>new Set(W(e).filter(o=>o.hasUnread).map(o=>o.key))),r=x.useRef(null);
2r.current===null&&(r.current=new Set(W(e).map(o=>o.key))),x.useEffect(()=>{const o=W(e).filter(l=>!r.current.has(l.key));o.length&&n(l=>{const p=new Set(l);for(const u of o)r.current.add(u.key),u.hasUnread&&p.add(u.key);return p})},[e]);const m=[...e.groups.map(o=>({key:o.group,label:a(o.labelKey),Icon:o.Icon,rows:o.rows})),...e.info.length?[{key:U.key,label:a(U.labelKey),Icon:U.Icon,rows:e.info}]:[],...e.other.length?[{key:G.key,label:a(G.labelKey),Icon:G.Icon,rows:e.other}]:[]],d=o=>n(l=>{const p=new Set(l);return p.has(o)?p.delete(o):p.add(o),p}),N=m.some(({key:o})=>i.has(o));return t.jsx("div",{className:"overflow-hidden rounded-2xl border border-border bg-card",children:t.jsxs(Xe,{children:[t.jsx(qe,{children:t.jsxs(z,{className:"border-border hover:bg-transparent",children:[t.jsx(Y,{className:"py-3 pl-16 pr-4",children:a("atNotifications.table.notification")}),N&&t.jsxs(t.Fragment,{children:[t.jsx(Y,{className:"px-4 py-3",children:a("atNotifications.table.action")}),t.jsx(Y,{className:"hidden px-4 py-3 sm:table-cell",children:a("atNotifications.table.date")})]})]})}),t.jsx(Qe,{children:m.map(({key:o,label:l,Icon:p,rows:u})=>{const S=i.has(o),I=u.filter(c=>!c.notification.read).length,f=S?Je:Ze;return t.jsxs(x.Fragment,{children:[t.jsx(z,{role:"button",tabIndex:0,"aria-expanded":S,onClick:()=>d(o),onKeyDown:c=>{(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),d(o))},className:"cursor-pointer border-border bg-[#EFECE6] hover:bg-[#E7E3DC] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[#FFC850]",children:t.jsx(B,{colSpan:Vt,className:"px-4 py-2.5",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(f,{className:"h-4 w-4 text-muted-foreground"}),t.jsx(p,{className:"h-4 w-4 text-[#E39C00]"}),t.jsx("span",{className:"text-sm font-semibold text-foreground",children:l}),t.jsxs("span",{className:"text-sm text-muted-foreground",children:["(",u.length,")"]}),I>0&&t.jsx(oe,{delayDuration:150,children:t.jsxs(re,{children:[t.jsx(ce,{asChild:!0,children:t.jsxs("span",{className:"ml-1 inline-flex cursor-help items-center gap-1 rounded-full bg-bright-red/10 px-2 py-0.5 text-xs font-medium text-bright-red","aria-label":a("atNotifications.unreadInSection",{count:I}),children:[t.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-bright-red"}),I]})}),t.jsx(le,{side:"top",children:a("atNotifications.unreadInSection",{count:I})})]})})]})})}),S&&u.map(c=>t.jsx(Gt,{row:c,onRowClick:s},c.notification.dedupKey))]},o)})})]})})},ae=({label:e,checked:s,onChange:a})=>t.jsxs("label",{className:"flex cursor-pointer select-none items-center gap-2 text-sm text-muted-foreground",children:[t.jsx(et,{checked:s,onCheckedChange:i=>a(i===!0)}),e]}),Wt=({isRefreshing:e,refreshedAt:s,canRefresh:a,onRefresh:i,unreadCount:n,onMarkAllRead:r,outdatedCount:m,showOutdated:d,onToggleOutdated:N,duplicateCount:o,showDuplicates:l,onToggleDuplicates:p})=>{const{t:u}=E();return t.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[t.jsx("div",{className:"flex min-w-0 items-center gap-2 text-sm text-muted-foreground",children:e?t.jsxs(t.Fragment,{children:[t.jsx(de,{color:"#E39C00",size:16}),t.jsx("span",{children:u("atNotifications.refreshing")})]}):t.jsxs(t.Fragment,{children:[s&&t.jsx("span",{className:"truncate",children:u("atNotifications.lastRefreshed",{time:At(s)})}),a&&t.jsx(R,{type:"button",variant:"neutralGhost",size:"small",className:"!h-7 !w-7 flex-shrink-0 !p-0",onClick:i,"aria-label":u("atNotifications.refreshNow"),title:u("atNotifications.refreshNow"),children:t.jsx(tt,{className:"h-4 w-4"})})]})}),t.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:gap-4",children:[(o>0||m>0)&&t.jsxs("div",{className:"flex flex-wrap items-center gap-x-5 gap-y-2",children:[o>0&&t.jsx(ae,{label:u("atNotifications.showDuplicates",{count:o}),checked:l,onChange:p}),m>0&&t.jsx(ae,{label:u("atNotifications.showOutdated",{count:m}),checked:d,onChange:N})]}),n>0&&t.jsx(R,{variant:"neutralSecondary",size:"small",className:"w-full sm:w-auto",onClick:r,children:u("at.notifications.markAllRead")}
2)]})]})},zt=()=>{const{t:e}=E(),s=Q(V),[a]=st(),[i]=at({fetchPolicy:"network-only",onCompleted:h=>{h!=null&&h.tenant&&V(h.tenant)}}),[n,r]=x.useState(null),{data:m,refetch:d}=it({variables:{id:(s==null?void 0:s.id)??""},skip:!(s!=null&&s.id),fetchPolicy:"cache-and-network"}),{isRefreshing:N,refresh:o}=nt({maxAgeMs:ot,onRefreshed:()=>{s!=null&&s.id&&d()}}),l=x.useMemo(()=>jt((m==null?void 0:m.atNotifications)??[]),[m==null?void 0:m.atNotifications]),p=l.filter(h=>!h.read&&!(h.noticeType&&H.has(h.noticeType))).length,[u,S]=x.useState(!1),[I,f]=x.useState(!1),c=x.useRef(!1);x.useEffect(()=>{c.current||!m||(c.current=!0,k.atNotifications.pageViewed({total:l.length,unread:p}))},[m,l.length,p]);const y=x.useMemo(()=>St(l,e,{includeOutdated:u,includeDuplicates:I}),[l,e,u,I]),C=y.groups.length>0||y.info.length>0||y.other.length>0,j=s==null?void 0:s.atSummary,g=!l.length&&!(j!=null&&j.connected);ct({title:e("atNotifications.title"),icon:t.jsx("div",{className:"rounded-full bg-[#FFC850]/10 p-1.5",children:t.jsx(ue,{className:"h-5 w-5 text-[#FFC850]"})})});const A=async h=>{if(!(!(s!=null&&s.id)||!h.length))try{for(const w of h)await a({variables:{id:s.id,dedupKey:w}});await d(),i({variables:{tenantId:s.id}})}catch(w){rt(w,e)}},T=h=>{const{notification:w}=h;k.atNotifications.notificationOpened({noticeType:w.noticeType,topic:w.topic,kind:w.kind,wasUnread:!w.read,hasDeadline:!!(w.computedDeadline??w.deadline)}),r(w),h.unreadDedupKeys.length&&A(h.unreadDedupKeys)},v=()=>{k.atNotifications.markedAllRead({unreadCount:p}),A([void 0])},O=()=>{k.atNotifications.refreshed(),o()},L=h=>{f(h),k.atNotifications.filterToggled({filter:"duplicates",enabled:h,count:y.duplicateCount})},$=h=>{S(h),k.atNotifications.filterToggled({filter:"outdated",enabled:h,count:y.outdatedCount})},F=()=>{d(),s!=null&&s.id&&i({variables:{tenantId:s.id}})};return t.jsxs("div",{className:"space-y-6 pb-6",children:[t.jsx(Bt,{}),t.jsx($t,{onLoaded:F}),g?t.jsx(se,{variant:"connect"}):t.jsxs(t.Fragment,{children:[t.jsx(Wt,{isRefreshing:N,refreshedAt:j==null?void 0:j.notificationsRefreshedAt,canRefresh:!!(j!=null&&j.backgroundRefreshEligible),onRefresh:O,unreadCount:p,onMarkAllRead:v,outdatedCount:y.outdatedCount,showOutdated:u,onToggleOutdated:$,duplicateCount:y.duplicateCount,showDuplicates:I,onToggleDuplicates:L}),l.length&&C?t.jsx(Yt,{sections:y,onRowClick:T},s==null?void 0:s.id):t.jsx(se,{variant:"empty"})]}),t.jsx(Dt,{notification:n,open:!!n,onOpenChange:h=>{h||r(null)}})]})};function ss(){return t.jsx(zt,{})}export{ss as Component};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.