import type { Metadata } from "next";
import { headers } from "next/headers";
import { resolvePublicOrigin } from "@/lib/server/public-origin";
import "./globals.css";

export async function generateMetadata(): Promise<Metadata> {
  const metadataBase = resolvePublicOrigin(await headers());
  return {
    metadataBase,
    title: "听阅 · HearBooks",
    description: "把 EPUB 和 PDF 变成可以随时收听的中英双语有声书。",
    alternates: { canonical: "/" },
    openGraph: {
      title: "听阅 · HearBooks",
      description: "上传 EPUB 或 PDF，校对正文，然后用中英文语音随时收听。",
      type: "website",
      locale: "zh_CN",
      url: "/",
      images: [{ url: "/og-hearbooks.png", width: 1536, height: 906, alt: "打开的书本化为声音波纹" }],
    },
  };
}

export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <html lang="zh-CN">
      <body>
        {children}
        <footer className="legal-footer">
          <span>HearBooks 是按 AGPLv3 开放源码的个人工具，不提供服务保证。</span>
          <span>
            <a href="/source.zip" download>下载当前版本源码</a>
            <span aria-hidden="true"> · </span>
            <a href="/THIRD_PARTY_NOTICES.md">第三方与语音说明</a>
          </span>
        </footer>
      </body>
    </html>
  );
}
