import type { Child, FC } from 'hono/jsx';
import type { SkillCard as SkillCardRow } from '../lib/skills';
import { categoryName, platformName, splitPlatforms } from '../lib/skills';
import type { SendOption } from '../lib/install';
import { nextTier, tierFor, tierProgress } from '../lib/tiers';
import { compactNumber, timeAgo } from '../lib/util';
import { ownRepo } from '../lib/hosts';
import { defaultAvatar, icon, spot, tierArt } from './art';
type AvatarUser = { id?: string; handle: string; avatar_key: string | null; avatar_fallback: string | null };
export const Avatar: FC<{ user: AvatarUser; size?: number }> = ({ user, size = 40 }) => {
if (user.avatar_key) {
const small = size <= 96 ? user.avatar_key.replace(/(\.\w+)$/, '-128$1') : user.avatar_key;
return ;
}
if (user.avatar_fallback) return ;
return defaultAvatar(user.id ?? user.handle, size);
};
export const TierBadge: FC<{ seeds: number; size?: number; label?: boolean }> = ({ seeds, size = 22, label = true }) => {
const t = tierFor(seeds);
return (
{tierArt(t.key, size)}
{label ? {t.name} : null}
);
};
export const TierProgress: FC<{ seeds: number }> = ({ seeds }) => {
const next = nextTier(seeds);
return (
{next ? `${(next.threshold - seeds).toLocaleString('en-US')} Seeds to ${next.name}` : 'Top tier reached'}
);
};
export const LikeButton: FC<{ skill: { id: string; likes_count: number; liked?: number | null; owner_id: string }; viewerId?: string | null; large?: boolean }> = ({ skill, viewerId, large }) => {
const own = viewerId === skill.owner_id;
const cls = `like${skill.liked ? ' is-liked' : ''}${large ? ' like-lg' : ''}`;
if (own) {
return (
{icon('leaf', large ? 20 : 17)}
{compactNumber(skill.likes_count)}
);
}
return (
{icon('leaf', large ? 20 : 17)}
{icon('leaf-filled', large ? 20 : 17)}
{compactNumber(skill.likes_count)}
likes
);
};
export const Stars: FC<{ skill: { github_repo: string | null; stars: number | null; repo_fetched_at: number | null; repo_unavailable: number | null } }> = ({ skill }) => {
// Skillfarm's own repos are on Branchwell, which has no stars.
if (!skill.github_repo || ownRepo(skill.github_repo) || skill.stars == null) return null;
const tip = `Stars on ${skill.github_repo}, checked ${timeAgo(skill.repo_fetched_at)}${skill.repo_unavailable ? '. Repo unavailable.' : ''}`;
return (
{icon('star', 17)}
{compactNumber(skill.stars)}
repo stars on {skill.github_repo}
);
};
/** Marks Sprout wherever a tier badge would sit for a member. */
export const AgentBadge: FC<{ label?: string }> = ({ label = 'Site agent' }) => (
{icon('plug', 13)} {label}
);
export const SkillCard: FC<{ skill: SkillCardRow; viewerId?: string | null; showState?: boolean }> = ({ skill, viewerId, showState }) => {
const href = `/skills/${skill.owner_handle}/${skill.slug}`;
const t = tierFor(skill.owner_seeds);
const pick = skill.kind === 'link';
const cat = categoryName(skill.category);
return (
{showState && skill.state !== 'live' ?
{stateLabel(skill.state)} : null}
{pick ?
Sprout's pick : null}
{skill.summary}
{cat ? {cat} : null}
{splitPlatforms(skill.platforms).slice(0, 4).map((p) => (
{platformName(p)}
))}
);
};
export function stateLabel(state: string): string {
return ({ pending: 'In review', live: 'Live', rejected: 'Not approved', hidden: 'Hidden', removed: 'Removed' } as Record)[state] ?? state;
}
export const Empty: FC<{ title: string; children?: Child; art?: 'empty' | 'plant' | 'harvest' | 'tend' | 'mcp' }> = ({ title, children, art = 'empty' }) => (
{spot(art)}
{title}
{children}
);
export const Copy: FC<{ text: string; label?: string }> = ({ text, label }) => (
{text}
{icon('copy', 16)}
{label ?? 'Copy'}
);
/**
* "Send to agent": one button that hands a prompt to the visitor's agent, and a picker that remembers which agent that is.
* Without script the button still works for the first agent, because it is a plain link.
*/
export const SendToAgent: FC<{ options: SendOption[]; small?: boolean; block?: boolean }> = ({ options, small, block }) => {
if (!options.length) return null;
const first = options[0];
return (
);
};
export const Pager: FC<{ page: number; hasMore: boolean; base: string }> = ({ page, hasMore, base }) => {
if (page <= 1 && !hasMore) return null;
const sep = base.includes('?') ? '&' : '?';
return (
);
};