"use client";

import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { useEffect, useState } from "react";
import { MailWorkspace } from "@/components/mail-workspace";
import { resolveBrandDomainFromHost } from "@/lib/site-config";

export function MailWorkspaceShell() {
  const [brandDomain, setBrandDomain] = useState("");
  const [client] = useState(
    () =>
      new QueryClient({
        defaultOptions: {
          queries: {
            refetchOnWindowFocus: false,
            retry: 1,
            staleTime: 20_000,
          },
        },
    })
  );

  useEffect(() => {
    setBrandDomain(resolveBrandDomainFromHost(window.location.hostname));
  }, []);

  return (
    <QueryClientProvider client={client}>
      <MailWorkspace tenantDomain={brandDomain} />
    </QueryClientProvider>
  );
}
