@extends('layouts.app')

@section('content')
<div class="max-w-3xl mx-auto bg-white shadow-md rounded p-6">
    <h2 class="text-xl font-bold mb-4">Edit Pickup Address</h2>

    @if($errors->any())
        <div class="bg-red-100 text-red-800 px-4 py-2 rounded mb-4">
            <ul class="list-disc list-inside">
                @foreach ($errors->all() as $error)
                    <li>{{ $error }}</li>
                @endforeach
            </ul>
        </div>
    @endif

    <form action="{{ route('import.update_supplier', $address->id) }}" method="POST" class="space-y-4">
        @csrf

        <div>
            <label class="font-semibold">Shipper's Contact Name *</label>
            <input type="text" name="contact_name" class="w-full border rounded px-3 py-2"
                   value="{{ old('contact_name', $address->contact_name) }}" required>
        </div>

        <div>
            <label class="font-semibold">Shipper's Company Name *</label>
            <input type="text" name="company_name" class="w-full border rounded px-3 py-2"
                   value="{{ old('company_name', $address->company_name) }}" required>
        </div>

        <div>
            <label class="font-semibold">Ship From Address 1 *</label>
            <input type="text" name="address1" class="w-full border rounded px-3 py-2"
                   value="{{ old('address1', $address->address1) }}" required>
        </div>

        <div>
            <label class="font-semibold">Ship From Address 2</label>
            <input type="text" name="address2" class="w-full border rounded px-3 py-2"
                   value="{{ old('address2', $address->address2) }}">
        </div>

        <div>
            <label class="font-semibold">Ship From Address 3</label>
            <input type="text" name="address3" class="w-full border rounded px-3 py-2"
                   value="{{ old('address3', $address->address3) }}">
        </div>

        <div>
            <label class="font-semibold">Ship From City *</label>
            <input type="text" name="city" class="w-full border rounded px-3 py-2"
                   value="{{ old('city', $address->city) }}" required>
        </div>

        <div>
            <label class="font-semibold">Ship From Zip/Postal Code *</label>
            <input type="text" name="zip" class="w-full border rounded px-3 py-2"
                   value="{{ old('zip', $address->zip) }}" required>
        </div>

        <div>
            <label class="font-semibold">Ship From Country *</label>
            <select name="country" class="w-full border rounded px-3 py-2" required>
                @foreach($countries as $country)
                    <option value="{{ $country }}"
                        {{ old('country', $address->country) == $country ? 'selected' : '' }}>
                        {{ $country }}
                    </option>
                @endforeach
            </select>
        </div>

        <div>
            <label class="font-semibold">Shipper's Email Address *</label>
            <input type="email" name="email" class="w-full border rounded px-3 py-2"
                   value="{{ old('email', $address->email) }}" required>
        </div>

        <div class="flex gap-4">
            <div class="w-1/3">
                <label class="font-semibold">Country Code *</label>
                <input type="text" name="phone_country_code" class="w-full border rounded px-3 py-2"
                       value="{{ old('phone_country_code', $address->phone_country_code) }}" required>
            </div>

            <div class="w-2/3">
                <label class="font-semibold">Phone Number *</label>
                <input type="text" name="phone_number" class="w-full border rounded px-3 py-2"
                       value="{{ old('phone_number', $address->phone_number) }}" required>
            </div>
        </div>

        <button type="submit"
                class="bg-green-600 text-white px-4 py-2 rounded hover:bg-green-700">
            Update
        </button>
    </form>
</div>
@endsection
