<?php
$f = __DIR__ . '/resources/views/welcome.blade.php';
$c = file_get_contents($f);

$start = strpos($c, '    <header class="welcome-bacheca__masthead"');
$end = strpos($c, '    @if($attivitaAttive->isEmpty())');
if ($start === false || $end === false) {
    echo "markers not found start=$start end=$end\n";
    exit(1);
}

$new = <<<'HTML'
    <header class="welcome-bacheca__masthead" aria-labelledby="bacheca-title">
      <motion class="welcome-bacheca__masthead-row">
        <div class="welcome-bacheca__brand">
          <img
            src="{{ asset('assets/img/logo_fest_L.png') }}"
            alt="{{ config('app.name') }}"
            class="welcome-bacheca__logo"
            width="200"
            height="60"
          >
        </div>
        <div class="welcome-bacheca__masthead-actions">
          <a href="{{ route('login') }}" class="welcome-bacheca__btn welcome-bacheca__btn--ghost">
            <i class="bx bx-log-in"></i>
            Accedi
          </a>
          <a href="{{ $registerUrl }}" class="welcome-bacheca__btn welcome-bacheca__btn--primary">
            Registrati
          </a>
        </div>
      </div>
      <div class="welcome-bacheca__masthead-body">
        <p class="welcome-bacheca__eyebrow">
          <span class="welcome-bacheca__live-dot" aria-hidden="true"></span>
          Bacheca eventi
        </p>
        <h1 id="bacheca-title" class="welcome-bacheca__title">
          Scopri le attività in programma
        </h1>
        <p class="welcome-bacheca__lead">
          Sagre, feste e rassegne attive: tocca un’attività per ordini, prenotazioni e servizi dedicati.
        </p>
      </div>
    </header>

HTML;

$new = str_replace('motion', 'div', $new);

$c = substr($c, 0, $start) . $new . substr($c, $end);

$c = str_replace(
    "          <span class=\"welcome-bacheca__board-count\">{{ \$attivitaAttive->count() }} {{ Str::plural('scheda', \$attivitaAttive->count()) }}</span>\n",
    '',
    $c
);

$c = preg_replace(
    '/\s*@if\(\$attivita->eventi_count > 0\)\s*<span class="welcome-bacheca__card-chip">.*?<\/span>\s*@endif/s',
    '',
    $c
);

file_put_contents($f, $c);
echo "done\n";
