import type { Preview } from '@storybook/nextjs'
import { useEffect } from 'react'
import '../src/app/fonts.css'

const ThemeDecorator = (Story: any, context: any) => {
  const backgroundValue = context.globals.backgrounds?.value
  const theme = backgroundValue == 'dark' ? 'dark-theme' : ''
  
  useEffect(() => {
    document.documentElement.setAttribute('data-theme', theme)
  }, [theme])
  return Story()
}

const preview: Preview = {
  parameters: {
    backgrounds: {
      default: 'light',
      options: {
        light: { name: 'light', value: '#ffe788' },
        dark: { name: 'dark', value: 'black' },
      },
    },
    controls: {
      matchers: {
        color: /(background|color)$/i,
        date: /Date$/i,
      },
    },
    a11y: {
      test: "todo"
    }
  },
  
  decorators: [ThemeDecorator],
  
  initialGlobals: {
    backgrounds: { value: 'white' },
  },
}

export default preview