// Universal "back" button: pops the in-memory route history (window.__goBack
// set up in app.jsx). Falls back to the Home route if history is empty.
function BackButton({ lang, label, style }) {
  const onBack = () => {
    if (typeof window.__goBack === 'function') {
      window.__goBack();
    } else {
      // Fallback if app.jsx hasn't wired history (shouldn't happen in v2)
      window.location.href = '/migronis2/';
    }
  };
  return (
    <button onClick={onBack}
            style={{
              color: 'var(--fg-muted)', fontSize: 13,
              background: 'transparent', border: 0, cursor: 'pointer',
              padding: '4px 0',
              display: 'inline-flex', alignItems: 'center', gap: 6,
              ...(style || {}),
            }}>
      ← {label || (lang === 'ru' ? 'Назад' : 'Back')}
    </button>
  );
}

window.BackButton = BackButton;
