import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { Pencil, Trash2 } from 'lucide-react';
import { useState } from 'react';
import { Button } from '#/components/atoms/button.jsx';
import { Card } from '#/components/atoms/card.jsx';
import { Link } from '#/components/atoms/link.jsx';
import { Notice } from '#/components/atoms/notice.jsx';
import { Skeleton } from '#/components/atoms/skeleton.jsx';
import { AtUri } from '#/components/molecules/at-uri.jsx';
import { Copyable } from '#/components/molecules/copyable.jsx';
import { JsonView } from '#/components/molecules/json-view.jsx';
import { RepoScope } from '#/components/molecules/repo-scope.jsx';
import { ago, fileSize, rkeyTime } from '#/lib/format.js';
import { href } from '#/lib/navigation.jsx';
import { useSession } from '#/lib/session.jsx';
import { deleteRecord, getBlob, getRecord, putRecord } from '#/lib/spaces.js';
/**
* One blob a record references. The PDS serves it with a disposition that stops
* it from being displayed in the PDS's own origin, so the bytes are read here
* and shown from an object URL belonging to this page.
*/
function BlobPreview({ space, repo, cid, onClose }) {
const { session } = useSession();
const { data, error, isPending } = useQuery({
queryKey: ['blob', space, repo, cid],
queryFn: () => getBlob(session, { space, repo }, cid),
retry: false,
});
return (