"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { Button } from "@/components/ui/button"; import { Textarea } from "@/components/ui/textarea"; import { Label } from "@/components/ui/label"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, DialogDescription, } from "@/components/ui/dialog"; import { useToast } from "@/hooks/use-toast"; import { Wand2 } from "lucide-react"; // Pre-filled with the Moon homestead house layout — Tony just clicks Create. const DEFAULT_OUTLINE = `House Main floor Entrance Living room Family room Dining room Kitchen Pantry Office Bedroom Guest room Bathroom Laundry room Basement Stairs Laundry room Furnace room Workshop Studio Bathroom Garage Exterior Gutters Exterior lights Roof Outbuildings Brown shed Green shed Wood shed Yard`; export function QuickSetupButton() { const [open, setOpen] = useState(false); const [outline, setOutline] = useState(DEFAULT_OUTLINE); const [groupGarden, setGroupGarden] = useState(true); const [busy, setBusy] = useState(false); const router = useRouter(); const { toast } = useToast(); async function run() { setBusy(true); const res = await fetch("/api/locations/bulk", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ outline, groupGardenUnder: groupGarden ? "Yard" : undefined }), }); setBusy(false); if (!res.ok) { const err = await res.json().catch(() => ({})); toast({ title: "Error", description: err.error ?? "Setup failed.", variant: "destructive" }); return; } const s = await res.json(); toast({ title: "Places set up!", description: `${s.created} created${s.moved ? `, ${s.moved} garden areas grouped under Yard` : ""}.`, }); setOpen(false); router.refresh(); } return ( <> setOpen(true)}> Quick setup Quick setup from an outline Each indent is a sub-location. Re-running is safe — existing places are reused, not duplicated. setOutline(e.target.value)} className="font-mono text-xs" /> setGroupGarden(e.target.checked)} className="accent-[hsl(var(--leaf))]" /> Move existing garden areas (places that hold plants) under “Yard” setOpen(false)}>Cancel {busy ? "Setting up…" : "Create"} > ); }