@extends('admin.layouts.app')
@section('title', $customer->exists ? 'Edit Customer' : 'Add Customer')
@section('content')
<div class="page-shell">
    <div class="page-head"><div><h1 class="page-title">{{ $customer->exists ? 'Edit Customer' : 'Add Customer' }}</h1><div class="page-subtitle">Full customer module</div></div><a href="{{ route('admin.customers.index') }}" class="btn btn-light">Customer List</a></div>
    <form method="POST" action="{{ $customer->exists ? route('admin.customers.update',$customer) : route('admin.customers.store') }}" class="card panel-tight grid-2">
        @csrf @if($customer->exists) @method('PUT') @endif
        <div><label>Name</label><input type="text" name="name" value="{{ old('name',$customer->name) }}" required></div>
        <div><label>Phone</label><input type="text" name="phone_number" value="{{ old('phone_number',$customer->phone_number) }}"></div>
        <div><label>Email</label><input type="text" name="email" value="{{ old('email',$customer->email) }}"></div>
        <div><label>Customer Group</label><select name="customer_group"><option @selected(old('customer_group',$customer->customer_group)=='Retail')>Retail</option><option @selected(old('customer_group',$customer->customer_group)=='Wholesale')>Wholesale</option><option @selected(old('customer_group',$customer->customer_group)=='VIP')>VIP</option></select></div>
        <div><label>Opening Balance</label><input type="number" step="0.01" min="0" name="opening_balance" value="{{ old('opening_balance',$customer->opening_balance ?? 0) }}"></div>
        <div><label>Loyalty Points</label><input type="number" min="0" name="points" value="{{ old('points',$customer->points ?? 0) }}"></div>
        <div><label>Wallet Balance</label><input type="number" step="0.01" min="0" name="wallet_balance" value="{{ old('wallet_balance',$customer->wallet_balance ?? 0) }}"></div>
        <div><label>Membership No</label><input type="text" name="membership_no" value="{{ old('membership_no',$customer->membership_no ?? '') }}"></div>
        <div><label>Membership Tier</label><select name="membership_tier"><option @selected(old('membership_tier',$customer->membership_tier ?? 'General')=='General')>General</option><option @selected(old('membership_tier',$customer->membership_tier ?? '')=='Silver')>Silver</option><option @selected(old('membership_tier',$customer->membership_tier ?? '')=='Gold')>Gold</option><option @selected(old('membership_tier',$customer->membership_tier ?? '')=='Platinum')>Platinum</option></select></div>
        <div><label>Special Discount %</label><input type="number" step="0.01" min="0" name="special_discount_percent" value="{{ old('special_discount_percent',$customer->special_discount_percent ?? 0) }}"></div>
        <div><label>SMS Invoice / Reminder</label><select name="sms_opt_in"><option value="1" @selected(old('sms_opt_in',$customer->sms_opt_in ?? 1)==1)>Enabled</option><option value="0" @selected(old('sms_opt_in',$customer->sms_opt_in ?? 1)==0)>Disabled</option></select></div>
        <div><label>Status</label><select name="status"><option @selected(old('status',$customer->status)=='Active')>Active</option><option @selected(old('status',$customer->status)=='Inactive')>Inactive</option></select></div>
        <div style="grid-column:1/-1"><label>Address</label><textarea name="address" rows="3">{{ old('address',$customer->address) }}</textarea></div>
        <div class="form-actions" style="grid-column:1/-1"><button class="btn primary">{{ $customer->exists ? 'Update' : 'Save' }}</button><a href="{{ route('admin.customers.index') }}" class="btn btn-light">Cancel</a></div>
    </form>
</div>
@endsection
