@extends('layouts.admin') @section('title', $package->exists ? 'Edit Package' : 'New Package') @section('heading', $package->exists ? 'Edit Package' : 'New Package') @section('subheading', $package->exists ? 'Changes apply to licenses generated from here on.' : 'Sets the term, cycle and price every license generated from it inherits.') @php // Seeds the shared field partial's Alpine state with exactly what the // server rendered into the inputs, so the two never disagree — including // after a validation bounce, where old() wins. $initial = [ 'id' => $package->id, 'name' => old('name', $package->name), 'duration_days' => old('duration_days', $package->duration_days) ?? '', 'price' => (string) old('price', $package->price ?? 0), 'billing_period' => old('billing_period', $package->billing_period ?? 'custom'), 'sort_order' => (int) old('sort_order', $package->sort_order ?? 0), 'is_active' => (bool) old('is_active', $package->is_active ?? true), ]; // Counted once: this drives the header line, the delete copy and whether // deleting is offered at all. $issued = $package->exists ? $package->licenses()->count() : 0; @endphp @section('content')
@csrf @if ($package->exists) @method('PUT') @endif

{{ $package->exists ? $package->name : 'Package details' }}

@if ($package->exists) {{ $issued }} {{ Str::plural('license', $issued) }} issued from this package @else Fill in the term, the billing cycle and the price @endif

@include('packages.partials.fields', ['package' => $package])
Cancel
{{-- Deleting lives outside the save form: two submit paths in one form is how a "save" ends up deleting something. --}} @if ($package->exists)

Delete this package

@if ($issued > 0) Not possible while licenses reference it. Deactivate it instead — it stops being offered without breaking the licenses already issued. @else Permanent. The package is not referenced by any license. @endif

@if ($issued > 0) Delete @else
@csrf @method('DELETE')
@endif
@endif
@endsection