import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App'
import './styles/global.css'

// Listen for auth token from parent Studio window
window.addEventListener('message', (event) => {
  const data = event.data as { type?: string; token?: string }
  if (data?.type === 'AUTH_TOKEN' && data?.token) {
    localStorage.setItem('auth_token', data.token)
    console.log('Auth token received from Studio')
  }
})

ReactDOM.createRoot(document.getElementById('root')!).render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
)
