@extends('Admin.layout.app')

@section('title', 'Update Customer')

@section('page-title', 'Update Customer')

@section('content')

<div class="container-fluid">

    <div class="card">

        <div class="card-header bg-white">
            <h5 class="mb-0">
                <i class="fas fa-user-plus text-primary me-2"></i>
                Update Customer {{($customers->name ?? '')}}
            </h5>
        </div>

        <div class="card-body">

            <form action="{{route ('admin.customers.update_customer',$customers->id)}}" method="POST">

                @csrf

                <div class="row">

                    <!-- Customer Name -->
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Customer Name <span class="text-danger">*</span></label>
                        <input type="text"
                               name="name"
                               class="form-control @error('name') is-invalid @enderror"
                               value="{{ old('name',$customers->name ?? '')  }}"
                               placeholder="Enter customer name">

                        @error('name')
                            <div class="invalid-feedback">{{ $message }}</div>
                        @enderror
                        
                        <input type="text"
                               name="customer_name_urdu"
                               class="form-control @error('name') is-invalid @enderror"
                               value="{{ old('name',$customers->urdu_name ?? '')  }}"
                               placeholder="Enter customer name">
                    </div>

                    <!-- Phone -->
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Phone Number <span class="text-danger">*</span></label>
                        <input type="text"
                               name="phone"
                               class="form-control @error('phone') is-invalid @enderror"
                               value="{{ old('phone',$customers->phone ?? '') }}"
                               placeholder="03XXXXXXXXX">

                        @error('phone')
                            <div class="invalid-feedback">{{ $message }}</div>
                        @enderror
                    </div>
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Alternate Phone  <span class="text-danger">*</span></label>
                        <input type="text"
                               name="phone2"
                               class="form-control @error('phone2') is-invalid @enderror"
                               value="{{ old('phone',$customers->phone2 ?? '') }}"
                               placeholder="03XXXXXXXXX">

                        @error('phone')
                            <div class="invalid-feedback">{{ $message }}</div>
                        @enderror
                    </div>

                    <!-- Email -->
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Email</label>
                        <input type="email"
                               name="email"
                               class="form-control @error('email') is-invalid @enderror"
                               value="{{ old('email',$customers->email ?? '') }}"
                               placeholder="example@gmail.com">

                        @error('email')
                            <div class="invalid-feedback">{{ $message }}</div>
                        @enderror
                    </div>
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Status</label>
                    
                        <select name="status" class="form-select @error('status') is-invalid @enderror">
                            <option value="1" {{ old('status', $customers->status) == 1 ? 'selected' : '' }}>
                                Active
                            </option>
                            <option value="0" {{ old('status', $customers->status) == 0 ? 'selected' : '' }}>
                                Inactive
                            </option>
                        </select>
                    
                        @error('status')
                            <div class="invalid-feedback">{{ $message }}</div>
                        @enderror
                    </div>

                    <!-- CNIC -->
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Customer Type</label>
                    
                        <select name="customer_type" class="form-select @error('customer_type') is-invalid @enderror">
                    
                            <option value="regular"
                                {{ old('customer_type', $customers->customer_type) == 'regular' ? 'selected' : '' }}>
                                Regular
                            </option>
                    
                            <option value="walkin"
                                {{ old('customer_type', $customers->customer_type) == 'walkin' ? 'selected' : '' }}>
                                Walk-in
                            </option>
                    
                            <option value="wholesale"
                                {{ old('customer_type', $customers->customer_type) == 'wholesale' ? 'selected' : '' }}>
                                Wholesale
                            </option>
                    
                        </select>
                    
                        @error('customer_type')
                            <div class="invalid-feedback">{{ $message }}</div>
                        @enderror
                    </div>

                    <!-- Address -->
                    <div class="col-md-12 mb-3">
                        <label class="form-label">Address</label>
                        <textarea name="address"
                                  rows="3"
                                  class="form-control @error('address') is-invalid @enderror"
                                  placeholder="Enter customer address">{{ old('address', $customers->address ?? '') }}</textarea>

                        @error('address')
                            <div class="invalid-feedback">{{ $message }}</div>
                        @enderror
                    </div>
                    <div class="col-md-12 mb-3">
                        <label class="form-label">Address urdu</label>
                        <textarea name="address_urdu"
                                  rows="3"
                                  class="form-control @error('address') is-invalid @enderror"
                                  placeholder="Enter customer address">{{ old('address', $customers->urdu_address ?? '') }}</textarea>

                        @error('address')
                            <div class="invalid-feedback">{{ $message }}</div>
                        @enderror
                    </div>

                    <!-- Status -->
                    

                </div>

                <hr>

                <div class="d-flex justify-content-end">

                    <a href="{{ route('admin.customers.list') }}"
                       class="btn btn-secondary me-2">
                        <i class="fas fa-arrow-left me-1"></i>
                        Back
                    </a>

                    <button type="submit" class="btn btn-primary">
                        <i class="fas fa-save me-1"></i>
                        Save Customer
                    </button>

                </div>

            </form>

        </div>

    </div>

</div>

@endsection