@extends('layouts.dashboard')
@section('title', $package->id ? 'Edit Package' : 'New Package')
@section('page-title', $package->id ? 'Edit Package' : 'New Package')
@section('content')
<div class="content-card" style="max-width:800px;">
    <form method="POST" action="{{ $package->id ? route('admin.packages.update', $package) : route('admin.packages.store') }}">
        @csrf @if($package->id)@method('PUT')@endif

        <div class="row">
            <div class="col-md-6 mb-3">
                <label class="form-label">Package Name</label>
                <input type="text" name="name" class="form-control" value="{{ old('name', $package->name) }}" required>
            </div>
            <div class="col-md-3 mb-3">
                <label class="form-label">Blogs Count</label>
                <input type="number" name="blogs_count" min="1" class="form-control" value="{{ old('blogs_count', $package->blogs_count ?? 1) }}" required>
            </div>
            <div class="col-md-3 mb-3">
                <label class="form-label">Price (USD)</label>
                <input type="number" step="0.01" min="0" name="price" class="form-control" value="{{ old('price', $package->price ?? 10) }}" required>
            </div>
        </div>

        <div class="mb-3">
            <label class="form-label">Description</label>
            <textarea name="description" rows="3" class="form-control">{{ old('description', $package->description) }}</textarea>
        </div>

        <div class="mb-3">
            <label class="form-label">Features (one per line)</label>
            <textarea name="features" rows="5" class="form-control" placeholder="Lifetime publishing&#10;Priority support&#10;Author profile page">{{ is_array($package->features) ? implode("\n", $package->features) : old('features') }}</textarea>
        </div>

        <div class="row">
            <div class="col-md-4 mb-3">
                <label class="form-label">Sort Order</label>
                <input type="number" name="sort_order" class="form-control" value="{{ old('sort_order', $package->sort_order ?? 0) }}">
            </div>
            <div class="col-md-4 mb-3 d-flex align-items-center pt-4">
                <input type="hidden" name="is_featured" value="0">
                <input type="checkbox" name="is_featured" id="is_featured" value="1" class="form-check-input" {{ old('is_featured', $package->is_featured) ? 'checked' : '' }}>
                <label for="is_featured" class="form-check-label ms-2">Featured</label>
            </div>
            <div class="col-md-4 mb-3 d-flex align-items-center pt-4">
                <input type="hidden" name="is_active" value="0">
                <input type="checkbox" name="is_active" id="is_active" value="1" class="form-check-input" {{ old('is_active', $package->is_active ?? 1) ? 'checked' : '' }}>
                <label for="is_active" class="form-check-label ms-2">Active</label>
            </div>
        </div>

        <div class="d-flex gap-2">
            <button class="btn btn-primary">Save Package</button>
            <a href="{{ route('admin.packages.index') }}" class="btn btn-outline-secondary">Cancel</a>
        </div>
    </form>
</div>
@endsection
