'use client'
import { Button, SizableText, type GetThemeValueForKey } from '@hanzo/gui'
import type { ReactNode } from 'react'
import { away, useWalk } from './link'
import { paint } from '../material/paint'
import { reach } from '../material/reach'
import { weight } from '../material/weight'
/**
* The one press a screen is built around.
*
* A ticket ends in it and a wizard step ends in it, and they are the same
* object: the largest control on the surface, carrying either the verb or the
* sentence saying why the verb is not available yet. Written twice they came
* apart at the corner radius and at what a blocked one looks like, which is the
* difference between "this is the button" and "this is a button".
*
* Nothing to press is a state rather than a disabled attribute. A disabled
* button leaves the tab order, and the label is the whole reason this exists:
* somebody who cannot reach it never learns that an amount is what is missing.
* So it stays reachable, says what is unmet, and does nothing.
*
* It either does something or goes somewhere, and the two are one control. A
* screen with no page at it ends in the way back to the door and a position
* that is not there ends in the way back to the list; those wear the same
* ground, the same rung and the same corner as the verb on a card, and written
* separately they drifted at exactly the four properties this comment records.
* The arm that goes somewhere is an anchor, so a middle click and "open in new
* tab" do what the reader meant and a plain click stays inside the app.
*
* Measured at 1440: 55 tall, cut at 20, the verb at 18 and 535 — `major` and
* `roundest` are the rungs those quantize to. The label stays at full strength
* when there is nothing to press: a blocked `Select supported tokens` is pure
* white, and so is a blocked `Connect wallet`. What says blocked is the ground
* under it, not the ink on it.
*
* Where it goes somewhere the size drops to 16 and the label decides the width
* — a 404's own way out measures 510 across and a missing position's 158 — so
* the size follows the arm rather than a prop nobody would know how to set.
*
* The ground is a step above whatever the surface is: a card drawn as an
* outline on black lifts this to the ink at eight hundredths, and a build whose
* cards are filled to that same value and copies the number has a button with
* no edge at all — a verb floating on a sheet.
*/
/**
* The two grounds this stands on, in the type this engine's style props take.
*
* The blocked one is the ink at eight hundredths, which is a `color-mix` rather
* than a theme key: the component looks the name up, falls through to whatever
* it was handed, and paints it. The type is narrower than the code, so the
* values say so — the same cast the weight ladder takes, for the same reason.
*/
const ground = {
lit: paint.solid as GetThemeValueForKey<'backgroundColor'>,
blocked: paint.act as unknown as GetThemeValueForKey<'backgroundColor'>,
}
/** Somewhere to go, and whether it spans the column or hugs its label. */
export type Goes = { to: string; across?: boolean }
export type Does = {
/** Every condition holds and the label is the verb itself. */
ready: boolean
/** There is nothing a press would do. */
inert: boolean
/**
* Somebody else has it — a wallet, most often.
*
* It blocks the press as `inert` does, and here rather than at each call
* site: a second press while a wallet holds the first is a second
* transaction, and a screen that has to remember to say both is a screen
* that will one day say one.
*/
busy?: boolean
onPress: () => void
}
export function Verb(props: { label: ReactNode } & (Goes | Does)) {
const walk = useWalk()
const goes = 'to' in props
/**
* Whether a press does anything now. Nothing left to do and somebody else
* already doing it are one answer: what separates them is the sentence the
* button carries, not what pressing it does.
*/
const stuck = !goes && (props.inert || props.busy === true)
const lit = goes || (props.ready && !stuck)
const arm = goes
? {
// Where it goes is read off the address, by the one rule the family
// has for that question. A `to` that turns out to be somebody else's
// origin is not handed to the router, and it opens the way any foreign
// address does: a new tab, the opener withheld.
render: away(props.to) ? (
) : (
),
alignSelf: props.across ? ('stretch' as const) : ('center' as const),
}
: {
width: '100%' as const,
'aria-disabled': stuck,
'aria-busy': props.busy,
onPress: props.onPress,
}
return (
)
}