<script setup>
import { Head, Link, useForm } from '@inertiajs/vue3';
import PublicLayout from '@/Layouts/PublicLayout.vue';

const form = useForm({
  email: '',
  password: '',
  remember: false,
});

const submit = () => {
  form.post('/storesight/login', { onFinish: () => form.reset('password') });
};
</script>

<template>
  <PublicLayout>
    <Head title="Login" />
    <div class="min-h-[60vh] flex items-center justify-center py-12 px-4">
      <div class="w-full max-w-md">
        <div class="text-center mb-8">
          <h1 class="text-3xl font-bold text-gray-900">Welcome back</h1>
          <p class="text-gray-500 mt-2">Sign in to your StoreSight AI account</p>
        </div>
        <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-8">
          <form @submit.prevent="submit" class="space-y-5">
            <div>
              <label class="block text-sm font-medium text-gray-700 mb-1">Email</label>
              <input v-model="form.email" type="email" class="w-full px-4 py-3 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-primary focus:border-primary outline-none" placeholder="you@example.com">
              <p v-if="form.errors.email" class="text-red-500 text-xs mt-1">{{ form.errors.email }}</p>
            </div>
            <div>
              <label class="block text-sm font-medium text-gray-700 mb-1">Password</label>
              <input v-model="form.password" type="password" class="w-full px-4 py-3 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-primary focus:border-primary outline-none" placeholder="Your password">
              <p v-if="form.errors.password" class="text-red-500 text-xs mt-1">{{ form.errors.password }}</p>
            </div>
            <div class="flex items-center justify-between">
              <label class="flex items-center">
                <input v-model="form.remember" type="checkbox" class="w-4 h-4 text-primary border-gray-300 rounded focus:ring-primary">
                <span class="ml-2 text-sm text-gray-600">Remember me</span>
              </label>
              <a href="#" class="text-sm text-primary hover:underline">Forgot password?</a>
            </div>
            <button type="submit" :disabled="form.processing" class="w-full bg-primary text-white font-semibold py-3 rounded-lg hover:bg-primary-dark transition disabled:opacity-50">
              {{ form.processing ? 'Signing in...' : 'Sign In' }}
            </button>
          </form>
          <p class="text-center text-sm text-gray-500 mt-6">
            Don't have an account? <Link :href="$url('/register')" class="text-primary font-medium hover:underline">Register</Link>
          </p>
        </div>
      </div>
    </div>
  </PublicLayout>
</template>
