@extends('layouts.layoutMaster')

@section('title', __('Edit Customer'))

@section('content')
<x-breadcrumb
    :title="__('Edit Customer')"
    :breadcrumbs="[
        ['name' => __('System Core'), 'url' => route('systemcore.dashboard')],
        ['name' => __('Customers'), 'url' => route('systemcore.customers.index')],
        ['name' => __('Edit')]
    ]"
/>

<div class="row">
    <div class="col-md-12">
        <form id="customerForm" action="{{ route('systemcore.customers.update', $customer->id) }}" method="POST">
            @csrf
            @method('PUT')

            <div class="card mb-4">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <h5 class="mb-0">{{ __('Customer Information') }}</h5>
                    <span class="badge bg-label-primary">{{ $customer->customer_code }}</span>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-6 mb-3">
                            <label for="name" class="form-label">{{ __('Name') }} <span class="text-danger">*</span></label>
                            <input type="text" class="form-control @error('name') is-invalid @enderror"
                                   id="name" name="name" value="{{ old('name', $customer->name) }}" required>
                            @error('name')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="col-md-6 mb-3">
                            <label for="company_name" class="form-label">{{ __('Company Name') }}</label>
                            <input type="text" class="form-control @error('company_name') is-invalid @enderror"
                                   id="company_name" name="company_name" value="{{ old('company_name', $customer->company_name) }}">
                            @error('company_name')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="col-md-6 mb-3">
                            <label for="customer_type" class="form-label">{{ __('Customer Type') }} <span class="text-danger">*</span></label>
                            <select class="form-select @error('customer_type') is-invalid @enderror"
                                    id="customer_type" name="customer_type" required>
                                <option value="">{{ __('Select Type') }}</option>
                                <option value="b2b" {{ old('customer_type', $customer->customer_type) == 'b2b' ? 'selected' : '' }}>{{ __('B2B') }}</option>
                                <option value="b2c" {{ old('customer_type', $customer->customer_type) == 'b2c' ? 'selected' : '' }}>{{ __('B2C') }}</option>
                                <option value="distributor" {{ old('customer_type', $customer->customer_type) == 'distributor' ? 'selected' : '' }}>{{ __('Distributor') }}</option>
                                <option value="prospect" {{ old('customer_type', $customer->customer_type) == 'prospect' ? 'selected' : '' }}>{{ __('Prospect') }}</option>
                                <option value="lead" {{ old('customer_type', $customer->customer_type) == 'lead' ? 'selected' : '' }}>{{ __('Lead') }}</option>
                            </select>
                            @error('customer_type')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="col-md-6 mb-3">
                            <label for="status" class="form-label">{{ __('Status') }} <span class="text-danger">*</span></label>
                            <select class="form-select @error('status') is-invalid @enderror"
                                    id="status" name="status" required>
                                <option value="active" {{ old('status', $customer->status) == 'active' ? 'selected' : '' }}>{{ __('Active') }}</option>
                                <option value="inactive" {{ old('status', $customer->status) == 'inactive' ? 'selected' : '' }}>{{ __('Inactive') }}</option>
                                <option value="pending" {{ old('status', $customer->status) == 'pending' ? 'selected' : '' }}>{{ __('Pending') }}</option>
                                <option value="suspended" {{ old('status', $customer->status) == 'suspended' ? 'selected' : '' }}>{{ __('Suspended') }}</option>
                            </select>
                            @error('status')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="col-md-6 mb-3">
                            <label for="email" class="form-label">{{ __('Email') }}</label>
                            <input type="email" class="form-control @error('email') is-invalid @enderror"
                                   id="email" name="email" value="{{ old('email', $customer->email) }}">
                            @error('email')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="col-md-6 mb-3">
                            <label for="phone" class="form-label">{{ __('Phone') }}</label>
                            <input type="text" class="form-control @error('phone') is-invalid @enderror"
                                   id="phone" name="phone" value="{{ old('phone', $customer->phone) }}">
                            @error('phone')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="col-md-6 mb-3">
                            <label for="mobile" class="form-label">{{ __('Mobile') }}</label>
                            <input type="text" class="form-control @error('mobile') is-invalid @enderror"
                                   id="mobile" name="mobile" value="{{ old('mobile', $customer->mobile) }}">
                            @error('mobile')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="col-md-6 mb-3">
                            <label for="website" class="form-label">{{ __('Website') }}</label>
                            <input type="url" class="form-control @error('website') is-invalid @enderror"
                                   id="website" name="website" value="{{ old('website', $customer->website) }}">
                            @error('website')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="col-md-6 mb-3">
                            <label for="tax_id" class="form-label">{{ __('Tax ID') }}</label>
                            <input type="text" class="form-control @error('tax_id') is-invalid @enderror"
                                   id="tax_id" name="tax_id" value="{{ old('tax_id', $customer->tax_id) }}">
                            @error('tax_id')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="col-md-6 mb-3">
                            <label for="vat_number" class="form-label">{{ __('VAT Number') }}</label>
                            <input type="text" class="form-control @error('vat_number') is-invalid @enderror"
                                   id="vat_number" name="vat_number" value="{{ old('vat_number', $customer->vat_number) }}">
                            @error('vat_number')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="col-md-6 mb-3">
                            <label for="credit_limit" class="form-label">{{ __('Credit Limit') }}</label>
                            <input type="number" step="0.01" class="form-control @error('credit_limit') is-invalid @enderror"
                                   id="credit_limit" name="credit_limit" value="{{ old('credit_limit', $customer->credit_limit) }}">
                            @error('credit_limit')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="col-md-12 mb-3">
                            <label for="notes" class="form-label">{{ __('Notes') }}</label>
                            <textarea class="form-control @error('notes') is-invalid @enderror"
                                      id="notes" name="notes" rows="4">{{ old('notes', $customer->notes) }}</textarea>
                            @error('notes')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>
                    </div>
                </div>
            </div>

            <div class="card">
                <div class="card-body">
                    <div class="d-flex gap-2">
                        <button type="submit" class="btn btn-primary">
                            <i class="bx bx-save me-1"></i> {{ __('Update Customer') }}
                        </button>
                        <a href="{{ route('systemcore.customers.index') }}" class="btn btn-label-secondary">
                            <i class="bx bx-x me-1"></i> {{ __('Cancel') }}
                        </a>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
@endsection
