<template>
  <div id="crm-app">
    <header class="app-header">
      <div class="header-left">
        <h1>📊 myCRM</h1>
      </div>
      
      <nav class="header-nav">
        <router-link to="/">Dashboard</router-link>
        <router-link to="/contacts">Kontakte</router-link>
        <router-link to="/companies">Unternehmen</router-link>
        <router-link to="/deals">Deals</router-link>
      </nav>
      
      <div class="header-right">
        <div class="user-info" v-if="authStore.isAuthenticated">
          <i class="pi pi-user"></i>
          <span>{{ authStore.fullName }}</span>
          <Button 
            icon="pi pi-sign-out" 
            severity="secondary" 
            text 
            size="small"
            @click="handleLogout"
            label="Logout"
          />
        </div>
      </div>
    </header>
    
    <main class="app-main">
      <router-view />
    </main>
    
    <footer class="app-footer">
      <p>&copy; {{ currentYear }} myCRM - Moderne CRM-Lösung</p>
    </footer>
  </div>
</template>

<script setup>
import { computed } from 'vue';
import { useAuthStore } from './stores/auth';
import Button from 'primevue/button';

const authStore = useAuthStore();
const currentYear = computed(() => new Date().getFullYear());

const handleLogout = () => {
  if (confirm('Möchten Sie sich wirklich abmelden?')) {
    authStore.logout();
  }
};
</script>

<style scoped lang="scss">
.app-header {
  background: #2563eb;
  color: white;
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  
  .header-left {
    display: flex;
    align-items: center;
    
    h1 {
      margin: 0;
      font-size: 1.5rem;
    }
  }
  
  .header-nav {
    display: flex;
    gap: 1.5rem;
    flex: 1;
    justify-content: center;
    
    a {
      color: white;
      text-decoration: none;
      padding: 0.5rem 1rem;
      border-radius: 4px;
      transition: background 0.2s;
      
      &:hover, &.router-link-active {
        background: rgba(255, 255, 255, 0.2);
      }
    }
  }
  
  .header-right {
    .user-info {
      display: flex;
      align-items: center;
      gap: 0.75rem;
      background: rgba(255, 255, 255, 0.1);
      padding: 0.5rem 1rem;
      border-radius: 6px;
      
      i {
        font-size: 1.1rem;
      }
      
      span {
        font-weight: 500;
      }
    }
  }
}

.app-main {
  min-height: calc(100vh - 150px);
  padding: 2rem;
  max-width: 1400px;
  margin: 0 auto;
}

.app-footer {
  background: #f3f4f6;
  padding: 1rem 2rem;
  text-align: center;
  color: #6b7280;
  border-top: 1px solid #e5e7eb;
}
</style>
