import { register } from 'ts-node-maintained'
import typescript from '@rollup/plugin-typescript'
import ts from 'typescript'
import resolve from '@rollup/plugin-node-resolve'
import { fromRollup } from '@web/dev-server-rollup'
import AuthPlugin from './demo/elements/authorization/AuthPlugin.js'
import { amfParserApi } from './dev/amf-server/api.js'

const typescriptPlugin = fromRollup(typescript, {}, {})
const resolvePlugin = fromRollup(resolve, {}, {})

register({
  transpileOnly: true, // Optional: Skips type checking for faster compilation
  esm: true, // Enables ES module support
})

export default /** @type {import('@web/dev-server').DevServerConfig} */ ({
  open: '/demo/',
  nodeResolve: false,

  plugins: [
    resolvePlugin({ browser: true }),

    typescriptPlugin({
      tsconfig: 'tsconfig.browser.json',
      typescript: ts,
      compilerOptions: {
        sourceMap: true,
      },
    }),

    {
      name: 'ts-mime-plugin',
      resolveMimeType(context) {
        if (context.path.endsWith('.ts')) {
          return 'js'
        }
      },
    },

    AuthPlugin,
  ],

  // preserveSymlinks: true,

  // See documentation for all available options

  middleware: [amfParserApi],
})
