import { createXRStore } from '@react-three/xr';

function loadXRFeatures() {
  const defaults = {
    handTracking: true,
    planeDetection: true,
    hitTest: true,
    domOverlay: true,
    anchors: true,
    meshDetection: false,
    depthSensing: false,
    layers: false,
    bodyTracking: false,
    lightEstimation: false,
  };
  try {
    const raw = localStorage.getItem('xrFeatures_v2');
    if (raw) return { ...defaults, ...JSON.parse(raw) };
  } catch (err) {
    console.warn('[XR] Falha ao ler xrFeatures do localStorage:', err);
  }
  return defaults;
}

const _xrf = loadXRFeatures();

export const xrStore = createXRStore({
  hand: { left: true, right: true },
  controller: { left: true, right: true },
  handTracking: _xrf.handTracking,
  planeDetection: _xrf.planeDetection,
  hitTest: _xrf.hitTest,
  domOverlay: _xrf.domOverlay,
  anchors: _xrf.anchors,
  meshDetection: _xrf.meshDetection,
  depthSensing: _xrf.depthSensing,
  layers: _xrf.layers,
  bodyTracking: _xrf.bodyTracking,
});
