// import "reflect-metadata"
import { Hono } from 'hono'
import { OpenAPIHono } from '@hono/zod-openapi'
import { cors } from 'hono/cors'
import { logger } from 'hono/logger'
import { swaggerUI } from '@hono/swagger-ui'
import { renderer } from './renderer'
import { AppDataSource } from './data-source'
import createApi from './api'
// const app = new Hono()

if(!AppDataSource.isInitialized) await AppDataSource.initialize();

const app = new OpenAPIHono()
// Middleware chain
app.use('*', logger())
app.use('*', cors(
  // {
  //   origin: ['http://localhost:3000'],
  //   allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
  //   credentials: true
  // }
))
createApi(app);

app.use(renderer)

app.get('/ui', swaggerUI({
  url: '/doc',
  persistAuthorization: true
}))

app.get('/*', (c) => {
  return c.render(
    <>
      <h1 className="text-3xl font-bold underline">Hello from SSR</h1>
      <div id="root"></div>
    </>
  )
}) 

export default app
