'use client'
import {
Popover,
PopoverContent,
PopoverTrigger,
SizableText,
XStack,
YStack,
} from '@hanzo/gui'
import { useState } from 'react'
import { useIdentity } from '../read/asset'
import { Caret, Tick } from '../read/caret'
import { SIZE } from '../read/coin'
import { Field } from '../read/field'
import { Picture } from '../read/picture'
import { paint } from '../material/paint'
import { reach } from '../material/reach'
/**
* Which venue is being read, and the way to read another.
*
* A surface that reaches one chain can print its name and stop. A surface that
* reaches a roster cannot: the name is the control — it says where you are and
* it opens the rest.
*
* Nothing here is ordered, scored or marked as the one to take. The roster's
* own order stands, and a row is a mark and a name and nothing else. Nothing on
* a row reports an indexer either: pressing one scopes a list, moves the
* interface or scopes a holding, and all three work on a venue no indexer
* serves, so a word about availability beside a name would be a fact about
* somewhere else.
*/
/**
* What the panel is painted with, in the token layer's own names.
*
* A text primitive given no colour resolves the engine's `$color`, which the
* installed theme row publishes as near-black — on a black page, invisible.
*/
const { plain, quiet, subtle: tile } = paint
/**
* The narrowest the panel goes.
*
* A floor rather than the width. The names are `nowrap` and the roster is the
* deployment's — one build calls a venue `BNB Smart Chain Testnet` where another
* calls it `BNB Chain` — so a stated width holds one roster's longest line and
* cuts the other's, and a cut name is the one thing this list cannot afford:
* the names are what it is read by.
*/
const WIDTH = 260
/**
* How the mark is drawn: a square with its corners taken off at 30%, the image
* laid into it whole.
*
* The rung is the one an asset's own mark is drawn at beside a pill, so a venue
* and the assets on it are the same size object wherever the two meet.
*
* The room is kept whether or not the build serves the mark, so the names line
* up down the panel. A venue with none draws nothing rather than a stand-in —
* the names are what the list is read by, and an empty square says only that
* something failed to load. The same answer covers a path the resolver did
* state and the fetch then lost, which is why `Picture` holds it: the resolver
* and the network fail differently and read the same on the panel.
*
* `contain` and not `cover`: the marks are square and the box is square, so the
* two agree — and a mark that ever disagreed would be cropped rather than shown
* whole, which is the one thing a brand may not survive.
*/
function Logo({ of, name, size = SIZE.pill }: { of?: string; name?: string; size?: number }) {
const src = useIdentity({ symbol: name, chain: of }).badge
return (
)
}
/** One place a surface can read. */
export interface Venue {
/** The name the mark resolver files this venue's drawing under. */
key: string
/** What it is called, in the roster's own words. */
name: string
}
/**
* The reading with no venue in it, where a caller offers one.
*
* Its name and what pressing it means travel together, because they are one
* fact about one row: a caller that reads one venue at a time has no name for
* that reading and no handler for it, and cannot be given half of either.
*/
export interface Every {
name: string
/** The name its own mark is filed under, where the build serves one for the
* idea of all of them at once. */
key?: string
pick: () => void
}
/**
* One reading: its mark and its name.
*
* A button rather than a link. Nothing here navigates — the screen a person is
* on is the screen they stay on — so an anchor would promise an address it does
* not have.
*/
function Row({
of,
name,
here,
pick,
}: {
of?: string
name: string
here: boolean
pick: () => void
}) {
return (
}
alignItems="center"
gap="$2"
minHeight={reach.plain}
paddingHorizontal="$2"
borderRadius="$4"
cursor="pointer"
// Stated, because a button with no ground takes the browser's own. In a
// dark scheme that is `buttonface`, a mid grey, which paints every row of
// this panel as a slab with a hover fill a reader cannot see arrive.
backgroundColor="transparent"
hoverStyle={{ backgroundColor: tile }}
focusVisibleStyle={paint.focus}
>
{/* Two rungs of ink, and the second is the tick's job rather than a
reading's: the row being shown and every other row.
The alignment is stated because a button is centred by the browser's
own stylesheet, and a name given the whole row otherwise sits in the
middle of it — a column of names on their centres, reading as a column
of nothing. */}
{name}
{/* After the name rather than before it. The mark holds the leading edge,
and a tick that led would push every name one column right of the one
thing a reader is scanning. */}
{here ? : null}
)
}
/**
* The venues, and — where a caller reads across them — the reading that is all
* of them.
*
* A field and the list, and nothing else. The field narrows and never chooses:
* a roster past a handful is where a reader scans rather than reads, and three
* letters is the difference between finding a venue and finding out that the
* panel scrolls.
*/
function List({
of,
on,
pick,
every,
done,
search,
none,
label,
}: {
of: readonly Venue[]
on: Venue | null
pick: (v: Venue) => void
every?: Every
done?: () => void
search: string
none: string
label: string
}) {
const [query, setQuery] = useState('')
/** By name, which is what a reader is looking at. Not by key: the key is what
* the mark is filed under and the name is what the row says, and a list that
* answers to a word nobody can see is a list with two spellings of every
* venue. */
const named = (name: string) => name.toLowerCase().includes(query.trim().toLowerCase())
const shown = of.filter((v) => named(v.name))
const all = every && named(every.name) ? every : null
return (
{/* Narrowing rather than choosing, so the label is bound and not drawn: a
heading over a list this short would be the loudest thing in the panel,
and the placeholder already says what typing here does.
On the page's own ground and without an edge, which is what a field cut
into a sheet is. A fill inside a hairline on a floating panel reads as
a second panel laid on the first. */}
{/* The reading with no venue in it leads: it is what the list opens on,
and a row for "no filter" sitting under the filtered ones reads as
one more venue. */}
{all ? (
{
all.pick()
done?.()
}}
/>
) : null}
{shown.map((v) => (
{
pick(v)
done?.()
}}
/>
))}
{/* A word that matches nothing. Said rather than left blank: an empty
panel under a field somebody has just typed into reads as a panel
that broke. */}
{all === null && shown.length === 0 ? (
{none}
) : null}
)
}
/**
* The control: a mark, the venue's name where there is room for it, and a caret.
*
* One shape, two grounds. On the band it carries no outline, because the word
* is the readout and it should not stop being one to become a control; in a
* page's own toolbar it stands as a hairline pill beside the other controls on
* that row.
*/
export function Venues({
of = [],
on = null,
pick,
every,
compact = false,
pill = false,
label = 'Network',
search = 'Search networks',
none = 'No results',
}: {
/** The roster, in its own order. */
of?: readonly Venue[]
/** Which venue the control reads as current, or null for every venue at
* once. */
on?: Venue | null
/** What choosing one means. */
pick?: (v: Venue) => void
/** The reading with no venue in it, where the caller reads across them. */
every?: Every
/** The mark and the caret alone, for a row with no width for a name. */
compact?: boolean
/** Drawn as one of a page's own controls rather than as part of the band. */
pill?: boolean
/** What pressing the control is about. A bare venue name in a row that also
* holds an account says nothing about which of the two it names. */
label?: string
/** What the field says it does. */
search?: string
/** What a query matching nothing says. */
none?: string
}) {
const [open, setOpen] = useState(false)
const chosen = pick ?? (() => {})
return (
}
flexDirection="row"
alignItems="center"
gap="$1.5"
minHeight={reach.plain}
paddingHorizontal="$2"
flexShrink={0}
cursor="pointer"
// The engine gives a trigger a filled ground. On the band the control
// stands on the band's own, with a fill arriving only under a pointer;
// in a page's toolbar it stands as a pill.
{...(pill
? paint.pill
: { borderRadius: '$4', backgroundColor: 'transparent', borderWidth: 0 })}
hoverStyle={{ backgroundColor: tile }}
focusVisibleStyle={paint.focus}
>
{/* On a page's row both glyphs are drawn at the rung a mark takes;
on the band the logo carries the panel's own square, and the word
runs a rung under the one a page's row sets. */}
{compact ? null : (
{on?.name ?? every?.name}
)}
{/* Only while it is open. The panel keeps a query of its own, and one
mounted behind a shut popover is a field holding last time's word. */}
{open ? (
setOpen(false)}
search={search}
none={none}
label={label}
/>
) : null}
)
}