@extends('admin.layouts.app')
@section('title', 'Edit: '.$subscription->name)
@section('content')
<div class="page-header d-print-none">
    <div class="container-xl">
        <div class="row g-2 align-items-center">
            <div class="col-auto"><a href="{{ route('admin.subscriptions.index') }}" class="btn btn-outline-secondary btn-sm">← Back</a></div>
            <div class="col"><h2 class="page-title">Edit: {{ $subscription->name }}</h2></div>
        </div>
    </div>
</div>
<div class="page-body">
    <div class="row justify-content-center">
        <div class="col-md-7">
            <div class="card">
                <div class="card-body" x-data="{ benefits: {{ json_encode($subscription->benefits ?? ['']) }} }">
                    <form action="{{ route('admin.subscriptions.update', $subscription) }}" method="POST">
                        @csrf @method('PUT')
                        <div class="mb-3">
                            <label class="form-label">Plan Name <span class="text-danger">*</span></label>
                            <input type="text" name="name" class="form-control" value="{{ old('name', $subscription->name) }}" required>
                        </div>
                        <div class="row mb-3">
                            <div class="col">
                                <label class="form-label">Price (₹)</label>
                                <input type="number" name="price" class="form-control" value="{{ old('price', $subscription->price) }}" step="0.01" min="0" required>
                            </div>
                            <div class="col">
                                <label class="form-label">Duration (days)</label>
                                <input type="number" name="duration_days" class="form-control" value="{{ old('duration_days', $subscription->duration_days) }}" min="1" required>
                            </div>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">Description</label>
                            <textarea name="description" class="form-control" rows="3">{{ old('description', $subscription->description) }}</textarea>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">Benefits</label>
                            <template x-for="(benefit, index) in benefits" :key="index">
                                <div class="d-flex gap-2 mb-2">
                                    <input type="text" :name="'benefits[' + index + ']'" x-model="benefits[index]" class="form-control">
                                    <button type="button" class="btn btn-outline-danger btn-sm" @click="benefits.splice(index, 1)" x-show="benefits.length > 1">✕</button>
                                </div>
                            </template>
                            <button type="button" class="btn btn-outline-secondary btn-sm" @click="benefits.push('')">+ Add Benefit</button>
                        </div>
                        <div class="row mb-3">
                            <div class="col">
                                <label class="form-label">Sort Order</label>
                                <input type="number" name="sort_order" class="form-control" value="{{ old('sort_order', $subscription->sort_order) }}">
                            </div>
                            <div class="col d-flex align-items-end">
                                <label class="form-check mb-0">
                                    <input type="checkbox" name="is_active" value="1" class="form-check-input" {{ old('is_active', $subscription->is_active) ? 'checked' : '' }}>
                                    <span class="form-check-label">Active</span>
                                </label>
                            </div>
                        </div>
                        <div class="d-flex gap-2">
                            <button type="submit" class="btn btn-primary">Update Plan</button>
                            <a href="{{ route('admin.subscriptions.index') }}" class="btn btn-outline-secondary">Cancel</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
