<script setup lang="ts">
import { ref, onMounted } from 'vue';
import TaskList from './components/TaskList.vue';
import HotKeySettingsDialog from './components/HotKeySettingsDialog.vue';

const toastMessage = ref('');
const toastType = ref<'error' | 'success'>('error');
const showToast = ref(false);

const showToastNotification = (message: string, type: 'error' | 'success' = 'error') => {
  toastMessage.value = message;
  toastType.value = type;
  showToast.value = true;
  setTimeout(() => {
    showToast.value = false;
  }, 5000);
};

onMounted(() => {
  // Expose to window for global access (e.g. from axios interceptor)
  (window as any).showToast = showToastNotification;
});
</script>

<template>
  <div class="app">
    <TaskList />
    <HotKeySettingsDialog />
    
    <!-- Global Toast Notification -->
    <Transition name="toast">
      <div v-if="showToast" class="toast" :class="toastType">
        <div class="toast-content">
          <span class="toast-icon">{{ toastType === 'error' ? '❌' : '✅' }}</span>
          <span class="toast-message">{{ toastMessage }}</span>
        </div>
        <button @click="showToast = false" class="toast-close">×</button>
      </div>
    </Transition>
  </div>
</template>

<style>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
    sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.app {
  min-height: 100vh;
  width: 100%;
  background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
}

h1 {
  text-align: center;
  color: #1f2937;
  font-size: 32px;
  font-weight: 700;
  margin-bottom: 32px;
}

/* Toast Styles */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 20px;
  border-radius: 12px;
  background: white;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 9999;
  min-width: 300px;
  max-width: 90%;
  border-left: 4px solid #ef4444;
}

.toast.success {
  border-left-color: #22c55e;
}

.toast.error {
  border-left-color: #ef4444;
}

.toast-content {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.toast-message {
  font-size: 14px;
  color: #1f2937;
  font-weight: 500;
  white-space: pre-line;
}

.toast-close {
  background: transparent;
  border: none;
  font-size: 20px;
  color: #9ca3af;
  cursor: pointer;
  padding: 0 4px;
}

.toast-close:hover {
  color: #4b5563;
}

/* Toast Transition */
.toast-enter-active,
.toast-leave-active {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toast-enter-from {
  opacity: 0;
  transform: translate(-50%, -20px);
}

.toast-leave-to {
  opacity: 0;
  transform: translate(-50%, -20px);
}
</style>
