<template>
  <div class="app-container">
    <!-- Header -->
    <header class="header">
      <h1>📄 KSEF PDF Generator</h1>
      <p class="subtitle">Generuj wizualizacje PDF faktur i UPO</p>
    </header>

    <!-- Navigation -->
    <nav class="nav-tabs">
      <button 
        @click="activeTab = 'invoice'"
        :class="{ 'active': activeTab === 'invoice' }"
        class="nav-btn"
      >
        📋 Faktura (FA1/FA2/FA3)
      </button>
      <button 
        @click="activeTab = 'upo'"
        :class="{ 'active': activeTab === 'upo' }"
        class="nav-btn"
      >
        📊 UPO v4.2
      </button>
    </nav>

    <!-- Content -->
    <main class="main-content">
      <!-- Invoice Tab -->
      <section v-if="activeTab === 'invoice'" class="tab-content">
        <InvoiceGenerator 
          @pdf-generated="onPdfGenerated"
          @error="onError"
        />
      </section>

      <!-- UPO Tab -->
      <section v-if="activeTab === 'upo'" class="tab-content">
        <UpoGenerator 
          @pdf-generated="onPdfGenerated"
          @error="onError"
        />
      </section>

      <!-- Status Messages -->
      <div v-if="message.text" :class="['message', message.type]">
        {{ message.text }}
      </div>
    </main>

    <!-- Footer -->
    <footer class="footer">
      <p>KSEF PDF Generator v1.0.0 | Oparte o Vite + Vue 3 + TypeScript</p>
      <p class="copyright">
        © 2026 | Oparte na bibliotece 
        <a href="https://github.com/CIRFMF/ksef-pdf-generator" target="_blank" rel="noopener noreferrer">
          github.com/CIRFMF
        </a>
      </p>
    </footer>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import InvoiceGenerator from './components/InvoiceGenerator.vue';
import UpoGenerator from './components/UpoGenerator.vue';

interface Message {
  text: string;
  type: 'success' | 'error' | 'info';
}

const activeTab = ref<'invoice' | 'upo'>('invoice');
const message = ref<Message>({ text: '', type: 'info' });

const onPdfGenerated = (fileName: string) => {
  message.value = {
    text: `✅ PDF "${fileName}" wygenerowany pomyślnie!`,
    type: 'success',
  };
  setTimeout(() => {
    message.value.text = '';
  }, 5000);
};

const onError = (error: string) => {
  message.value = {
    text: `❌ Błąd: ${error}`,
    type: 'error',
  };
};
</script>

<style scoped>
.app-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

.header {
  background: rgba(0, 0, 0, 0.2);
  color: white;
  padding: 2rem 1rem;
  text-align: center;
  backdrop-filter: blur(10px);
}

.header h1 {
  font-size: 2.5rem;
  margin: 0 0 0.5rem 0;
  font-weight: 700;
}

.subtitle {
  font-size: 1rem;
  margin: 0;
  opacity: 0.9;
}

.nav-tabs {
  display: flex;
  gap: 1rem;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.1);
  justify-content: center;
}

.nav-btn {
  padding: 0.75rem 1.5rem;
  border: 2px solid transparent;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-2px);
}

.nav-btn.active {
  background: white;
  color: #667eea;
  border-color: white;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.main-content {
  flex: 1;
  padding: 2rem 1rem;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.tab-content {
  animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message {
  padding: 1rem;
  border-radius: 8px;
  margin-top: 1rem;
  font-weight: 500;
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.message.success {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.message.error {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.message.info {
  background: #d1ecf1;
  color: #0c5460;
  border: 1px solid #bee5eb;
}

.footer {
  background: rgba(0, 0, 0, 0.2);
  color: white;
  text-align: center;
  padding: 1rem;
  font-size: 0.9rem;
  backdrop-filter: blur(10px);
}

.footer p {
  margin: 0.25rem 0;
}

.copyright {
  font-size: 0.85rem;
  opacity: 0.9;
}

.copyright a {
  color: #a0d0ff;
  text-decoration: none;
  border-bottom: 1px dashed #a0d0ff;
  transition: all 0.3s ease;
}

.copyright a:hover {
  color: white;
  border-bottom-color: white;
}

@media (max-width: 768px) {
  .header h1 {
    font-size: 1.75rem;
  }

  .nav-tabs {
    flex-direction: column;
  }

  .nav-btn {
    width: 100%;
  }

  .main-content {
    padding: 1rem;
  }
}
</style>
