@extends('layouts.app')
@section('title','Edit Lead — ' . $lead->name)
@section('header','Edit Lead')

@section('content')
<div style="max-width: 800px;">
    <div style="font-size: 13px; color: #8e9ab4; margin-bottom: 8px;">
        <a href="{{ route('leads.show', $lead) }}" style="color: #6d59ff; text-decoration: none;">← Back to Lead Details</a>
    </div>

    <div class="panel" style="margin-top: 0;">
        <h2 style="margin-top: 0; padding-bottom: 12px; border-bottom: 1px solid #202b47; color: #fff;">
            Update Lead: {{ $lead->name }}
        </h2>

        <form method="POST" action="{{ route('leads.update', $lead) }}">
            @csrf
            @method('PUT')

            <div class="grid2">
                <div>
                    <label>Lead / Contact Name *</label>
                    <input type="text" name="name" value="{{ old('name', $lead->name) }}" required>
                </div>

                <div>
                    <label>Company Name</label>
                    <input type="text" name="company" value="{{ old('company', $lead->company) }}">
                </div>

                <div>
                    <label>Phone Number</label>
                    <input type="text" name="phone" value="{{ old('phone', $lead->phone) }}">
                </div>

                <div>
                    <label>Email Address</label>
                    <input type="email" name="email" value="{{ old('email', $lead->email) }}">
                </div>

                <div>
                    <label>Lead Source *</label>
                    <select name="source" required>
                        <option value="manual" {{ $lead->source == 'manual' ? 'selected' : '' }}>Manual Entry</option>
                        <option value="website" {{ $lead->source == 'website' ? 'selected' : '' }}>Website Form</option>
                        <option value="facebook" {{ $lead->source == 'facebook' ? 'selected' : '' }}>Facebook Lead Ads</option>
                        <option value="instagram" {{ $lead->source == 'instagram' ? 'selected' : '' }}>Instagram Ads</option>
                        <option value="whatsapp" {{ $lead->source == 'whatsapp' ? 'selected' : '' }}>WhatsApp Inquiry</option>
                        <option value="referral" {{ $lead->source == 'referral' ? 'selected' : '' }}>Referral</option>
                    </select>
                </div>

                <div>
                    <label>Pipeline Status *</label>
                    <select name="status" required>
                        <option value="new" {{ $lead->status == 'new' ? 'selected' : '' }}>New</option>
                        <option value="contacted" {{ $lead->status == 'contacted' ? 'selected' : '' }}>Contacted</option>
                        <option value="qualified" {{ $lead->status == 'qualified' ? 'selected' : '' }}>Qualified</option>
                        <option value="won" {{ $lead->status == 'won' ? 'selected' : '' }}>Won</option>
                        <option value="lost" {{ $lead->status == 'lost' ? 'selected' : '' }}>Lost</option>
                    </select>
                </div>

                <div>
                    <label>Assign Executive</label>
                    <select name="assigned_to">
                        <option value="">Unassigned</option>
                        @if(isset($users))
                            @foreach($users as $user)
                                <option value="{{ $user->id }}" {{ $lead->assigned_to == $user->id ? 'selected' : '' }}>
                                    {{ $user->name }} ({{ ucfirst($user->role) }})
                                </option>
                            @endforeach
                        @endif
                    </select>
                </div>

                <div>
                    <label>Expected Deal Value (₹)</label>
                    <input type="number" step="0.01" name="expected_value" value="{{ old('expected_value', $lead->expected_value) }}">
                </div>
            </div>

            <div style="margin-top: 16px;">
                <label>Lead Notes & Description</label>
                <textarea name="notes">{{ old('notes', $lead->notes) }}</textarea>
            </div>

            <div style="display: flex; gap: 12px; margin-top: 24px; padding-top: 16px; border-top: 1px solid #202b47;">
                <button type="submit" class="btn">Save Changes</button>
                <a href="{{ route('leads.show', $lead) }}" class="btn btn-secondary" style="text-decoration: none;">Cancel</a>
            </div>
        </form>
    </div>
</div>
@endsection
