@extends('layouts.app')

@section('page_title', 'Edit Top-Up')

@section('content')
    <div class="card-header border-0 bg-transparent py-2">
        <h5 class="mb-0 fw-bold text-dark" style="font-size: 1.25rem;">Edit Top-Up</h5>
    </div>
    <div class="row justify-content-center">
        <div class="card-body p-3">
            @if (session('success'))
                <div class="alert alert-success">
                    {{ session('success') }}
                </div>
            @endif
            @if (session('error'))
                <div class="alert alert-danger">
                    {{ session('error') }}
                </div>
            @endif
            <form method="POST" action="{{ route('top-up.update', $topup['topup_uuid']) }}">
                @csrf
                @method('PUT')
                <div class="mb-3">
                    <label for="freeCode" class="form-label">Free Code</label>
                    <input type="text" class="form-control @error('freeCode') is-invalid @enderror" id="freeCode" name="freeCode" value="{{ old('freeCode', $topup['freeCode']) }}" required>
                    @error('freeCode')
                        <div class="invalid-feedback">{{ $message }}</div>
                    @enderror
                </div>
                <div class="mb-3">
                    <label for="name" class="form-label">Name</label>
                    <input type="text" class="form-control @error('name') is-invalid @enderror" id="name" name="name" value="{{ old('name', $topup['name']) }}" required>
                    @error('name')
                        <div class="invalid-feedback">{{ $message }}</div>
                    @enderror
                </div>
                <div class="mb-3">
                    <label for="value" class="form-label">Value</label>
                    <input type="number" class="form-control @error('value') is-invalid @enderror" id="value" name="value" step="0.01" value="{{ old('value', $topup['value']) }}" required>
                    @error('value')
                        <div class="invalid-feedback">{{ $message }}</div>
                    @enderror
                </div>
                <div class="mb-3">
                    <label for="type" class="form-label">Type</label>
                    <select class="form-select @error('type') is-invalid @enderror" id="type" name="type" required>
                        <option value="Prepaid" {{ old('type', $topup['type']) == 'Prepaid' ? 'selected' : '' }}>Prepaid</option>
                        <option value="Postpaid" {{ old('type', $topup['type']) == 'Postpaid' ? 'selected' : '' }}>Postpaid</option>
                        <option value="Bonus" {{ old('type', $topup['type']) == 'Bonus' ? 'selected' : '' }}>Bonus</option>
                    </select>
                    @error('type')
                        <div class="invalid-feedback">{{ $message }}</div>
                    @enderror
                </div>
                <div class="d-flex justify-content-end mt-3">
                    <a href="{{ route('top-up') }}" class="btn btn-outline-secondary me-2" style="margin-right:5px">Cancel</a>
                    <button type="submit" class="btn btn-primary">Update Top-Up</button>
                </div>
            </form>
        </div>
    </div>

    <style>
        .card {
            border-radius: 5px;
            border: 1px solid #dee2e6;
        }
        .form-label {
            font-size: 0.95rem;
        }
        .form-control,
        .form-select {
            font-size: 0.9rem;
            width: 100%;
        }
        .alert {
            font-size: 0.9rem;
        }
    </style>
@endsection