@extends('layouts.app')
@php $edit = isset($party); @endphp
@section('title', $edit ? "Edit {$party->name}" : 'New Party')
@section('breadcrumb')
    @include('components.breadcrumb', ['items' => ['Parties' => null, $edit ? "Edit {$party->name}" : 'New' => null]])
@endsection
@section('content')
<div class="max-w-2xl mx-auto">
    <x-card :title="$edit ? 'Edit Party' : 'Add New Party'" :icon="$edit ? 'edit-2' : 'plus'">
        <form action="{{ $edit ? route('party.update', $party->id) : route('party.store') }}" method="POST" class="space-y-4">
            @csrf @if($edit) @method('PUT') @endif
            <div class="grid grid-cols-2 gap-4">
                <x-form-input name="name" label="Name" icon="building" :value="old('name', $edit ? $party->name : '')" required />
                <div class="relative">
                    <i data-lucide="tag" class="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400 z-10 peer-[:not(:placeholder-shown)]:hidden"></i>
                    <select name="type" required class="peer w-full rounded-xl border border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-900 text-sm text-slate-900 dark:text-white pl-10 pr-3.5 pt-5 pb-2 transition focus:ring-2 focus:ring-primary-500">
                        <option value="supplier" {{ $edit && $party->type == 'supplier' ? 'selected' : '' }}>Supplier</option>
                        <option value="customer" {{ $edit && $party->type == 'customer' ? 'selected' : '' }}>Customer</option>
                        <option value="both" {{ $edit && $party->type == 'both' ? 'selected' : '' }}>Both</option>
                    </select>
                    <label class="absolute left-10 top-3.5 text-sm text-slate-500 transition-all pointer-events-none origin-left peer-focus:-translate-y-3 peer-focus:scale-75 peer-focus:text-primary-600">Type <span class="text-red-500">*</span></label>
                </div>
                <x-form-input name="phone" label="Phone" icon="phone" :value="old('phone', $edit ? $party->phone : '')" required />
                <x-form-input name="email" label="Email" type="email" icon="mail" :value="old('email', $edit ? $party->email : '')" />
                <x-form-input name="city" label="City" icon="map-pin" :value="old('city', $edit ? $party->city : '')" />
                <x-form-input name="credit_limit" label="Credit Limit" type="number" icon="circle-dollar-sign" :value="old('credit_limit', $edit ? $party->credit_limit : 0)" />
            </div>
            <x-form-input name="address" label="Address" type="textarea" icon="map-pin" :value="old('address', $edit ? $party->address : '')" />
            <div class="flex justify-end gap-2 pt-2">
                <x-button variant="secondary" :href="$edit && $party->type === 'customer' ? route('customer.index') : route('supplier.index')">Cancel</x-button>
                <x-button variant="primary" icon="save" type="submit">{{ $edit ? 'Update' : 'Save' }}</x-button>
            </div>
        </form>
    </x-card>
</div>
@endsection
