import { Heading, Paragraph, YStack } from '@hanzo/gui'
import { useId, type ReactNode } from 'react'
import { paint } from '../material/paint'
/**
* The surface a page is built out of, and the block a surface is built out of.
*
* Two components, because there are two facts and they are independent: whether
* a thing stands on a surface, and whether it is named. Braided, that reads as
* three components — a named surface, a named block, an unnamed surface — and
* two of the three were written, in two files, under one name. A page of them
* then had a titled section from one file and an untitled sheet from the other
* drawing different insets and different corners while claiming to be the same
* object.
*
* So: `Part` is the naming, `Panel` is the surface, and a `Panel` given a title
* is a `Panel` holding one `Part`. That composition is the whole of the
* difference the two files disagreed about, and it is now spelled once.
*/
/**
* Where a line of prose stops being readable, at the published body size.
*
* One number for the family. A panel's sentence, a notice's, a page header's
* and an empty screen's are the same measure, and three of the four had their
* own copy of it. Here rather than in the material because it is not a colour,
* a rung or a radius — it is the width of a line of type, which is a fact about
* reading rather than about paint.
*/
export const measure = 560
/**
* A surface, or a block set into one. The reference draws these two and no
* third: a card frames on the page's own ground inside a hairline, a well
* recedes onto the darker ground and draws no line at all.
*
* Which one a thing takes is the whole of what says whether it is a surface or
* something set into a surface, so it is stated rather than inferred.
*/
export type Face = 'card' | 'well'
/**
* A surface and the corner it is cut at, together, because the pair is what
* makes the face read: a card at the well's radius sits inside its own line,
* and a well at the card's radius bleeds past the block it is set into.
*/
const FACE = {
card: { ...paint.card, borderRadius: paint.corner },
well: { ...paint.well, borderRadius: paint.roundest },
} as const
/**
* A block, under the name of what it holds.
*
* The heading is an element rather than a styled line, because a page of six of
* these is a page a screen reader moves through by heading — unnamed, they are
* six regions whose only way in is to read every word of the one before.
*
* `id` names the heading so a control below it can be labelled by the same
* words a reader sees, rather than by a second copy of them that drifts.
*
* The heading and its sentence set solid, with the air under the pair rather
* than inside it: two lines that name one thing read as one block.
*/
export function Part({
id,
title,
note,
level = 'h2',
children,
}: {
id?: string
title: ReactNode
/** What a person needs to know before reading on. One sentence or none. */
note?: ReactNode
/** Its rank in the page's outline. A block inside a block is an `h3`. */
level?: 'h2' | 'h3'
children?: ReactNode
}) {
return (
{title}
{note ? (
{note}
) : null}
{children}
)
}
/**
* A surface, and what stands on it.
*
* Titled, it is a section of a page and says so: the heading names the region,
* and one `useId` binds the two so the name a reader sees is the name the
* region has. Untitled, it is the sheet a task is done on — a wizard's step,
* a ticket's body — and the things inside it are `Part`s carrying their own
* names.
*
* One inset and one rhythm either way. A panel holding a single fact list and
* a sheet holding three questions are the same object at different fills, and
* two spellings of one inset is how a page ends up with two column edges.
*/
export function Panel({
title,
note,
level,
face = 'card',
children,
}: {
title?: ReactNode
note?: ReactNode
level?: 'h2' | 'h3'
face?: Face
children?: ReactNode
}) {
const named = useId()
return (
{title ? (
{children}
) : (
children
)}
)
}