@extends('admin.layouts.app')

@section('title', 'Edit Supplier')
@section('page_title', 'Edit Supplier')

@section('content')
<div class="page-shell">
    <div class="page-head">
        <div>
            <h1 class="page-title">Edit Supplier</h1>
            <div class="page-subtitle">Update supplier information without breaking purchase records.</div>
        </div>
        <a href="{{ route('admin.suppliers.index') }}" class="btn btn-light">Back to List</a>
    </div>

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

        <div class="grid-3">
            <div class="card">
                <label for="name">Supplier Name</label>
                <input type="text" id="name" name="name" value="{{ old('name', $supplier->name) }}" required>
            </div>

            <div class="card">
                <label for="phone">Phone</label>
                <input type="text" id="phone" name="phone" value="{{ old('phone', $supplier->phone) }}">
            </div>

            <div class="card">
                <label for="email">Email</label>
                <input type="email" id="email" name="email" value="{{ old('email', $supplier->email) }}">
            </div>

            <div class="card">
                <label for="company">Company</label>
                <input type="text" id="company" name="company" value="{{ old('company', $supplier->company ?? $supplier->company_name) }}">
            </div>

            <div class="card">
                <label for="contact_person">Contact Person</label>
                <input type="text" id="contact_person" name="contact_person" value="{{ old('contact_person', $supplier->contact_person) }}">
            </div>

            <div class="card">
                <label for="opening_due">Opening Due</label>
                <input type="number" step="0.01" id="opening_due" name="opening_due" value="{{ old('opening_due', $supplier->opening_due ?? 0) }}">
            </div>
        </div>

        <div class="grid-2" style="margin-top:12px;">
            <div class="card">
                <label for="address">Address</label>
                <textarea id="address" name="address" rows="5">{{ old('address', $supplier->address) }}</textarea>
            </div>

            <div class="card">
                <label for="notes">Notes</label>
                <textarea id="notes" name="notes" rows="5">{{ old('notes', $supplier->notes) }}</textarea>

                <div class="form-actions">
                    <button type="submit" class="btn primary">Update Supplier</button>
                    <a href="{{ route('admin.suppliers.index') }}" class="btn btn-light">Cancel</a>
                </div>
            </div>
        </div>
    </form>
</div>
@endsection