<script setup>
import { Head, useForm } from '@inertiajs/vue3';
import { tokens, FONT } from '@/Components/Diabetix/palette.js';

const props = defineProps({
    email: { type: String, required: true },
    token: { type: String, required: true },
});

const tok = tokens('mint');
const font = FONT;

const form = useForm({
    token: props.token,
    email: props.email,
    password: '',
    password_confirmation: '',
});

function submit() {
    form.post(route('password.store'), {
        onFinish: () => form.reset('password', 'password_confirmation'),
    });
}

function inputStyle() {
    return {
        width: '100%', padding: '12px 14px', borderRadius: '14px',
        border: '1.5px solid ' + tok.border, background: tok.bg,
        fontSize: '15px', color: tok.text, outline: 'none', boxSizing: 'border-box',
    };
}
</script>

<template>
    <Head title="Réinitialiser le mot de passe" />

    <div :style="{ minHeight: '100vh', background: '#eeece8', fontFamily: font.body, display: 'flex', alignItems: 'center', justifyContent: 'center', padding: '24px' }">
        <div :style="{ width: '100%', maxWidth: '400px' }">

            <div style="text-align:center;margin-bottom:32px;">
                <div :style="{ width: '64px', height: '64px', borderRadius: '50%', background: tok.light, border: '2px solid ' + tok.primary, display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: '28px', margin: '0 auto 14px' }">🔒</div>
                <div :style="{ fontFamily: font.title, fontSize: '24px', fontWeight: 700, color: tok.text }">Nouveau mot de passe</div>
                <div :style="{ fontSize: '13px', color: tok.muted, marginTop: '4px' }">Choisissez un mot de passe sécurisé.</div>
            </div>

            <div :style="{ background: tok.white, borderRadius: '24px', padding: '28px 24px', boxShadow: '0 4px 24px rgba(42,53,51,0.10)' }">
                <form @submit.prevent="submit">
                    <div style="margin-bottom:14px;">
                        <label :style="{ fontSize: '11px', color: tok.muted, fontWeight: 600, display: 'block', marginBottom: '6px', textTransform: 'uppercase', letterSpacing: '0.7px' }">Adresse e-mail</label>
                        <input v-model="form.email" type="email" required autocomplete="username" :style="inputStyle()" />
                        <span v-if="form.errors.email" :style="{ fontSize: '11px', color: '#c43', marginTop: '4px', display: 'block' }">{{ form.errors.email }}</span>
                    </div>

                    <div style="margin-bottom:14px;">
                        <label :style="{ fontSize: '11px', color: tok.muted, fontWeight: 600, display: 'block', marginBottom: '6px', textTransform: 'uppercase', letterSpacing: '0.7px' }">Nouveau mot de passe</label>
                        <input v-model="form.password" type="password" required autofocus autocomplete="new-password" :style="inputStyle()" />
                        <span v-if="form.errors.password" :style="{ fontSize: '11px', color: '#c43', marginTop: '4px', display: 'block' }">{{ form.errors.password }}</span>
                    </div>

                    <div style="margin-bottom:24px;">
                        <label :style="{ fontSize: '11px', color: tok.muted, fontWeight: 600, display: 'block', marginBottom: '6px', textTransform: 'uppercase', letterSpacing: '0.7px' }">Confirmer le mot de passe</label>
                        <input v-model="form.password_confirmation" type="password" required autocomplete="new-password" :style="inputStyle()" />
                        <span v-if="form.errors.password_confirmation" :style="{ fontSize: '11px', color: '#c43', marginTop: '4px', display: 'block' }">{{ form.errors.password_confirmation }}</span>
                    </div>

                    <button type="submit" :disabled="form.processing"
                        :style="{
                            width: '100%', padding: '15px', background: tok.primary, color: '#fff',
                            borderRadius: '16px', border: 'none', fontSize: '15px', fontWeight: 700,
                            cursor: form.processing ? 'not-allowed' : 'pointer',
                            opacity: form.processing ? 0.6 : 1,
                            boxShadow: '0 6px 18px rgba(123,191,181,0.35)',
                        }">
                        {{ form.processing ? 'Enregistrement…' : 'Réinitialiser le mot de passe' }}
                    </button>
                </form>
            </div>

        </div>
    </div>
</template>
