<?php

use App\Models\LandingPage;

class LandingPageSeeder extends \Hyperf\Database\Seeders\Seeder
{
    public function run(): void
    {
        foreach ($this->templates() as $tpl) {
            $existing = LandingPage::where('title', $tpl['title'])->first();
            if ($existing) {
                $existing->update([
                    'html_content' => $tpl['html_content'],
                    'description' => $tpl['description'],
                ]);
            } else {
                LandingPage::create([
                    'title' => $tpl['title'],
                    'html_content' => $tpl['html_content'],
                    'description' => $tpl['description'],
                    'is_active' => false,
                ]);
            }
        }
    }

    private function templates(): array
    {
        return [
            [
                'title' => 'Barangay System — Default Landing',
                'description' => 'Default landing page for the Barangay Management & Governance Platform.',
                'html_content' => $this->defaultTemplate(),
            ],
        ];
    }

    private function defaultTemplate(): string
    {
        return <<<'HTML'
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Barangay System</title>
  <style>
    * { box-sizing: border-box; margin: 0; padding: 0; }
    body { font-family: 'Segoe UI', sans-serif; background: #f0f4ff; color: #1a1a2e; }
    header { background: #1a3c6e; color: #fff; padding: 20px 40px; display: flex; align-items: center; gap: 16px; }
    header img { height: 48px; }
    header h1 { font-size: 1.5rem; }
    .hero { background: linear-gradient(135deg, #1a3c6e 0%, #2563eb 100%); color: #fff; text-align: center; padding: 80px 20px; }
    .hero h2 { font-size: 2.5rem; margin-bottom: 16px; }
    .hero p { font-size: 1.1rem; opacity: 0.9; max-width: 600px; margin: 0 auto 32px; }
    .hero a { display: inline-block; background: #fff; color: #1a3c6e; font-weight: 700; padding: 14px 36px; border-radius: 8px; text-decoration: none; font-size: 1rem; }
    .services { display: flex; flex-wrap: wrap; justify-content: center; gap: 24px; padding: 60px 40px; background: #fff; }
    .service-card { background: #f0f4ff; border-radius: 12px; padding: 28px 24px; width: 220px; text-align: center; }
    .service-card .icon { font-size: 2.5rem; margin-bottom: 12px; }
    .service-card h3 { font-size: 1rem; margin-bottom: 8px; color: #1a3c6e; }
    .service-card p { font-size: 0.85rem; color: #555; }
    footer { background: #1a3c6e; color: #fff; text-align: center; padding: 24px; font-size: 0.85rem; }
  </style>
</head>
<body>
  <header>
    <h1>Barangay System</h1>
  </header>
  <section class="hero">
    <h2>Serving Our Community</h2>
    <p>Request barangay certificates, report incidents, and access government services — online, anytime.</p>
    <a href="/login">Access Portal</a>
  </section>
  <section class="services">
    <div class="service-card">
      <div class="icon">📄</div>
      <h3>Certificate Requests</h3>
      <p>Barangay Clearance, Residency, Indigency, Good Moral & more</p>
    </div>
    <div class="service-card">
      <div class="icon">📋</div>
      <h3>Blotter Filing</h3>
      <p>File incidents and track hearing schedules online</p>
    </div>
    <div class="service-card">
      <div class="icon">👥</div>
      <h3>Resident Records</h3>
      <p>Manage resident and household information</p>
    </div>
    <div class="service-card">
      <div class="icon">📢</div>
      <h3>Announcements</h3>
      <p>Stay updated on barangay news and events</p>
    </div>
  </section>
  <footer>
    &copy; 2026 Barangay System. All rights reserved.
  </footer>
</body>
</html>
HTML;
    }
}
