<script setup lang="ts">
import AdminLayout from '@/Layouts/AdminLayout.vue';
import admin from '@/routes/admin';
import { Head, useForm } from '@inertiajs/vue3';
import { ArrowLeft } from 'lucide-vue-next';

const form = useForm({
    customer_name: '',
    phone_number: '',
    device_model: '',
    problem: '',
    charge_amount: '',
    status: 'pending',
});

const submit = () => {
    form.post(admin.repairs.store.url());
};
</script>

<template>
    <AdminLayout>
        <Head title="Add Repair" />

        <div class="animate-fade-in space-y-8 pb-12">
            <div class="flex items-center gap-4">
                <Link
                    :href="admin.repairs.index.url()"
                    class="rounded-xl border border-slate-200 bg-white p-3 shadow-sm transition-colors hover:bg-slate-50 dark:border-slate-700 dark:bg-slate-800 dark:hover:bg-slate-700"
                >
                    <ArrowLeft :size="20" />
                </Link>
                <div>
                    <h1 class="text-3xl font-black tracking-tight text-slate-900 dark:text-white">Add Repair</h1>
                    <p class="mt-1 text-sm text-slate-500 dark:text-slate-400">Create a new repair or unlock service.</p>
                </div>
            </div>

            <form @submit.prevent="submit" class="rounded-4xl border border-slate-200/60 bg-white p-8 shadow-sm dark:border-slate-700 dark:bg-slate-800">
                <div class="grid grid-cols-1 gap-6 md:grid-cols-2">
                    <div>
                        <label class="block text-sm font-bold text-slate-700 dark:text-slate-300">Customer Name</label>
                        <input
                            v-model="form.customer_name"
                            type="text"
                            class="mt-1 block w-full rounded-lg border border-slate-300 px-3 py-2 shadow-sm focus:border-brand-500 focus:outline-none focus:ring-1 focus:ring-brand-500 dark:border-slate-600 dark:bg-slate-700 dark:text-white"
                            required
                        />
                        <div v-if="form.errors.customer_name" class="mt-1 text-sm text-red-600">{{ form.errors.customer_name }}</div>
                    </div>
                    <div>
                        <label class="block text-sm font-bold text-slate-700 dark:text-slate-300">Phone Number</label>
                        <input
                            v-model="form.phone_number"
                            type="text"
                            class="mt-1 block w-full rounded-lg border border-slate-300 px-3 py-2 shadow-sm focus:border-brand-500 focus:outline-none focus:ring-1 focus:ring-brand-500 dark:border-slate-600 dark:bg-slate-700 dark:text-white"
                            required
                        />
                        <div v-if="form.errors.phone_number" class="mt-1 text-sm text-red-600">{{ form.errors.phone_number }}</div>
                    </div>
                    <div>
                        <label class="block text-sm font-bold text-slate-700 dark:text-slate-300">Device Model</label>
                        <input
                            v-model="form.device_model"
                            type="text"
                            class="mt-1 block w-full rounded-lg border border-slate-300 px-3 py-2 shadow-sm focus:border-brand-500 focus:outline-none focus:ring-1 focus:ring-brand-500 dark:border-slate-600 dark:bg-slate-700 dark:text-white"
                            required
                        />
                        <div v-if="form.errors.device_model" class="mt-1 text-sm text-red-600">{{ form.errors.device_model }}</div>
                    </div>
                    <div>
                        <label class="block text-sm font-bold text-slate-700 dark:text-slate-300">Problem</label>
                        <select
                            v-model="form.problem"
                            class="mt-1 block w-full rounded-lg border border-slate-300 px-3 py-2 shadow-sm focus:border-brand-500 focus:outline-none focus:ring-1 focus:ring-brand-500 dark:border-slate-600 dark:bg-slate-700 dark:text-white"
                            required
                        >
                            <option value="">Select Problem</option>
                            <option value="Repair">Repair</option>
                            <option value="Unlock">Unlock</option>
                            <option value="iCloud">iCloud</option>
                            <option value="FRP">FRP</option>
                            <option value="Network">Network</option>
                        </select>
                        <div v-if="form.errors.problem" class="mt-1 text-sm text-red-600">{{ form.errors.problem }}</div>
                    </div>
                    <div>
                        <label class="block text-sm font-bold text-slate-700 dark:text-slate-300">Charge Amount</label>
                        <input
                            v-model="form.charge_amount"
                            type="number"
                            step="0.01"
                            class="mt-1 block w-full rounded-lg border border-slate-300 px-3 py-2 shadow-sm focus:border-brand-500 focus:outline-none focus:ring-1 focus:ring-brand-500 dark:border-slate-600 dark:bg-slate-700 dark:text-white"
                            required
                        />
                        <div v-if="form.errors.charge_amount" class="mt-1 text-sm text-red-600">{{ form.errors.charge_amount }}</div>
                    </div>
                    <div>
                        <label class="block text-sm font-bold text-slate-700 dark:text-slate-300">Status</label>
                        <select
                            v-model="form.status"
                            class="mt-1 block w-full rounded-lg border border-slate-300 px-3 py-2 shadow-sm focus:border-brand-500 focus:outline-none focus:ring-1 focus:ring-brand-500 dark:border-slate-600 dark:bg-slate-700 dark:text-white"
                            required
                        >
                            <option value="pending">Pending</option>
                            <option value="done">Done</option>
                        </select>
                        <div v-if="form.errors.status" class="mt-1 text-sm text-red-600">{{ form.errors.status }}</div>
                    </div>
                </div>
                <div class="mt-6 flex justify-end">
                    <button
                        type="submit"
                        :disabled="form.processing"
                        class="rounded-xl bg-brand-600 px-6 py-3 text-sm font-bold text-white transition-colors hover:bg-brand-700 disabled:opacity-50"
                    >
                        {{ form.processing ? 'Saving...' : 'Save Repair' }}
                    </button>
                </div>
            </form>
        </div>
    </AdminLayout>
</template>