<template>
  <section class="landing">
    <div class="landing-container">
      <div class="landing-content animate-splash">
        <div class="terminal-duck-container">
          <div class="terminal-wrapper">
            <DuckTerminal />
          </div>
          <div class="duck-container">
            <div class="duck-placeholder">
              <img
                src="/duck.gif"             
                alt="Canard dansant"
                class="dancing-duck"
                @load="duckLoaded = true"
                :class="{ 'duck-loaded': duckLoaded }"
                @error="() => console.error('Duck image failed to load')"
              />
              <div class="duck-loading" v-if="!duckLoaded">
                <span class="loading-text">Chargement du canard...</span>
              </div>
            </div>
          </div>
        </div>
        <div class="landing-buttons">
          <button @click="scrollToExperience" class="btn btn-primary">
            Voir mon parcours
            <svg
              xmlns="http://www.w3.org/2000/svg"
              width="24"
              height="24"
              viewBox="0 0 24 24"
              fill="none"
              stroke="currentColor"
              stroke-width="2"
              stroke-linecap="round"
              stroke-linejoin="round"
              class="btn-icon"
            >
              <path d="M12 5v14"></path>
              <path d="m19 12-7 7-7-7"></path>
            </svg>
          </button>
          <a href="mailto:contact@maric.ro" class="btn btn-secondary">Me contacter</a>
        </div>
      </div>
    </div>

    <div id="experience-section">
      <Experience />
    </div>
  </section>
</template>

<script setup>
import { ref, onMounted } from 'vue';

const duckLoaded = ref(false);

onMounted(() => {
  const img = new Image();
  img.src = '/duck.gif';
  
  if (img.complete) {
    duckLoaded.value = true;
  }
  
  img.onload = () => {
    duckLoaded.value = true;
  };
  
  setTimeout(() => {
    duckLoaded.value = true;
  }, 3000);
});

const scrollToExperience = () => {
  const experienceSection = document.getElementById('experience-section');
  if (experienceSection) {
    experienceSection.scrollIntoView({ behavior: 'smooth' });
  }
};
</script>

<style>
.landing {
  padding: 4rem 1rem;
  min-height: 80vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
}

.landing-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 90%;
  margin: 0 auto;
  z-index: 10;
}

.landing-content {
  text-align: center;
  width: 100%;
  margin-bottom: 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.terminal-duck-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  margin-bottom: 1.5rem;
}

.terminal-wrapper {
  position: relative;
  z-index: 1;
  width: 100%;
}

.duck-container {
  margin-top: 1.5rem;
  width: 320px;
  display: flex;
  justify-content: center;
}

.landing-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 2.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  height: 2.75rem;
  border-radius: 0.375rem;
  padding: 0 2rem;
  transition: all 0.2s;
  cursor: pointer;
  text-decoration: none;
}

.btn-primary {
  background-color: var(--duck-yellow);
  color: black;
  border: none;
}

.btn-primary:hover {
  background-color: rgba(255, 219, 88, 0.9);
}

.btn-secondary {
  background-color: transparent;
  border: 1px solid var(--duck-blue);
  color: var(--duck-blue);
}

.btn-secondary:hover {
  background-color: rgba(70, 130, 180, 0.1);
}

.btn-icon {
  width: 1rem;
  height: 1rem;
  margin-left: 0.5rem;
}

.duck-svg {
  width: 5rem;
  height: 5rem;
}

.dancing-duck {
  width: 320px;
  height: 320px;
  object-fit: contain;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.duck-placeholder {
  width: 320px;
  height: 320px;
  position: relative;
  border-radius: 0.5rem;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

.duck-loaded {
  opacity: 1;
}

.duck-loading {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 0.5rem;
}

.loading-text {
  color: var(--duck-yellow);
  font-family: "Courier New", monospace;
  font-size: 1rem;
  animation: duck-bounce 1.5s infinite;
}

@keyframes duck-bounce {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}

@media (min-width: 768px) {
  .landing-content {
    text-align: left;
    align-items: flex-start;
  }

  .terminal-duck-container {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
  }

  .terminal-wrapper {
    width: 620px;
    margin-right: 2rem;
  }

  .duck-container {
    width: 320px;
    margin-top: 0;
    flex-shrink: 0;
  }

  .landing-buttons {
    justify-content: flex-start;
  }

  .duck-placeholder {
    width: 320px;
    height: 320px;
    flex-shrink: 0;
  }
}

@media (max-width: 767px) {
  .terminal-wrapper {
    min-width: 100%;
    max-width: 100%;
    width: 100%;
  }

  .duck-container,
  .duck-placeholder {
    width: 280px;
    height: 280px;
  }

  .dancing-duck {
    width: 280px;
    height: 280px;
  }
}
</style>