@extends('admin.layouts.app')

@section('title', $title)

@section('content')
    <div class="col-md-12">
        <!-- Page Heading -->
        <div class="row mb-4">
            <h4 class="c-grey-900">Create Manual License</h4>
        </div>

        <!-- Main Content -->
        <div class="row">
            <div class="col-md-8">
                <div class="bgc-white bd bdrs-3 p-20 mB-20">
                    <form action="{{ route('ch-admin.license.store') }}" method="POST">
                        @csrf

                        <!-- User Selection -->
                        <div class="mb-3">
                            <label for="user_id" class="form-label">Select User <span class="text-danger">*</span></label>
                            <select name="user_id" id="user_id" class="form-control select2 @error('user_id') is-invalid @enderror" required>
                                <option value="">Select a user</option>
                                @foreach($users as $user)
                                    <option value="{{ $user->id }}" {{ old('user_id') == $user->id ? 'selected' : '' }}>
                                        {{ $user->first_name }} {{ $user->last_name }} ({{ $user->email }})
                                    </option>
                                @endforeach
                            </select>
                            @error('user_id')
                            <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <!-- Product Name -->
                        <div class="mb-3">
                            <label for="product_name" class="form-label">Product/Plan Name <span class="text-danger">*</span></label>
                            <input type="text" class="form-control @error('product_name') is-invalid @enderror" id="product_name" name="product_name" value="{{ old('product_name') }}" required placeholder="e.g. Pro SaaS Plan">
                            @error('product_name')
                            <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                            <small class="text-muted">This is purely for display purposes.</small>
                        </div>

                        <!-- Expiry Date -->
                        <div class="mb-3">
                            <label for="expiry_date" class="form-label">Expiry Date (Optional)</label>
                            <input type="text" class="form-control datepicker @error('expiry_date') is-invalid @enderror" id="expiry_date" name="expiry_date" value="{{ old('expiry_date') }}" placeholder="Leave blank for lifetime">
                            @error('expiry_date')
                            <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <!-- Max Activations -->
                        <div class="mb-3">
                            <label for="max_activations" class="form-label">Maximum Activations (Optional)</label>
                            <input type="number" class="form-control @error('max_activations') is-invalid @enderror" id="max_activations" name="max_activations" value="{{ old('max_activations', 1) }}" min="1">
                            @error('max_activations')
                            <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                            <small class="text-muted">Leave blank for unlimited activations.</small>
                        </div>

                        <!-- Action Buttons -->
                        <div>
                            <button class="btn btn-primary">Generate License</button>
                            <a href="{{ route('ch-admin.license.index') }}" class="btn btn-secondary">Cancel</a>
                        </div>
                    </form>
                </div>
            </div>

            <div class="col-md-4">
                <div class="bgc-white bd bdrs-3 p-20 mB-20">
                    <h5>Important Information</h5>
                    <p>Creating a manual license completely bypasses the order and payment system. This license will be functional but won't be tied to any invoice or subscription.</p>
                </div>
            </div>
        </div>
    </div>
@endsection
