import { StyleObjectIdentifier, StyleObjectRules } from '@hanzogui/helpers'
import type { StyleObject } from '../types'

// turns out this is pretty slow, creating a bunch of extra tags...

export function getStyleTags(styles: StyleObject[]) {
  if (process.env.GUI_TARGET !== 'native') {
    if (styles.length) {
      return (
        <>
          {styles.map((styleObject) => {
            const identifier = styleObject[StyleObjectIdentifier]
            return (
              <style
                key={identifier}
                // @ts-ignore
                href={`t_${identifier}`}
                // @ts-ignore
                precedence="default"
                // we remove after first render in favor of inserting to a global stylesheet (faster)
                suppressHydrationWarning
              >
                {styleObject[StyleObjectRules].join('\n')}
              </style>
            )
          })}
        </>
      )
    }
  }
}
