import { useQuery } from '@tanstack/react-query';
import { FolderGit2Icon, LockIcon } from 'lucide-react';
import { Badge } from '#/components/atoms/badge.jsx';
import { Notice } from '#/components/atoms/notice.jsx';
import { RowIcon } from '#/components/atoms/row-icon.jsx';
import { EmptyState } from '#/components/molecules/empty-state.jsx';
import { ListRow } from '#/components/molecules/list-row.jsx';
import { xrpcGet } from '#/lib/api.js';
import { bytes, timeAgo } from '#/lib/format.js';
import { queryKeys } from '#/lib/query.js';
import { NewRepoDialog } from '#/pages/git-new-repo.jsx';
/** One line summarizing a repository's shape. */
function repoSummary(repo) {
if (repo.branches === 0 && repo.bundles === 0) return 'nothing pushed yet';
const parts = [
`${repo.branches} ${repo.branches === 1 ? 'branch' : 'branches'}`,
];
if (repo.tags > 0) {
parts.push(`${repo.tags} ${repo.tags === 1 ? 'tag' : 'tags'}`);
}
parts.push(bytes(repo.size));
if (repo.updatedAt) parts.push(`pushed ${timeAgo(repo.updatedAt)}`);
return parts.join(' ยท ');
}
/** The repository page URL, carrying the space for a private repository. */
export function repoHref(repo) {
const base = `/account/git/${encodeURIComponent(repo.name)}`;
return repo.space ? `${base}?space=${encodeURIComponent(repo.space)}` : base;
}
/**
* @param {{data: Object, onNavigate: (href: string) => void}} props
*/
export function GitPage({ data: account, onNavigate }) {
const { data, error } = useQuery({
queryKey: queryKeys.gitRepos,
queryFn: () => xrpcGet('dev.pdsjs.git.listRepos'),
});
if (error) {
return