@extends('backEnd.layouts.master')
@section('title','Add Delivery Man')
@section('content')
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="page-title-box d-flex align-items-center justify-content-between">
                <h4 class="page-title"><i class="fe-truck me-2"></i>Add Delivery Man</h4>
                <a href="{{ route('admin.delivery-men.index') }}" class="btn btn-secondary btn-sm rounded-pill shadow-sm"><i class="fe-arrow-left me-1"></i>Back</a>
            </div>
        </div>
    </div>
    <div class="row justify-content-center">
        <div class="col-lg-8">
            <div class="card shadow-sm border-0">
                <div class="card-body">
                    <form action="{{ route('admin.delivery-men.store') }}" method="POST" enctype="multipart/form-data">
                        @csrf
                        <div class="row g-3">
                            <div class="col-md-6">
                                <label class="form-label fw-semibold">Full Name *</label>
                                <input type="text" name="name" class="form-control @error('name') is-invalid @enderror" value="{{ old('name') }}" placeholder="e.g. Rahim Uddin" required>
                                @error('name') <div class="invalid-feedback">{{ $message }}</div> @enderror
                            </div>
                            <div class="col-md-6">
                                <label class="form-label fw-semibold">Phone *</label>
                                <input type="text" name="phone" class="form-control @error('phone') is-invalid @enderror" value="{{ old('phone') }}" placeholder="01XXXXXXXXX" required>
                                @error('phone') <div class="invalid-feedback">{{ $message }}</div> @enderror
                            </div>
                            <div class="col-md-6">
                                <label class="form-label fw-semibold">Email</label>
                                <input type="email" name="email" class="form-control" value="{{ old('email') }}" placeholder="Optional">
                            </div>
                            <div class="col-md-6">
                                <label class="form-label fw-semibold">Status *</label>
                                <select name="status" class="form-select" required>
                                    <option value="active" {{ old('status')=='active'?'selected':'' }}>Active</option>
                                    <option value="inactive" {{ old('status')=='inactive'?'selected':'' }}>Inactive</option>
                                </select>
                            </div>
                            <div class="col-md-6">
                                <label class="form-label fw-semibold">Vehicle Type</label>
                                <input type="text" name="vehicle_type" class="form-control" value="{{ old('vehicle_type') }}" placeholder="e.g. Bike, Van, Cycle">
                            </div>
                            <div class="col-md-6">
                                <label class="form-label fw-semibold">Vehicle Number</label>
                                <input type="text" name="vehicle_number" class="form-control" value="{{ old('vehicle_number') }}" placeholder="e.g. DHA-1234">
                            </div>
                            <div class="col-md-6">
                                <label class="form-label fw-semibold">Platform Commission Percent (%)</label>
                                <input type="number" step="0.01" name="platform_commission_percent" class="form-control" value="{{ old('platform_commission_percent', 0) }}" placeholder="e.g. 10.00">
                            </div>

                            <div class="col-12">
                                <label class="form-label fw-semibold">Assigned Delivery Zones *</label>
                                <div class="row g-2 border rounded p-3 bg-light">
                                    @php
                                        $allZones = \App\Models\LocalDeliveryZone::where('is_enabled', 1)->get();
                                    @endphp
                                    @forelse($allZones as $z)
                                        <div class="col-md-4">
                                            <div class="form-check">
                                                <input type="checkbox" name="zone_ids[]" value="{{ $z->id }}" id="zone_{{ $z->id }}" class="form-check-input"
                                                       {{ is_array(old('zone_ids')) && in_array($z->id, old('zone_ids')) ? 'checked' : '' }}>
                                                <label for="zone_{{ $z->id }}" class="form-check-label fw-medium">{{ $z->name }} <span class="text-muted">({{ $z->radius }} km)</span></label>
                                            </div>
                                        </div>
                                    @empty
                                        <div class="col-12 text-muted">No active local delivery zones found. Add zones in Local Delivery settings first.</div>
                                    @endforelse
                                </div>
                            </div>

                            <div class="col-12">
                                <label class="form-label fw-semibold">Photo</label>
                                <input type="file" name="photo" class="form-control" accept="image/*">
                            </div>
                            <div class="col-12 text-end mt-4">
                                <button type="submit" class="btn btn-primary px-5 shadow-sm"><i class="fe-save me-1"></i>Save Delivery Man</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
