import { createServerFn } from '@tanstack/react-start'

export const getConfig = createServerFn({ method: 'GET' }).handler(async () => {
  return {
    apiDomain: process.env.VITE_API_DOMAIN || 'http://localhost:3000',
    websiteDomain: process.env.VITE_WEBSITE_DOMAIN || 'http://localhost:3000',
    spotifyClientId: process.env.VITE_SPOTIFY_CLIENT_ID || '',
    spotifyRedirectUri: process.env.VITE_SPOTIFY_REDIRECT_URI || '',
  }
})

export const serverConfig = {
  apiDomain: process.env.VITE_API_DOMAIN || 'http://localhost:3000',
  websiteDomain: process.env.VITE_WEBSITE_DOMAIN || 'http://localhost:3000',
  supertokensUri: process.env.SUPERTOKENS_URI || 'http://localhost:3567',
  pocketbaseUrl: process.env.POCKETBASE_URL || 'http://localhost:8090',
  spotifyClientId: process.env.VITE_SPOTIFY_CLIENT_ID || '',
  spotifyClientSecret: process.env.SPOTIFY_CLIENT_SECRET || '',
}

export const vapidConfig = {
  publicKey: process.env.VAPID_PUBLIC_KEY || '',
  privateKey: process.env.VAPID_PRIVATE_KEY || '',
  subject: process.env.VAPID_SUBJECT || 'mailto:admin@flexxon.app',
}

export const isPushConfigured = () =>
  Boolean(vapidConfig.publicKey && vapidConfig.privateKey)
