import { PostHog } from "posthog-node"

let client: PostHog | undefined

export default function PostHogClient(): PostHog | undefined {
  if (process.env.NODE_ENV !== "production") {
    return undefined
  }
  if (!client) {
    client = new PostHog("phc_aUO790jHd7z1SXwsYCz8dRApxueplZlZWeDSpKc5hol", {
      host: "https://app.posthog.com",
      flushAt: 20,
      flushInterval: 10000,
    })
  }
  return client
}
