import { Portal } from 'solid-js/web'
import { Toast, Toaster, createToaster } from '@ark-ui/solid/toast'
import { XIcon } from 'lucide-solid'
import button from 'styles/button.module.css'
import styles from 'styles/toast.module.css'

export const Placement = () => {
  const toaster = createToaster({
    placement: 'top-end',
    overlap: true,
    gap: 16,
  })

  return (
    <div>
      <button
        type="button"
        class={button.Root}
        onClick={() =>
          toaster.create({
            title: 'Notification',
            description: 'This toast appears at the top-right corner.',
            type: 'info',
          })
        }
      >
        Show toast (top-end)
      </button>
      <Portal>
        <Toaster toaster={toaster}>
          {(toast) => (
            <Toast.Root class={styles.Root}>
              <Toast.Title class={styles.Title}>{toast().title}</Toast.Title>
              <Toast.Description class={styles.Description}>{toast().description}</Toast.Description>
              <Toast.CloseTrigger class={styles.CloseTrigger}>
                <XIcon />
              </Toast.CloseTrigger>
            </Toast.Root>
          )}
        </Toaster>
      </Portal>
    </div>
  )
}
