{"version":3,"sources":["../../../../src/components/notification-item/NotificationItem.tsx"],"sourcesContent":["import type { Notification } from '@novu/js';\nimport { SeverityLevelEnum } from '@novu/js';\nimport type { NotificationActionClickHandler, NotificationClickHandler } from '@novu/js/ui';\nimport {\n  cn,\n  createNotificationItemController,\n  isInsideIsland,\n  notificationItemStyles,\n  SEVERITY_TO_BAR_KEYS,\n  SEVERITY_TO_NOTIFICATION_KEYS,\n} from '@novu/js/ui-core';\nimport React, { type ReactNode, useMemo, useRef } from 'react';\nimport { useEngineStores, useStyle } from '../../hooks/internal/useEngineStores';\nimport {\n  type NotificationItemContextValue,\n  NotificationItemProvider,\n  useInheritedNotificationHandlers,\n} from './context';\nimport { CustomActions, DefaultActions } from './parts/Actions';\nimport { Avatar } from './parts/Avatar';\nimport { Content, Text } from './parts/Content';\nimport { Date } from './parts/Date';\nimport { Dot } from './parts/Dot';\nimport { Body, Subject } from './parts/Subject';\n\nexport type NotificationItemProps = {\n  notification: Notification;\n  /** Your own arrangement of the parts. Without it, the built-in arrangement is rendered. */\n  children?: ReactNode;\n  className?: string;\n  onNotificationClick?: NotificationClickHandler;\n  onPrimaryActionClick?: NotificationActionClickHandler;\n  onSecondaryActionClick?: NotificationActionClickHandler;\n  renderAvatar?: (notification: Notification) => ReactNode;\n  renderSubject?: (notification: Notification) => ReactNode;\n  renderBody?: (notification: Notification) => ReactNode;\n  renderDefaultActions?: (notification: Notification) => ReactNode;\n  renderCustomActions?: (notification: Notification) => ReactNode;\n};\n\nconst DefaultArrangement = () => (\n  <>\n    <Avatar />\n    <Content>\n      <Text>\n        <Subject />\n        <Body />\n      </Text>\n      <DefaultActions />\n      <CustomActions />\n      <Date />\n    </Content>\n    <Dot />\n  </>\n);\n\n/**\n * The built-in notification item, rendered natively in React.\n *\n * `<NotificationItem notification={n} />` is the default look. Pass children to arrange the parts yourself:\n * `NotificationItem.Avatar`, `Content`, `Text`, `Subject`, `Body`, `DefaultActions`, `CustomActions`, `Date`\n * and `Dot`. The root carries the item's behaviour in both modes: severity styling, the hover group, and the\n * click that marks the notification read and follows its redirect. Handlers fall back to the ones given to\n * `Inbox`, `Notifications` or `InboxContent`.\n */\nconst NotificationItemRoot = (props: NotificationItemProps) => {\n  const {\n    notification,\n    children,\n    className,\n    onNotificationClick,\n    onPrimaryActionClick,\n    onSecondaryActionClick,\n    renderAvatar,\n    renderSubject,\n    renderBody,\n    renderDefaultActions,\n    renderCustomActions,\n  } = props;\n  const style = useStyle();\n  const { inbox } = useEngineStores();\n  const inherited = useInheritedNotificationHandlers();\n\n  const handlers = useMemo(\n    () => ({\n      onNotificationClick: onNotificationClick ?? inherited.onNotificationClick,\n      onPrimaryActionClick: onPrimaryActionClick ?? inherited.onPrimaryActionClick,\n      onSecondaryActionClick: onSecondaryActionClick ?? inherited.onSecondaryActionClick,\n    }),\n    [onNotificationClick, onPrimaryActionClick, onSecondaryActionClick, inherited]\n  );\n\n  const latest = useRef({ notification, handlers });\n  latest.current = { notification, handlers };\n  const controller = useMemo(\n    () =>\n      createNotificationItemController({\n        notification: () => latest.current.notification,\n        handlers: () => latest.current.handlers,\n        navigate: inbox.navigate,\n      }),\n    [inbox]\n  );\n\n  const contextValue = useMemo<NotificationItemContextValue>(\n    () => ({\n      notification,\n      handlers,\n      renderers: { renderAvatar, renderSubject, renderBody, renderDefaultActions, renderCustomActions },\n    }),\n    [notification, handlers, renderAvatar, renderSubject, renderBody, renderDefaultActions, renderCustomActions]\n  );\n\n  const severity = notification.severity ?? SeverityLevelEnum.NONE;\n\n  return (\n    <NotificationItemProvider value={contextValue}>\n      <a\n        className={style({\n          key: SEVERITY_TO_NOTIFICATION_KEYS[severity],\n          className: cn(\n            notificationItemStyles.root.className,\n            notificationItemStyles.root.severity[severity],\n            { [notificationItemStyles.root.clickable]: controller.isClickable() },\n            className\n          ),\n          context: { notification },\n        })}\n        onClick={(event) => {\n          if (!isInsideIsland(event.target)) {\n            event.stopPropagation();\n          }\n          void controller.handleClick(event.nativeEvent);\n        }}\n      >\n        <div\n          className={style({\n            key: SEVERITY_TO_BAR_KEYS[severity],\n            className: cn(notificationItemStyles.bar.className, notificationItemStyles.bar.severity[severity]),\n            context: { notification },\n          })}\n        />\n        {children ?? <DefaultArrangement />}\n      </a>\n    </NotificationItemProvider>\n  );\n};\n\nNotificationItemRoot.displayName = 'NotificationItem';\n\nexport const NotificationItem = Object.assign(NotificationItemRoot, {\n  Avatar,\n  Content,\n  Text,\n  Subject,\n  Body,\n  DefaultActions,\n  CustomActions,\n  Date,\n  Dot,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,gBAAkC;AAElC,qBAOO;AACP,mBAAuD;AACvD,6BAA0C;AAC1C,qBAIO;AACP,qBAA8C;AAC9C,oBAAuB;AACvB,qBAA8B;AAC9B,kBAAqB;AACrB,iBAAoB;AACpB,qBAA8B;AAkB5B;AADF,IAAM,qBAAqB,MACzB,4EACE;AAAA,8CAAC,wBAAO;AAAA,EACR,6CAAC,0BACC;AAAA,iDAAC,uBACC;AAAA,kDAAC,0BAAQ;AAAA,MACT,4CAAC,uBAAK;AAAA,OACR;AAAA,IACA,4CAAC,iCAAe;AAAA,IAChB,4CAAC,gCAAc;AAAA,IACf,4CAAC,oBAAK;AAAA,KACR;AAAA,EACA,4CAAC,kBAAI;AAAA,GACP;AAYF,IAAM,uBAAuB,CAAC,UAAiC;AAC7D,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AACJ,QAAM,YAAQ,iCAAS;AACvB,QAAM,EAAE,MAAM,QAAI,wCAAgB;AAClC,QAAM,gBAAY,iDAAiC;AAEnD,QAAM,eAAW;AAAA,IACf,OAAO;AAAA,MACL,qBAAqB,uBAAuB,UAAU;AAAA,MACtD,sBAAsB,wBAAwB,UAAU;AAAA,MACxD,wBAAwB,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