'use client'; import { useEffect, useRef, useState } from 'react'; import { useParams } from 'react-router'; import { supabase } from '~/lib/supabase'; // --- A-FRAME/AR.JS CUSTOM ELEMENTS TYPING FIX --- declare module 'react' { namespace JSX { interface IntrinsicElements { 'a-scene': any; 'a-assets': any; 'a-asset-item': any; 'a-marker': any; 'a-entity': any; 'a-text': any; 'model-viewer': React.DetailedHTMLProps< React.HTMLAttributes, HTMLElement > & { src?: string; 'ios-src'?: string; ar?: boolean; 'ar-modes'?: string; 'ar-scale'?: string; 'ar-placement'?: string; 'camera-controls'?: boolean; 'touch-action'?: string; alt?: string; 'shadow-intensity'?: string | number; 'shadow-softness'?: string | number; exposure?: string | number; 'interaction-prompt'?: string; 'min-camera-orbit'?: string; 'max-camera-orbit'?: string; 'camera-orbit'?: string; 'field-of-view'?: string; scale?: string; 'auto-rotate'?: boolean; 'rotation-per-second'?: string; onLoad?: (e: any) => void; 'onAr-status'?: (e: any) => void; 'onModel-visibility'?: (e: any) => void; 'onCamera-change'?: (e: any) => void; }; } } } export default function ARViewer() { const { id } = useParams(); const modelViewerRef = useRef(null); const [asset, setAsset] = useState(null); const [scriptLoaded, setScriptLoaded] = useState(false); useEffect(() => { if (!id) return; const loadAsset = async () => { const { data, error } = await supabase .from('ar_assets') .select('*') .eq('id', id) .single(); console.log('Supabase response:', { data, error }); if (!error && data) { setAsset(data); } }; loadAsset(); }, [id]); useEffect(() => { if (document.getElementById('model-viewer-script')) { setScriptLoaded(true); return; } const script = document.createElement('script'); script.id = 'model-viewer-script'; script.type = 'module'; script.src = 'https://ajax.googleapis.com/ajax/libs/model-viewer/3.4.0/model-viewer.min.js'; script.onload = () => { console.log('model-viewer loaded'); setScriptLoaded(true); }; document.head.appendChild(script); }, []); if (!scriptLoaded) { return (
                Loading AR Viewer…
                {'\n\n'}
                asset: {JSON.stringify(asset, null, 2)}
                {'\n'}
                scriptLoaded: {String(scriptLoaded)}
                {'\n'}
                id: {String(id)}
            
); } return ( { console.error('Model viewer error:', e); console.error('Failed to load:', asset?.glb_url); }} onLoad={() => console.log('Model loaded successfully')} /> //
// Id : {asset?.id} // AR Viewer for asset: {asset?.name} // glb URL: {asset?.glb_url} // usdz URL: {asset?.usdz_url} //
); }