import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './App';
import './index.css';

const path = window.location.pathname;

if (path.startsWith('/app')) {
  // Clear the body and add root div
  document.body.innerHTML = '<div id="root"></div>';
  const rootElement = document.getElementById('root');
  if (rootElement) {
    createRoot(rootElement).render(
      <React.StrictMode>
        <App />
      </React.StrictMode>
    );
  }
} else {
  // We are on the landing page, inject the login button
  const nav = document.getElementById('nav-menu');
  if (nav) {
    const loginBtn = document.createElement('a');
    loginBtn.href = '/app';
    loginBtn.className = 'btn';
    loginBtn.style.marginLeft = '10px';
    loginBtn.style.backgroundColor = '#444';
    loginBtn.innerHTML = '<i class="fa-solid fa-user"></i> Área do Cliente';
    nav.appendChild(loginBtn);
  }
}
