// Shared helpers and context

const { createContext, useContext, useState, useEffect, useRef, useMemo } = React;

const RouteCtx = createContext({ route: 'home', go: () => {} });
const TweaksCtx = createContext({ tweaks: window.__TWEAKS__, setTweak: () => {} });

function useRoute(){ return useContext(RouteCtx); }
function useTweaks(){ return useContext(TweaksCtx); }

// Persist tweaks upstream to the host for the Tweaks toolbar toggle
function persistTweak(key, value){
  try {
    window.parent.postMessage({ type: '__edit_mode_set_keys', edits: { [key]: value } }, '*');
  } catch(e){}
}

// Logo switcher — always uses the red PNG (with transparency) so it adapts to any theme
function Logo({ size = 34 }){
  return <img src="assets/logo-red.png" alt="byace" style={{ height: size, width: 'auto' }} />;
}

Object.assign(window, { RouteCtx, TweaksCtx, useRoute, useTweaks, persistTweak, Logo });
