---
import DocLayout from "../../layouts/DocLayout.astro";
import Heading from "../../components/docs/Heading.astro";
import ComponentSection from "../../components/docs/ComponentSection.astro";
import ComponentExample from "../../components/docs/ComponentExample.astro";
import CodeBlock from "../../components/docs/CodeBlock.astro";
import PropsTable from "../../components/docs/PropsTable.astro";
import {
  PaginationBasicDemo,
  PaginationSimpleDemo,
  PaginationFullDemo,
  PaginationMidPageDemo,
  PaginationLargeDatasetDemo,
  PaginationCustomTextDemo,
} from "../../components/demos/PaginationDemo";
---

<DocLayout
  title="Pagination"
  description="A page navigation component for navigating through paginated content."
  sourceFile="components/pagination"
>
  <!-- Demo -->
  <ComponentSection>
    <ComponentExample
      code={`<Pagination
  page={page}
  setPage={setPage}
  perPage={10}
  totalCount={100}
/>`}
    >
      <PaginationBasicDemo client:visible />
    </ComponentExample>
  </ComponentSection>

  <!-- Installation -->
  <ComponentSection>
    <Heading level={2}>Installation</Heading>
    <Heading level={3} class="mb-2 text-lg">Barrel</Heading>
    <CodeBlock
      code={`import { Pagination } from "@cloudflare/kumo";`}
      lang="tsx"
    />
    <Heading level={3} class="mb-2 mt-4 text-lg">Granular</Heading>
    <CodeBlock
      code={`import { Pagination } from "@cloudflare/kumo/components/pagination";`}
      lang="tsx"
    />
  </ComponentSection>

  <!-- Usage -->
  <ComponentSection>
    <Heading level={2}>Usage</Heading>
    <CodeBlock
      code={`import { useState } from "react";
import { Pagination } from "@cloudflare/kumo";

export default function Example() {
  const [page, setPage] = useState(1);

  return (
    <Pagination
      page={page}
      setPage={setPage}
      perPage={10}
      totalCount={100}
    />
  );
}`}
      lang="tsx"
    />
  </ComponentSection>

  <!-- Examples -->
  <ComponentSection>
    <Heading level={2} class="mb-6">Examples</Heading>

    <div class="space-y-8">
      <div>
        <Heading level={3}>Full Controls (Default)</Heading>
        <p class="mb-4 text-kumo-subtle">
          The default pagination includes first, previous, page input, next, and
          last buttons.
        </p>
        <ComponentExample
          code={`<Pagination
  page={page}
  setPage={setPage}
  perPage={10}
  totalCount={100}
  controls="full"
/>`}
        >
          <PaginationFullDemo client:visible />
        </ComponentExample>
      </div>

      <div>
        <Heading level={3}>Simple Controls</Heading>
        <p class="mb-4 text-kumo-subtle">
          Use <code class="text-kumo-default">controls="simple"</code> for a minimal
          pagination with only previous and next buttons.
        </p>
        <ComponentExample
          code={`<Pagination
  page={page}
  setPage={setPage}
  perPage={10}
  totalCount={100}
  controls="simple"
/>`}
        >
          <PaginationSimpleDemo client:visible />
        </ComponentExample>
      </div>

      <div>
        <Heading level={3}>Mid-Page State</Heading>
        <p class="mb-4 text-kumo-subtle">
          Pagination in the middle of a dataset with all navigation enabled.
        </p>
        <ComponentExample
          code={`<Pagination
  page={5}
  setPage={setPage}
  perPage={10}
  totalCount={100}
/>`}
        >
          <PaginationMidPageDemo client:visible />
        </ComponentExample>
      </div>

      <div>
        <Heading level={3}>Large Dataset</Heading>
        <p class="mb-4 text-kumo-subtle">
          Pagination handles large datasets with many pages.
        </p>
        <ComponentExample
          code={`<Pagination
  page={1}
  setPage={setPage}
  perPage={25}
  totalCount={1250}
/>`}
        >
          <PaginationLargeDatasetDemo client:visible />
        </ComponentExample>
      </div>

      <div>
        <Heading level={3}>Custom Text</Heading>
        <p class="mb-4 text-kumo-subtle">
          You can set custom pagination text
        </p>
        <ComponentExample
          code={`<Pagination
  text={({perPage}) => \`Showing $\{perPage\} per page!\`}
  page={1}
  setPage={setPage}
  perPage={25}
  totalCount={100}
/>`}
        >
          <PaginationCustomTextDemo client:visible />
        </ComponentExample>
      </div>
    </div>
  </ComponentSection>

  <!-- API Reference -->
  <ComponentSection>
    <Heading level={2}>API Reference</Heading>
    <PropsTable component="Pagination" />
  </ComponentSection>
</DocLayout>
