// solid-js/html wrapProps auto-invokes zero-arg functions passed as component
// props, so handlers must use a parameter. Readers must accept either the
// unwrapped value or an accessor function.
export type MaybeAccessor<T> = T | (() => T);

export function readAccessor<T>(value: MaybeAccessor<T> | undefined | null, fallback: T): T {
    if (value == null) return fallback;
    return typeof value === "function" ? (value as () => T)() : value;
}

/** Reactive PageLayout/PageHeader prop — survives wrapProps (uses a dummy param). */
export function accessor<T>(fn: () => T): (_: unknown) => T {
    return (_: unknown) => fn();
}
