@extends('layouts.admin')

@section('title', 'Edit Promotion Package')

@section('admin-content')
    <!-- Page Header -->
    <div class="page-header">
        <div>
            <h3 class="page-title">Edit Promotion Package</h3>
            <p class="text-muted mb-0">Modify existing promotion package</p>
        </div>
        <div class="d-flex gap-2">
            <a href="{{ route('admin.promotions.packages.index') }}" class="btn btn-light shadow-sm">
                <i class="bi bi-arrow-left me-2"></i> Back to Packages
            </a>
        </div>
    </div>

    <div class="row">
        <div class="col-lg-8 mx-auto">
            <div class="card">
                <div class="card-body p-4">
                    <form action="{{ route('admin.promotions.packages.update', $package) }}" method="POST">
                        @csrf
                        @method('PUT')

                        <div class="row g-4">
                            <div class="col-md-6">
                                <label class="form-label fw-bold">Package Name <span class="text-danger">*</span></label>
                                <input type="text" name="name" class="form-control @error('name') is-invalid @enderror" 
                                       value="{{ old('name', $package->name) }}" required>
                                @error('name')<div class="invalid-feedback">{{ $message }}</div>@enderror
                            </div>

                            <div class="col-md-3">
                                <label class="form-label fw-bold">Price (₹) <span class="text-danger">*</span></label>
                                <div class="input-group">
                                    <span class="input-group-text bg-light border-end-0">₹</span>
                                    <input type="number" name="price" class="form-control border-start-0 @error('price') is-invalid @enderror" 
                                           value="{{ old('price', $package->price) }}" step="0.01" min="0" required>
                                </div>
                                @error('price')<div class="invalid-feedback d-block">{{ $message }}</div>@enderror
                            </div>

                            <div class="col-md-3">
                                <label class="form-label fw-bold">Price ($) <span class="text-danger">*</span></label>
                                <div class="input-group">
                                    <span class="input-group-text bg-light border-end-0">$</span>
                                    <input type="number" name="price_usd" class="form-control border-start-0 @error('price_usd') is-invalid @enderror" 
                                           value="{{ old('price_usd', $package->price_usd) }}" step="0.01" min="0" required>
                                </div>
                                @error('price_usd')<div class="invalid-feedback d-block">{{ $message }}</div>@enderror
                            </div>

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

                            <div class="col-md-4">
                                <label class="form-label fw-bold">Duration (Days) <span class="text-danger">*</span></label>
                                <input type="number" name="duration_days" class="form-control @error('duration_days') is-invalid @enderror" 
                                       value="{{ old('duration_days', $package->duration_days) }}" min="1" required>
                                @error('duration_days')<div class="invalid-feedback">{{ $message }}</div>@enderror
                            </div>

                            <div class="col-md-4">
                                <label class="form-label fw-bold">Page Position <span class="text-danger">*</span></label>
                                <select name="page_position" class="form-select @error('page_position') is-invalid @enderror" required>
                                    <option value="1" {{ old('page_position', $package->page_position) == 1 ? 'selected' : '' }}>Page 1</option>
                                    <option value="2" {{ old('page_position', $package->page_position) == 2 ? 'selected' : '' }}>Page 2</option>
                                </select>
                                @error('page_position')<div class="invalid-feedback">{{ $message }}</div>@enderror
                            </div>

                            <div class="col-md-4">
                                <label class="form-label fw-bold">Max Products <span class="text-danger">*</span></label>
                                <input type="number" name="max_products" class="form-control @error('max_products') is-invalid @enderror" 
                                       value="{{ old('max_products', $package->max_products) }}" min="1" required>
                                @error('max_products')<div class="invalid-feedback">{{ $message }}</div>@enderror
                            </div>

                            <div class="col-md-4">
                                <label class="form-label fw-bold">Priority Level (1-10) <span class="text-danger">*</span></label>
                                <input type="number" name="priority_level" class="form-control @error('priority_level') is-invalid @enderror" 
                                       value="{{ old('priority_level', $package->priority_level) }}" min="1" max="10" required>
                                <div class="form-text small">Higher priority shows first</div>
                                @error('priority_level')<div class="invalid-feedback">{{ $message }}</div>@enderror
                            </div>

                            <div class="col-md-4">
                                <label class="form-label fw-bold">Badge Text <span class="text-danger">*</span></label>
                                <input type="text" name="badge_text" class="form-control @error('badge_text') is-invalid @enderror" 
                                       value="{{ old('badge_text', $package->badge_text) }}" maxlength="50" required>
                                @error('badge_text')<div class="invalid-feedback">{{ $message }}</div>@enderror
                            </div>

                            <div class="col-md-4">
                                <label class="form-label fw-bold">Badge Color <span class="text-danger">*</span></label>
                                <input type="color" name="badge_color" class="form-control form-control-color w-100 @error('badge_color') is-invalid @enderror" 
                                       value="{{ old('badge_color', $package->badge_color) }}" required>
                                @error('badge_color')<div class="invalid-feedback">{{ $message }}</div>@enderror
                            </div>

                            <div class="col-12">
                                <div class="form-check form-switch">
                                    <input type="checkbox" name="is_active" value="1" class="form-check-input" id="is_active" 
                                           {{ old('is_active', $package->is_active) ? 'checked' : '' }} style="cursor: pointer;">
                                    <label class="form-check-label fw-medium" for="is_active">
                                        Active (sellers can purchase this package)
                                    </label>
                                </div>
                            </div>

                            <div class="col-12 mt-4 pt-3 border-top d-flex justify-content-end gap-2">
                                <a href="{{ route('admin.promotions.packages.index') }}" class="btn btn-light">Cancel</a>
                                <button type="submit" class="btn btn-primary-gradient px-4">
                                    <i class="bi bi-save me-2"></i> Update Package
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
@endsection
