{{define "content"}}
<div class="space-y-6">
    <div class="sm:flex sm:items-center sm:justify-between">
        <h1 class="text-2xl font-bold text-gray-900">{{if .IsNew}}New Customer{{else}}Edit Customer{{end}}</h1>
        <a href="{{if .IsNew}}/customers{{else}}/customers/{{.Customer.ID}}{{end}}" class="text-sm text-gray-500 hover:text-gray-700">&larr; Back</a>
    </div>

    {{if .Error}}
    <div class="rounded-md bg-red-50 p-4">
        <div class="text-sm text-red-700">{{.Error}}</div>
    </div>
    {{end}}

    <div class="bg-white shadow sm:rounded-lg">
        <form class="space-y-6 p-6"
            {{if .IsNew}}
                method="POST" action="/customers" hx-post="/customers"
            {{else}}
                method="POST" action="/customers/{{.Customer.ID}}" hx-put="/customers/{{.Customer.ID}}"
            {{end}}>

            <div class="grid grid-cols-1 gap-6 sm:grid-cols-2">
                <div>
                    <label for="name" class="block text-sm font-medium text-gray-700">Name *</label>
                    <input type="text" name="name" id="name" required value="{{.Customer.Name}}"
                        class="mt-1 block w-full rounded-md border border-gray-300 px-3 py-2 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-indigo-500 sm:text-sm">
                </div>

                <div>
                    <label for="email" class="block text-sm font-medium text-gray-700">Email</label>
                    <input type="email" name="email" id="email" value="{{.Customer.Email}}"
                        class="mt-1 block w-full rounded-md border border-gray-300 px-3 py-2 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-indigo-500 sm:text-sm">
                </div>

                <div>
                    <label for="phone" class="block text-sm font-medium text-gray-700">Phone</label>
                    <input type="tel" name="phone" id="phone" value="{{.Customer.Phone}}"
                        class="mt-1 block w-full rounded-md border border-gray-300 px-3 py-2 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-indigo-500 sm:text-sm">
                </div>
            </div>

            <div>
                <label for="address" class="block text-sm font-medium text-gray-700">Address</label>
                <textarea name="address" id="address" rows="3"
                    class="mt-1 block w-full rounded-md border border-gray-300 px-3 py-2 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-indigo-500 sm:text-sm">{{.Customer.Address}}</textarea>
            </div>

            <div class="flex justify-end space-x-3">
                <a href="{{if .IsNew}}/customers{{else}}/customers/{{.Customer.ID}}{{end}}"
                    class="rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50">Cancel</a>
                <button type="submit"
                    class="rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500">
                    {{if .IsNew}}Create Customer{{else}}Update Customer{{end}}
                </button>
            </div>
        </form>
    </div>
</div>
{{end}}
