import { useInspectorOptions } from "../lib/inspectorStore"; import { useEffect, useState } from "react"; import { useQuery } from "@tanstack/react-query"; import { Link } from "react-router"; import { loci } from "@botanica/genetics"; import { stages, type GrowthStage, type Background } from "@botanica/renderer"; import type { PlantDto } from "@botanica/shared"; import { PlantPreview } from "./PlantPreview"; import { ExportActions } from "./ExportActions"; import { QueryMessage } from "./QueryMessage"; import { locusLabels } from "./GenomeEditor"; import { api } from "../lib/api"; import { request } from "../lib/api"; import type { CollectionStats, BreedingEventDto } from "@botanica/shared"; import { PlantGameActions } from "./PlantGameActions"; export function PlantRecord({ plant: p, onParent, scope = "owned", }: { plant: PlantDto; onParent?: (id: string) => void; scope?: "owned" | "demo"; }) { const { stage, background, set } = useInspectorOptions(); const setStage = (stage: GrowthStage) => set({ stage }), setBackground = (background: Background) => set({ background }); const stats = useQuery({ queryKey: ["collection-stats", scope], queryFn: () => scope === "demo" ? request("/demo/collection/stats") : api.stats(), }), birth = useQuery({ queryKey: ["birth", p.id, scope], queryFn: () => scope === "demo" ? request<{ event: BreedingEventDto | null }>( "/demo/plants/" + p.id + "/birth", ) : api.birth(p.id), }); useEffect(() => { setStage("flowering"); }, [p.id]); return (
{p.phenotype.pigment} · {p.phenotype.leafShape} ·{" "} {p.phenotype.leafPattern}
); }