# Record panel

A record opened in a panel over the list: 640 px on the right, starting under the header, with the record's name in its header and its sections in tabs.

An example screen: a page layout built only from the library's exports, on made-up records. It is not a page of the CRM. Copy its structure; replace the sample data and the local state with the app's own.

## What it shows

- The list stays where it was behind the panel. Escape, the close button or a press outside goes back to it.
- A detail with no value says what is missing, like No due date. It is never left blank.
- Activity is a list with a line between rows: each row is read on its own, so it isn't a table.

## RecordPanel.tsx

```tsx
import {
  CirclePlus,
  FileText,
  MessageSquareText,
  RefreshCw,
  UserRoundPen,
} from "lucide-react";
import type { ReactNode } from "react";
import {
  Avatar,
  Badge,
  Drawer,
  DrawerBody,
  DrawerContent,
  DrawerHeader,
  EmptyValue,
  IconTile,
  List,
  ListItem,
  Tabs,
  TabsList,
  TabsPanel,
  TabsPanels,
  TabsTab,
  TextLink,
} from "@leap-crm/design-system";
import {
  activity,
  formatDate,
  statuses,
  type ActivityKind,
  type SampleRecord,
} from "./fixtures";

const activityIcons: Record<ActivityKind, ReactNode> = {
  created: <CirclePlus />,
  status: <RefreshCw />,
  note: <MessageSquareText />,
  owner: <UserRoundPen />,
};

/** One named value. A value that is missing says so; it is never left blank. */
function Detail({ label, children }: { label: string; children: ReactNode }) {
  return (
    <div className="flex min-w-0 flex-col gap-1">
      <dt className="text-small text-neutral-text-muted">{label}</dt>
      <dd className="text-body text-neutral-text m-0 flex min-h-5 items-center">
        {children}
      </dd>
    </div>
  );
}

/**
 * A record in a panel over the page it was opened from, as the CRM opens a
 * workspace: 640 px wide on the right, starting under the header, with the
 * record's name and what it is in the panel's header and its sections in
 * tabs. The page stays where it was behind it.
 */
function RecordPanel({
  record,
  open,
  onOpenChange,
}: {
  record: SampleRecord;
  open: boolean;
  onOpenChange: (open: boolean) => void;
}) {
  return (
    <Drawer open={open} onOpenChange={onOpenChange}>
      {/* The panel starts under the 48 px header, so the header stays in view. */}
      <DrawerContent className="top-12">
        <DrawerHeader
          icon={<FileText />}
          title={record.name}
          subtitle={`${record.category} · ${record.id.toUpperCase()}`}
        />
        {/* The tabs sit flush under the panel's header, across its whole width; only the section under them scrolls. */}
        <Tabs defaultValue="details" className="flex min-h-0 flex-1 flex-col">
          <TabsList aria-label="Record sections" className="px-3">
            <TabsTab value="details">Details</TabsTab>
            <TabsTab value="activity" count={activity.length}>
              Activity
            </TabsTab>
          </TabsList>
          <DrawerBody>
            <TabsPanels>
              <TabsPanel value="details">
                <dl className="m-0 grid gap-x-8 gap-y-6 pt-2 sm:grid-cols-2">
                  <Detail label="Status">
                    <Badge size="sm" tone={statuses[record.status].tone}>
                      {statuses[record.status].label}
                    </Badge>
                  </Detail>
                  <Detail label="Owner">
                    <span className="flex items-center gap-2">
                      <Avatar
                        size="xs"
                        person="staff"
                        name={record.owner.name}
                        initials={record.owner.initials}
                      />
                      {record.owner.name}
                    </span>
                  </Detail>
                  <Detail label="Category">{record.category}</Detail>
                  <Detail label="Due">
                    {record.due === null ? (
                      <EmptyValue label="No due date" />
                    ) : (
                      formatDate(record.due)
                    )}
                  </Detail>
                  <Detail label="Contact email">
                    {record.email === null ? (
                      <EmptyValue label="No contact email" />
                    ) : (
                      <TextLink href={`mailto:${record.email}`}>
                        {record.email}
                      </TextLink>
                    )}
                  </Detail>
                  <Detail label="Created">{record.created}</Detail>
                </dl>
              </TabsPanel>
              <TabsPanel value="activity">
                <List dividers aria-label="Activity">
                  {activity.map(entry => (
                    <ListItem
                      key={entry.id}
                      leading={
                        <IconTile
                          size={28}
                          tone="neutral"
                          icon={activityIcons[entry.kind]}
                        />
                      }
                      primary={entry.what}
                      secondary={entry.who}
                      trailing={entry.when}
                    />
                  ))}
                </List>
              </TabsPanel>
            </TabsPanels>
          </DrawerBody>
        </Tabs>
      </DrawerContent>
    </Drawer>
  );
}

export { RecordPanel };
```

## RecordPanelScreen.tsx

```tsx
import { RecordsPage } from "./RecordsPage";

/** The list page with a record open in its panel. */
function RecordPanelScreen() {
  return <RecordsPage defaultOpenId="r-1042" />;
}

export { RecordPanelScreen };
```

## RecordsPage.tsx

```tsx
import { Inbox, Search, SearchX } from "lucide-react";
import { useState } from "react";
import {
  AlertDialog,
  AlertDialogClose,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
  Avatar,
  Badge,
  Button,
  Checkbox,
  EmptyState,
  Input,
  ScrollArea,
  SegmentedControl,
  SegmentedControlItem,
  Select,
  SelectContent,
  SelectItem,
  SelectTrigger,
  SelectValue,
  Table,
  TableBody,
  TableCell,
  TableHead,
  TableHeader,
  TableRow,
  Truncate,
  toast,
} from "@leap-crm/design-system";
import { AppShell } from "./AppShell";
import {
  me,
  records as sample,
  statuses,
  type SampleRecord,
  type StatusId,
} from "./fixtures";
import { NewRecordPanel } from "./NewRecordPanel";
import { RecordPanel } from "./RecordPanel";

const views = { all: "All", mine: "Mine", closed: "Closed" } as const;
type View = keyof typeof views;
const isView = (value: unknown): value is View =>
  typeof value === "string" && value in views;

const anyStatus = "any";
const statusIds = Object.keys(statuses).filter(
  (id): id is StatusId => id in statuses,
);

const inView = (view: View) => (record: SampleRecord) =>
  view === "all" ||
  (view === "mine" && record.owner.id === me.id) ||
  (view === "closed" && record.status === "closed");

/**
 * A list page, laid out as the CRM's lists are: the page is the list. One
 * 48 px toolbar sits straight under the header, with the views on its left
 * and search, filters and the selection's actions on its right. The table
 * fills everything below it, edge to edge, and is the only part that scrolls.
 * There is no page title and no padding around the table.
 *
 * A row's name opens the record in a panel over the list. New, in the header,
 * opens the form panel.
 */
function RecordsPage({
  initial = sample,
  defaultOpenId = null,
  defaultCreating = false,
}: {
  /** The records to list. */
  initial?: SampleRecord[];
  /** The record whose panel starts open. */
  defaultOpenId?: string | null;
  /** Whether the New record panel starts open. */
  defaultCreating?: boolean;
}) {
  const [items, setItems] = useState(initial);
  const [view, setView] = useState<View>("all");
  const [query, setQuery] = useState("");
  const [status, setStatus] = useState<string>(anyStatus);
  const [selected, setSelected] = useState<string[]>([]);
  const [confirming, setConfirming] = useState(false);
  const [openId, setOpenId] = useState(defaultOpenId);
  const [creating, setCreating] = useState(defaultCreating);

  const needle = query.trim().toLowerCase();
  const rows = items
    .filter(inView(view))
    .filter(record => status === anyStatus || record.status === status)
    .filter(record => record.name.toLowerCase().includes(needle));
  const filtered = needle !== "" || status !== anyStatus;
  const shownIds = rows.map(row => row.id);
  const shownSelected = shownIds.filter(id => selected.includes(id));
  const open = items.find(record => record.id === openId);

  // Any change to what's listed drops the selection: a hidden row is never deleted.
  const refine = (change: () => void) => {
    change();
    setSelected([]);
  };
  const clearFilters = () =>
    refine(() => {
      setQuery("");
      setStatus(anyStatus);
    });

  const remove = () => {
    const removed = items.filter(record => selected.includes(record.id));
    setItems(current =>
      current.filter(record => !selected.includes(record.id)),
    );
    setSelected([]);
    toast.success({
      title:
        removed.length === 1
          ? "Record deleted"
          : `${removed.length} records deleted`,
      action: {
        label: "Undo",
        onAction: () => setItems(current => [...removed, ...current]),
      },
    });
  };

  return (
    <AppShell
      page="Records"
      unread={3}
      creating={creating}
      onNew={() => setCreating(true)}
    >
      <div className="border-neutral-divider flex min-h-12 flex-wrap items-center justify-between gap-x-4 gap-y-2 border-b px-4 py-2">
        <SegmentedControl
          size="xs"
          aria-label="View"
          value={view}
          onValueChange={next => {
            if (isView(next)) refine(() => setView(next));
          }}
        >
          {Object.entries(views).map(([value, label]) => (
            <SegmentedControlItem key={value} value={value}>
              {label}
            </SegmentedControlItem>
          ))}
        </SegmentedControl>
        <div className="flex flex-wrap items-center gap-2">
          <Input
            size="xs"
            className="w-60"
            aria-label="Search records"
            placeholder={
              items.length === 0
                ? "Search records"
                : `Search ${rows.length} records`
            }
            prefix={<Search className="size-3.5" />}
            value={query}
            onValueChange={value => refine(() => setQuery(value))}
            clearable
          />
          <Select
            value={status}
            onValueChange={value => refine(() => setStatus(value ?? anyStatus))}
          >
            <SelectTrigger size="xs" className="w-36" aria-label="Status">
              <SelectValue />
            </SelectTrigger>
            <SelectContent>
              <SelectItem value={anyStatus}>Any status</SelectItem>
              {statusIds.map(id => (
                <SelectItem key={id} value={id}>
                  {statuses[id].label}
                </SelectItem>
              ))}
            </SelectContent>
          </Select>
          {selected.length > 0 && (
            <Button
              intent="outline"
              size="xs"
              onClick={() => setConfirming(true)}
            >
              Delete {selected.length}
            </Button>
          )}
        </div>
      </div>

      {rows.length === 0 ? (
        <div className="flex flex-1 items-center justify-center p-6">
          {items.length === 0 ? (
            <EmptyState
              icon={<Inbox />}
              title="No records yet"
              description="Records you add show here."
              action={
                <Button
                  intent="outline"
                  size="sm"
                  onClick={() => setCreating(true)}
                >
                  New record
                </Button>
              }
            />
          ) : (
            <EmptyState
              icon={<SearchX />}
              title="No records match"
              description={
                filtered
                  ? "Try another search, or clear the filters to see every record in this view."
                  : "This view has no records in it."
              }
              action={
                filtered ? (
                  <Button intent="outline" size="sm" onClick={clearFilters}>
                    Clear filters
                  </Button>
                ) : undefined
              }
            />
          )}
        </div>
      ) : (
        <ScrollArea horizontal aria-label="Records" className="min-h-0 flex-1">
          <Table
            variant="main"
            className="min-w-220"
            tableClassName="whitespace-nowrap"
          >
            <TableHeader>
              <TableRow>
                <TableHead className="w-10 ps-4">
                  <Checkbox
                    aria-label="Select every record listed"
                    checked={
                      shownSelected.length === shownIds.length
                        ? true
                        : shownSelected.length > 0 && "indeterminate"
                    }
                    onCheckedChange={checked =>
                      setSelected(checked === true ? shownIds : [])
                    }
                  />
                </TableHead>
                <TableHead>Name</TableHead>
                <TableHead>Category</TableHead>
                <TableHead>Status</TableHead>
                <TableHead>Owner</TableHead>
                <TableHead>Created</TableHead>
                <TableHead className="pe-4">Last updated</TableHead>
              </TableRow>
            </TableHeader>
            <TableBody>
              {rows.map(row => (
                <TableRow key={row.id}>
                  <TableCell className="ps-4">
                    <Checkbox
                      aria-label={`Select ${row.name}`}
                      checked={selected.includes(row.id)}
                      onCheckedChange={checked =>
                        setSelected(current =>
                          checked === true
                            ? [...current, row.id]
                            : current.filter(id => id !== row.id),
                        )
                      }
                    />
                  </TableCell>
                  <TableCell className="max-w-96">
                    <Button
                      intent="ghost"
                      size="sm"
                      className="-ms-3 max-w-full text-base"
                      onClick={() => setOpenId(row.id)}
                    >
                      <Truncate>{row.name}</Truncate>
                    </Button>
                  </TableCell>
                  <TableCell className="text-neutral-text-secondary">
                    {row.category}
                  </TableCell>
                  <TableCell>
                    <Badge size="sm" tone={statuses[row.status].tone}>
                      {statuses[row.status].label}
                    </Badge>
                  </TableCell>
                  <TableCell>
                    <span className="flex items-center gap-2">
                      <Avatar
                        size="xs"
                        person="staff"
                        name={row.owner.name}
                        initials={row.owner.initials}
                      />
                      {row.owner.name}
                    </span>
                  </TableCell>
                  <TableCell className="text-neutral-text-secondary">
                    {row.created}
                  </TableCell>
                  <TableCell className="text-neutral-text-secondary pe-4">
                    {row.updated}
                  </TableCell>
                </TableRow>
              ))}
            </TableBody>
          </Table>
        </ScrollArea>
      )}

      <AlertDialog open={confirming} onOpenChange={setConfirming}>
        <AlertDialogContent>
          <AlertDialogHeader>
            <AlertDialogTitle>
              {selected.length === 1
                ? "Delete record?"
                : `Delete ${selected.length} records?`}
            </AlertDialogTitle>
            <AlertDialogDescription>
              {selected.length === 1
                ? "It leaves the list for everyone."
                : "They leave the list for everyone."}
            </AlertDialogDescription>
          </AlertDialogHeader>
          <AlertDialogFooter>
            <AlertDialogClose
              render={<Button intent="outline">Cancel</Button>}
            />
            <AlertDialogClose
              render={
                <Button
                  intent="destructive"
                  data-agent-confirm="Deletes the selected records"
                  onClick={remove}
                >
                  Delete
                </Button>
              }
            />
          </AlertDialogFooter>
        </AlertDialogContent>
      </AlertDialog>

      {open && (
        <RecordPanel
          record={open}
          open
          onOpenChange={next => {
            if (!next) setOpenId(null);
          }}
        />
      )}
      <NewRecordPanel
        open={creating}
        onOpenChange={setCreating}
        onCreate={record => {
          setItems(current => [record, ...current]);
          toast.success({ title: "Record saved" });
        }}
      />
    </AppShell>
  );
}

export { RecordsPage };
```

## NewRecordPanel.tsx

```tsx
import { FilePlus2 } from "lucide-react";
import { useId, useState, type SubmitEvent } from "react";
import {
  AlertDialog,
  AlertDialogClose,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
  Button,
  DatePicker,
  Drawer,
  DrawerBody,
  DrawerContent,
  DrawerFooter,
  DrawerHeader,
  Field,
  Input,
  Select,
  SelectContent,
  SelectItem,
  SelectTrigger,
  SelectValue,
  Textarea,
} from "@leap-crm/design-system";
import {
  categories,
  me,
  people,
  today,
  type Category,
  type SampleRecord,
} from "./fixtures";

const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;

type Values = {
  name: string;
  category: Category;
  ownerId: string;
  email: string;
  due: string | null;
  notes: string;
};

const blank: Values = {
  name: "",
  category: categories[0],
  ownerId: me.id,
  email: "",
  due: null,
  notes: "",
};

const isCategory = (value: unknown): value is Category =>
  categories.some(category => category === value);

/**
 * A form in a panel, as the CRM creates and edits records: the fields in one
 * column, two side by side where they are short, and Cancel and Save in the
 * panel's footer. Errors show on Save, under their fields, without moving
 * anything. Leaving with something typed asks "Discard changes?" first.
 */
function NewRecordPanel({
  open,
  onOpenChange,
  onCreate,
}: {
  open: boolean;
  onOpenChange: (open: boolean) => void;
  onCreate: (record: SampleRecord) => void;
}) {
  const form = useId();
  const [values, setValues] = useState(blank);
  const [submitted, setSubmitted] = useState(false);
  const [asking, setAsking] = useState(false);

  const set = (patch: Partial<Values>) =>
    setValues(current => ({ ...current, ...patch }));
  const dirty =
    values.name !== "" ||
    values.category !== blank.category ||
    values.ownerId !== blank.ownerId ||
    values.email !== "" ||
    values.due !== null ||
    values.notes !== "";

  const errors = {
    name: values.name.trim() === "" ? "Please enter a name" : undefined,
    email:
      values.email !== "" && !emailPattern.test(values.email)
        ? "Please enter a valid email"
        : undefined,
  };
  const shown: Partial<typeof errors> = submitted ? errors : {};

  const close = () => {
    setValues(blank);
    setSubmitted(false);
    onOpenChange(false);
  };
  const leave = () => (dirty ? setAsking(true) : close());

  const submit = (event: SubmitEvent<HTMLFormElement>) => {
    event.preventDefault();
    setSubmitted(true);
    const owner = people.find(person => person.id === values.ownerId) ?? me;
    if (Object.values(errors).some(Boolean)) return;
    onCreate({
      // Never from the name: two records can share one, or differ only by a space.
      id: `r-${crypto.randomUUID()}`,
      name: values.name.trim(),
      category: values.category,
      status: "active",
      owner,
      email: values.email || null,
      due: values.due,
      created: "Today",
      updated: "Just now",
    });
    close();
  };

  return (
    <>
      <Drawer
        open={open}
        onOpenChange={next => (next ? onOpenChange(true) : leave())}
        dismissible={!dirty}
        onDismissAttempt={leave}
      >
        <DrawerContent className="top-12">
          <DrawerHeader
            icon={<FilePlus2 />}
            title="New record"
            subtitle="It joins the list for everyone."
          />
          <DrawerBody>
            <form
              id={form}
              noValidate
              onSubmit={submit}
              className="flex flex-col gap-6"
            >
              <Field label="Name" error={shown.name}>
                <Input
                  value={values.name}
                  onValueChange={name => set({ name })}
                  autoComplete="off"
                  required
                />
              </Field>
              <div className="grid gap-x-4 gap-y-6 sm:grid-cols-2">
                <Select
                  value={values.category}
                  onValueChange={category => {
                    if (isCategory(category)) set({ category });
                  }}
                >
                  <Field label="Category">
                    <SelectTrigger>
                      <SelectValue />
                    </SelectTrigger>
                  </Field>
                  <SelectContent>
                    {categories.map(category => (
                      <SelectItem key={category} value={category}>
                        {category}
                      </SelectItem>
                    ))}
                  </SelectContent>
                </Select>
                <Select
                  value={values.ownerId}
                  onValueChange={ownerId => set({ ownerId: ownerId ?? me.id })}
                >
                  <Field label="Owner">
                    <SelectTrigger>
                      <SelectValue />
                    </SelectTrigger>
                  </Field>
                  <SelectContent>
                    {people.map(person => (
                      <SelectItem key={person.id} value={person.id}>
                        {person.name}
                      </SelectItem>
                    ))}
                  </SelectContent>
                </Select>
              </div>
              <div className="grid gap-x-4 gap-y-6 sm:grid-cols-2">
                <Field label="Contact email" optional error={shown.email}>
                  <Input
                    type="email"
                    value={values.email}
                    onValueChange={email => set({ email })}
                    autoComplete="off"
                  />
                </Field>
                <Field label="Due" optional>
                  <DatePicker
                    locale="en-AU"
                    min={today}
                    value={values.due}
                    onValueChange={due =>
                      set({ due: typeof due === "string" ? due : null })
                    }
                  />
                </Field>
              </div>
              <Field label="Notes" optional hint="Visible to everyone.">
                <Textarea
                  autoResize
                  className="max-h-40"
                  value={values.notes}
                  onValueChange={notes => set({ notes })}
                />
              </Field>
            </form>
          </DrawerBody>
          <DrawerFooter>
            <Button intent="outline" onClick={leave}>
              Cancel
            </Button>
            <Button type="submit" form={form}>
              Save record
            </Button>
          </DrawerFooter>
        </DrawerContent>
      </Drawer>

      <AlertDialog open={asking} onOpenChange={setAsking}>
        <AlertDialogContent>
          <AlertDialogHeader>
            <AlertDialogTitle>Discard changes?</AlertDialogTitle>
            <AlertDialogDescription>
              This record hasn't been saved. What you entered will be lost.
            </AlertDialogDescription>
          </AlertDialogHeader>
          <AlertDialogFooter>
            <AlertDialogClose
              render={<Button intent="outline">Keep editing</Button>}
            />
            <AlertDialogClose
              render={
                <Button
                  intent="destructive"
                  data-agent-confirm="Discards the unsaved record"
                  onClick={close}
                >
                  Discard
                </Button>
              }
            />
          </AlertDialogFooter>
        </AlertDialogContent>
      </AlertDialog>
    </>
  );
}

export { NewRecordPanel };
```

## AppShell.tsx

```tsx
import {
  Bell,
  ChartLine,
  LayoutDashboard,
  Plus,
  Search,
  Table2,
} from "lucide-react";
import type { ReactNode } from "react";
import {
  AppHeader,
  Avatar,
  HeaderIconButton,
  HeaderNavLink,
} from "@leap-crm/design-system";
import { me } from "./fixtures";

const pages = [
  { label: "Overview", icon: <LayoutDashboard /> },
  { label: "Records", icon: <Table2 /> },
  { label: "Reports", icon: <ChartLine /> },
] as const;

type PageName = (typeof pages)[number]["label"];

/**
 * The frame every page of the app sits in, as the CRM lays it out: the 48 px
 * navy header across the top, and one page under it that fills the rest of
 * the window and owns its own scrolling. There is no side menu and no page
 * chrome between the header and the page.
 *
 * The header holds the main pages on the left and, on the right, New, Search,
 * Notifications and the person signed in. New things are made from the header,
 * so a page's own toolbar carries no "New" button.
 *
 * In an app, pass your router's link to each HeaderNavLink's `render`.
 */
function AppShell({
  page,
  unread = 0,
  onNew,
  creating = false,
  children,
}: {
  /** The page you're on, marked in the header. Leave it out on a page the header doesn't list, like Settings. */
  page?: PageName;
  /** Unread notifications, on the bell. */
  unread?: number;
  /** Runs when New is pressed. */
  onNew?: () => void;
  /** Whether what New opens is open now. */
  creating?: boolean;
  children: ReactNode;
}) {
  return (
    <div className="bg-neutral-surface flex h-dvh flex-col overflow-hidden">
      <AppHeader
        nav={pages.map(item => (
          <HeaderNavLink
            key={item.label}
            href="#"
            icon={item.icon}
            active={item.label === page}
            onClick={event => event.preventDefault()}
          >
            {item.label}
          </HeaderNavLink>
        ))}
        actions={
          <>
            <HeaderIconButton
              icon={<Plus />}
              aria-label="New record"
              open={creating}
              onClick={onNew}
            />
            <HeaderIconButton icon={<Search />} aria-label="Search" />
            <HeaderIconButton
              icon={<Bell />}
              aria-label="Notifications"
              count={unread}
            />
            <Avatar
              size="lg"
              person="staff"
              name={me.name}
              initials={me.initials}
            />
          </>
        }
      />
      <main className="flex min-h-0 flex-1 flex-col overflow-hidden">
        {children}
      </main>
    </div>
  );
}

export { AppShell };
export type { PageName };
```

## fixtures.ts

```ts
// Sample data for the example screens: plainly made-up records, so a screen
// reads as a layout to copy and never as one of the CRM's own pages.

type Person = { id: string; name: string; initials: string };

const people = [
  { id: "ah", name: "Ada Hartley", initials: "AH" },
  { id: "bo", name: "Ben Okafor", initials: "BO" },
  { id: "cm", name: "Chloe Moreau", initials: "CM" },
] as const satisfies Person[];

/** The person signed in: "Mine" lists their records. */
const me: Person = people[0];

const statuses = {
  active: { label: "Active", tone: "success" },
  review: { label: "In review", tone: "warning" },
  closed: { label: "Closed", tone: "default" },
} as const;

type StatusId = keyof typeof statuses;

const categories = ["Agreement", "Report", "Request", "Template"] as const;

type Category = (typeof categories)[number];

type SampleRecord = {
  id: string;
  name: string;
  category: Category;
  status: StatusId;
  owner: Person;
  /** Who to write to about it, when someone is named. */
  email: string | null;
  /** An ISO date. */
  due: string | null;
  created: string;
  updated: string;
};

const [ada, ben, chloe] = people;

const records: SampleRecord[] = [
  {
    id: "r-1042",
    name: "Supplier agreement renewal",
    category: "Agreement",
    status: "active",
    owner: ada,
    email: "accounts@northwind.example",
    due: "2026-12-11",
    created: "3 Nov 2026",
    updated: "2 hours ago",
  },
  {
    id: "r-1041",
    name: "Quarterly activity report",
    category: "Report",
    status: "review",
    owner: ben,
    email: null,
    due: "2026-12-01",
    created: "2 Nov 2026",
    updated: "Yesterday",
  },
  {
    id: "r-1040",
    name: "Access request for the shared archive and its historical exports",
    category: "Request",
    status: "active",
    owner: chloe,
    email: "it@harbourside.example",
    due: null,
    created: "30 Oct 2026",
    updated: "Yesterday",
  },
  {
    id: "r-1039",
    name: "Onboarding checklist",
    category: "Template",
    status: "closed",
    owner: ada,
    email: null,
    due: null,
    created: "28 Oct 2026",
    updated: "3 days ago",
  },
  {
    id: "r-1038",
    name: "Office lease variation",
    category: "Agreement",
    status: "review",
    owner: ben,
    email: "leasing@quayside.example",
    due: "2026-12-18",
    created: "24 Oct 2026",
    updated: "4 days ago",
  },
  {
    id: "r-1037",
    name: "Annual compliance summary",
    category: "Report",
    status: "active",
    owner: ada,
    email: null,
    due: "2027-01-15",
    created: "21 Oct 2026",
    updated: "5 days ago",
  },
  {
    id: "r-1036",
    name: "Equipment purchase request",
    category: "Request",
    status: "closed",
    owner: chloe,
    email: "orders@fieldworks.example",
    due: null,
    created: "17 Oct 2026",
    updated: "1 week ago",
  },
  {
    id: "r-1035",
    name: "Welcome letter",
    category: "Template",
    status: "active",
    owner: ben,
    email: null,
    due: null,
    created: "14 Oct 2026",
    updated: "1 week ago",
  },
  {
    id: "r-1034",
    name: "Service agreement",
    category: "Agreement",
    status: "closed",
    owner: chloe,
    email: "hello@brightline.example",
    due: null,
    created: "9 Oct 2026",
    updated: "2 weeks ago",
  },
  {
    id: "r-1033",
    name: "Monthly usage report",
    category: "Report",
    status: "active",
    owner: ada,
    email: null,
    due: "2026-12-04",
    created: "6 Oct 2026",
    updated: "2 weeks ago",
  },
];

type ActivityKind = "created" | "status" | "note" | "owner";

/** What happened to a record, newest first. */
const activity: {
  id: string;
  kind: ActivityKind;
  what: string;
  who: string;
  when: string;
}[] = [
  {
    id: "a4",
    kind: "note",
    what: "Note added",
    who: "Ada Hartley",
    when: "2 hours ago",
  },
  {
    id: "a3",
    kind: "status",
    what: "Status changed to Active",
    who: "Ben Okafor",
    when: "Yesterday",
  },
  {
    id: "a2",
    kind: "owner",
    what: "Owner changed to Ada Hartley",
    who: "Chloe Moreau",
    when: "5 Nov 2026",
  },
  {
    id: "a1",
    kind: "created",
    what: "Record created",
    who: "Chloe Moreau",
    when: "3 Nov 2026",
  },
];

/** The figures on the overview page, with twelve weeks of history each. */
const stats = [
  {
    id: "open",
    title: "Open records",
    value: "128",
    trend: [96, 101, 99, 107, 111, 108, 115, 118, 116, 122, 125, 128],
  },
  {
    id: "new",
    title: "New this month",
    value: "34",
    trend: [18, 22, 19, 25, 21, 27, 24, 30, 26, 29, 31, 34],
  },
  {
    id: "closed",
    title: "Closed this month",
    value: "21",
    trend: [12, 15, 11, 16, 18, 14, 19, 17, 20, 18, 22, 21],
  },
  {
    id: "days",
    title: "Average days to close",
    value: "9",
    trend: [14, 13, 13, 12, 12, 11, 12, 10, 11, 10, 9, 9],
  },
] as const;

const upcoming = [
  {
    id: "u1",
    title: "Quarterly activity report",
    detail: "Due for review",
    when: "Tue 1 Dec",
  },
  { id: "u2", title: "Monthly usage report", detail: "Due", when: "Fri 4 Dec" },
  {
    id: "u3",
    title: "Supplier agreement renewal",
    detail: "Due",
    when: "Fri 11 Dec",
  },
  {
    id: "u4",
    title: "Office lease variation",
    detail: "Due for review",
    when: "Fri 18 Dec",
  },
] as const;

/** Today, as the screens see it: fixed, so every capture shows the same dates. */
const today = "2026-11-24";

const dateFormat = new Intl.DateTimeFormat("en-AU", {
  day: "numeric",
  month: "short",
  year: "numeric",
});

/** An ISO date as people read it, like "11 Dec 2026". */
const formatDate = (iso: string) =>
  dateFormat.format(new Date(`${iso}T00:00:00`));

export {
  activity,
  categories,
  formatDate,
  me,
  people,
  records,
  stats,
  statuses,
  today,
  upcoming,
};
export type { ActivityKind, Category, Person, SampleRecord, StatusId };
```
