import { emitter, useScene } from "@pascal-app/core"; import { useViewer } from "@pascal-app/viewer"; import { Camera, Download, Save, Trash2, Upload } from "lucide-react"; import { useRef, useState } from "react"; import { Button } from "@/components/ui/primitives/button"; import useEditor from "@/store/use-editor"; import { AudioSettingsDialog } from "./audio-settings-dialog"; import { usePropertyStore } from "@/features/community/lib/properties/store"; export function SettingsPanel() { const fileInputRef = useRef(null); const nodes = useScene((state) => state.nodes); const rootNodeIds = useScene((state) => state.rootNodeIds); const setScene = useScene((state) => state.setScene); const clearScene = useScene((state) => state.clearScene); const resetSelection = useViewer((state) => state.resetSelection); const exportScene = useViewer((state) => state.exportScene); const setPhase = useEditor((state) => state.setPhase); const activeProperty = usePropertyStore((state) => state.activeProperty); const [isGeneratingThumbnail, setIsGeneratingThumbnail] = useState(false); const propertyId = activeProperty?.id; const isLocalProperty = false; // Store only contains cloud properties const handleExport = async () => { if (exportScene) { await exportScene(); } }; const handleSaveBuild = () => { const sceneData = { nodes, rootNodeIds }; const json = JSON.stringify(sceneData, null, 2); const blob = new Blob([json], { type: "application/json" }); const url = URL.createObjectURL(blob); const link = document.createElement("a"); link.href = url; const date = new Date().toISOString().split("T")[0]; link.download = `layout_${date}.json`; link.click(); URL.revokeObjectURL(url); }; const handleFileLoad = (e: React.ChangeEvent) => { const file = e.target.files?.[0]; if (!file) return; const reader = new FileReader(); reader.onload = (event) => { try { const data = JSON.parse(event.target?.result as string); if (data.nodes && data.rootNodeIds) { setScene(data.nodes, data.rootNodeIds); resetSelection(); setPhase("site"); } } catch (err) { console.error("Failed to load build:", err); } }; reader.readAsText(file); // Reset input so the same file can be loaded again e.target.value = ""; }; const handleResetToDefault = () => { clearScene(); resetSelection(); setPhase("site"); }; const handleGenerateThumbnail = () => { if (!propertyId) { console.error('❌ No property ID found'); return; } console.log('🎯 Generate thumbnail clicked for property:', propertyId); setIsGeneratingThumbnail(true); emitter.emit('camera-controls:generate-thumbnail', { propertyId }); console.log('📤 Event emitted with property ID:', propertyId); // Reset loading state after a delay (thumbnail generation is async) setTimeout(() => setIsGeneratingThumbnail(false), 3000); }; return (
{/* Export Section */}
{/* Thumbnail Section (only for cloud properties) */} {propertyId && !isLocalProperty && (
)} {/* Save/Load Section */}
{/* Audio Section */}
{/* Danger Zone */}
); }