'use client'
import { Portal } from '@ark-ui/react/portal'
import { Toaster as ArkToaster, createToaster, Toast, useToastContext } from '@ark-ui/react/toast'
import type React from 'react'
import { type ComponentPropsWithRef, forwardRef } from 'react'
import { createStyleContext, Stack, styled } from 'styled-system/jsx'
import { toast } from 'styled-system/recipes'
import { CloseButton } from './CloseButton'
import { Icon, type IconProps } from './Icon'
import { Spinner } from './Spinner'
const CheckCircleIcon = () => (
)
const CircleAlertIcon = () => (
)
const CircleXIcon = () => (
)
const { withProvider, withContext } = createStyleContext(toast)
const Root = withProvider(Toast.Root, 'root')
const Title = withContext(Toast.Title, 'title')
const Description = withContext(Toast.Description, 'description')
const ActionTrigger = withContext(Toast.ActionTrigger, 'actionTrigger')
const CloseTrigger = withContext(Toast.CloseTrigger, 'closeTrigger')
const StyledToaster = styled(ArkToaster)
const iconMap: Record = {
warning: CircleAlertIcon,
success: CheckCircleIcon,
error: CircleXIcon,
}
// eslint-disable-next-line no-undef
const Indicator = forwardRef>(function ToastIndicator(props, ref) {
const toast = useToastContext()
const StatusIcon = iconMap[toast.type]
if (!StatusIcon) return null
return (
)
})
export const toaster: ReturnType = createToaster({
placement: 'bottom-end',
pauseOnPageIdle: true,
overlap: true,
max: 5,
})
export const Toaster = () => {
return (
{(toast) => (
{toast.type === 'loading' ? : }
{toast.title && {toast.title}}
{toast.description && {toast.description}}
{toast.action && {toast.action.label}}
{toast.closable && (
)}
)}
)
}