import type { Metadata } from "next";
import Link from "next/link";
import { SiteShell } from "@/components/site-shell";

export const metadata: Metadata = {
  title: "Guide | BatchForge",
  description: "How to use, inspect, run, and modify BatchForge.",
};

const contents = [
  ["use", "1. Use"],
  ["formats", "2. Formats"],
  ["privacy", "3. Privacy"],
  ["limits", "4. Limits"],
  ["source", "5. Source and build"],
  ["testing", "6. Test standing"],
  ["licence", "7. Licence"],
] as const;

export default function GuidePage() {
  return (
    <SiteShell>
      <div className="family-container family-guide-layout">
        <aside className="family-guide-index">
          <p>BatchForge Guide</p>
          <span>Version 1.7 · September 2026</span>
          <nav aria-label="Guide contents">
            {contents.map(([href, label]) => <a href={`#${href}`} key={href}>{label}</a>)}
          </nav>
        </aside>

        <article className="tool-guide family-guide-content">
          <header className="tool-guide-header">
            <p className="eyebrow">Project documentation</p>
            <h1>BatchForge Guide</h1>
            <p>Use, behavior, limits, source, testing, and licence.</p>
          </header>

          <section id="use">
            <h2>1. Use</h2>
            <ol>
              <li>Drop images or folders into the converter, or use the two browse controls.</li>
              <li>Choose WebP quality and, if needed, a maximum width.</li>
              <li>Select <strong>Convert</strong>.</li>
              <li>Download one converted WebP directly or several successful files as a ZIP.</li>
            </ol>
            <p>Conversion runs sequentially so large batches are less likely to freeze the browser. A failed file does not prevent downloading successful results.</p>
          </section>

          <section id="formats">
            <h2>2. Formats</h2>
            <table>
              <thead><tr><th>Input</th><th>Behavior</th></tr></thead>
              <tbody>
                <tr><td>PNG, JPEG, BMP, SVG, AVIF</td><td>Converted to a still WebP.</td></tr>
                <tr><td>GIF and WebP</td><td>Animated files become one still frame.</td></tr>
                <tr><td>TIFF</td><td>The first page is used.</td></tr>
                <tr><td>HEIC and HEIF</td><td>The first decoded image is used.</td></tr>
                <tr><td>ICO</td><td>One decoded resolution is used.</td></tr>
              </tbody>
            </table>
            <p>Output is always WebP. Re-encoding does not guarantee a smaller file; high quality can make an already efficient source larger.</p>
          </section>

          <section id="privacy">
            <h2>3. Privacy</h2>
            <p>Image conversion happens inside the browser. BatchForge has no image-upload endpoint and does not send source image bytes to a conversion service. A first-party cookie shares only the selected theme across the `myforgeworks.net` family; local storage supplies immediate display and fallback behavior. The theme value is not an account or visitor identifier.</p>
          </section>

          <section id="limits">
            <h2>4. Limits</h2>
            <ul>
              <li>There is no set file-count cap, but practical capacity depends on image dimensions, browser memory, and available device memory.</li>
              <li>RAW camera files, PSD, and PDF are not supported.</li>
              <li>Animated and multipage inputs are flattened as described above.</li>
              <li>Browser support for WebP encoding and individual source formats still applies.</li>
            </ul>
          </section>

          <section id="source">
            <h2>5. Source and build</h2>
            <p><Link href="/download-source">Download the complete source package</Link>. It includes the application, this Guide, the test suite, build instructions, maintenance rules, changelog, and licence.</p>
            <pre><code>{`npm ci\nnpm test\nnpm run dev`}</code></pre>
            <p>Node.js 22.13 or newer is required. The repository is the reconstruction record; future changes should extend its existing architecture rather than replace it with a new template.</p>
          </section>

          <section id="testing">
            <h2>6. Test standing</h2>
            <p>The release checks cover the production build, page routes, conversion workflow contracts, download behavior, theme structure, privacy wording, logo assets, and shared Forgeworks interface contract.</p>
            <p>Browser conversion was previously verified for PNG, JPEG, WebP, AVIF, GIF, BMP, SVG, ICO, and TIFF. HEIC and HEIF use a dedicated local decoder but did not receive identical automated fixture coverage in that release environment.</p>
          </section>

          <section id="licence">
            <h2>7. Licence</h2>
            <p>BatchForge software is released under the <Link href="/LICENSE.txt">MIT License</Link>. It may be used, copied, modified, and distributed, including commercially, while retaining the copyright and licence notice.</p>
            <p>The licence covers the software. Project names and logos do not automatically grant endorsement or identity rights.</p>
          </section>
        </article>
      </div>
    </SiteShell>
  );
}
