'use client'

import type { PipelineStatus } from '../types'

export function SetupTab({ pipelineStatus }: { pipelineStatus: PipelineStatus | null }) {
  return (
    <div className="space-y-6">
      <div>
        <h3 className="text-lg font-semibold text-slate-800 mb-2">Erstkonfiguration - Gitea CI/CD</h3>
        <p className="text-slate-600">
          Anleitung zur Einrichtung der CI/CD Pipeline mit Gitea Actions auf dem Mac Mini Server.
        </p>
      </div>

      {/* Gitea Server Info */}
      <div className="bg-blue-50 p-4 rounded-lg">
        <h4 className="font-medium text-blue-800 mb-3 flex items-center gap-2">
          <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
            <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 12h14M5 12a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v4a2 2 0 01-2 2M5 12a2 2 0 00-2 2v4a2 2 0 002 2h14a2 2 0 002-2v-4a2 2 0 00-2-2" />
          </svg>
          Gitea Server
        </h4>
        <div className="grid grid-cols-1 md:grid-cols-3 gap-4">
          <div className="bg-white p-3 rounded-lg">
            <p className="text-sm text-slate-500">Web-URL</p>
            <p className="font-mono text-blue-700">http://macmini:3003</p>
          </div>
          <div className="bg-white p-3 rounded-lg">
            <p className="text-sm text-slate-500">SSH</p>
            <p className="font-mono text-blue-700">macmini:2222</p>
          </div>
          <div className="bg-white p-3 rounded-lg">
            <p className="text-sm text-slate-500">Status</p>
            <p className={`font-medium ${pipelineStatus?.gitea_connected ? 'text-green-600' : 'text-yellow-600'}`}>
              {pipelineStatus?.gitea_connected ? 'Verbunden' : 'Konfiguration erforderlich'}
            </p>
          </div>
        </div>
      </div>

      {/* Implementierte Komponenten */}
      <div className="bg-slate-50 p-4 rounded-lg">
        <h4 className="font-medium text-slate-800 mb-3">Implementierte Komponenten</h4>
        <div className="overflow-x-auto">
          <table className="min-w-full text-sm">
            <thead>
              <tr className="border-b border-slate-200">
                <th className="text-left py-2 px-3 font-medium text-slate-600">Komponente</th>
                <th className="text-left py-2 px-3 font-medium text-slate-600">Pfad</th>
                <th className="text-left py-2 px-3 font-medium text-slate-600">Beschreibung</th>
              </tr>
            </thead>
            <tbody className="divide-y divide-slate-100">
              <tr>
                <td className="py-2 px-3 font-medium">Gitea Service</td>
                <td className="py-2 px-3"><code className="bg-slate-200 px-1 rounded text-xs">docker-compose.yml</code></td>
                <td className="py-2 px-3 text-slate-600">Gitea 1.22 mit Actions enabled</td>
              </tr>
              <tr>
                <td className="py-2 px-3 font-medium">Gitea Runner</td>
                <td className="py-2 px-3"><code className="bg-slate-200 px-1 rounded text-xs">docker-compose.yml</code></td>
                <td className="py-2 px-3 text-slate-600">act_runner fuer Job-Ausfuehrung</td>
              </tr>
              <tr>
                <td className="py-2 px-3 font-medium">SBOM Workflow</td>
                <td className="py-2 px-3"><code className="bg-slate-200 px-1 rounded text-xs">.gitea/workflows/sbom.yaml</code></td>
                <td className="py-2 px-3 text-slate-600">5 Jobs: generate, scan, license, upload, summary</td>
              </tr>
              <tr>
                <td className="py-2 px-3 font-medium">Backend API</td>
                <td className="py-2 px-3"><code className="bg-slate-200 px-1 rounded text-xs">backend/security_api.py</code></td>
                <td className="py-2 px-3 text-slate-600">SBOM Upload, Pipeline Status, History</td>
              </tr>
              <tr>
                <td className="py-2 px-3 font-medium">Runner Config</td>
                <td className="py-2 px-3"><code className="bg-slate-200 px-1 rounded text-xs">gitea/runner-config.yaml</code></td>
                <td className="py-2 px-3 text-slate-600">Labels: ubuntu-latest, self-hosted</td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>

      {/* Setup Steps */}
      <div className="bg-orange-50 p-4 rounded-lg">
        <h4 className="font-medium text-orange-800 mb-3 flex items-center gap-2">
          <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
            <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01" />
          </svg>
          Setup-Schritte
        </h4>
        <div className="space-y-3">
          <div className="bg-white p-3 rounded-lg">
            <h5 className="font-medium text-slate-800 mb-1">1. Gitea oeffnen</h5>
            <code className="text-sm bg-slate-100 px-2 py-1 rounded">http://macmini:3003</code>
          </div>
          <div className="bg-white p-3 rounded-lg">
            <h5 className="font-medium text-slate-800 mb-1">2. Admin-Account erstellen</h5>
            <p className="text-sm text-slate-600">Username: admin, Email: admin@breakpilot.de</p>
          </div>
          <div className="bg-white p-3 rounded-lg">
            <h5 className="font-medium text-slate-800 mb-1">3. Repository erstellen</h5>
            <p className="text-sm text-slate-600">Name: breakpilot-pwa, Visibility: Private</p>
          </div>
          <div className="bg-white p-3 rounded-lg">
            <h5 className="font-medium text-slate-800 mb-1">4. Actions aktivieren</h5>
            <p className="text-sm text-slate-600">Repository Settings → Actions → Enable Repository Actions</p>
          </div>
          <div className="bg-white p-3 rounded-lg">
            <h5 className="font-medium text-slate-800 mb-1">5. Runner Token erstellen & starten</h5>
            <pre className="text-xs bg-slate-100 p-2 rounded mt-1 overflow-x-auto">
{`export GITEA_RUNNER_TOKEN=<token>
docker compose up -d gitea-runner`}
            </pre>
          </div>
          <div className="bg-white p-3 rounded-lg">
            <h5 className="font-medium text-slate-800 mb-1">6. Repository pushen</h5>
            <pre className="text-xs bg-slate-100 p-2 rounded mt-1 overflow-x-auto">
{`git remote add gitea http://macmini:3003/admin/breakpilot-pwa.git
git push gitea main`}
            </pre>
          </div>
        </div>
      </div>

      {/* Quick Links */}
      <div className="bg-purple-50 p-4 rounded-lg">
        <h4 className="font-medium text-purple-800 mb-3">Quick Links</h4>
        <div className="grid grid-cols-1 md:grid-cols-2 gap-3">
          <a href="http://macmini:3003" target="_blank" rel="noopener noreferrer" className="flex items-center justify-between bg-white p-3 rounded-lg hover:bg-purple-100 transition-colors">
            <div>
              <p className="font-medium text-purple-800">Gitea</p>
              <p className="text-xs text-slate-500">Git Server & CI/CD</p>
            </div>
            <svg className="w-5 h-5 text-purple-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14" />
            </svg>
          </a>
          <a href="http://macmini:3003/admin/breakpilot-pwa/actions" target="_blank" rel="noopener noreferrer" className="flex items-center justify-between bg-white p-3 rounded-lg hover:bg-purple-100 transition-colors">
            <div>
              <p className="font-medium text-purple-800">Pipeline Actions</p>
              <p className="text-xs text-slate-500">Workflow Runs</p>
            </div>
            <svg className="w-5 h-5 text-purple-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14" />
            </svg>
          </a>
        </div>
      </div>
    </div>
  )
}
