@extends('layouts.app')

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

@section('content')
    @php
        $topups = [
            [
                'id' => 1,
                'freeCode' => 'CODE123',
                'name' => 'Monthly Top-Up',
                'value' => '100.00',
                'type' => 'Prepaid'
            ],
            [
                'id' => 2,
                'freeCode' => 'CODE456',
                'name' => 'Annual Plan',
                'value' => '500.00',
                'type' => 'Postpaid'
            ],
            [
                'id' => 3,
                'freeCode' => 'CODE789',
                'name' => 'Welcome Bonus',
                'value' => '50.00',
                'type' => 'Bonus'
            ],
            [
                'id' => 4,
                'freeCode' => 'CODE101',
                'name' => 'Data Boost',
                'value' => '200.00',
                'type' => 'Prepaid'
            ],
            [
                'id' => 5,
                'freeCode' => 'CODE202',
                'name' => 'Family Plan',
                'value' => '300.00',
                'type' => 'Postpaid'
            ],
            [
                'id' => 6,
                'freeCode' => 'CODE303',
                'name' => 'Loyalty Credit',
                'value' => '75.00',
                'type' => 'Bonus'
            ]
        ];
    @endphp

    @include('components.table-component', [
        'pageTitle' => 'Top-Up',
        'data' => $topups,
        'columns' => [
            ['name' => 'Free Code', 'key' => 'freeCode', 'sortable' => true],
            ['name' => 'Name', 'key' => 'name', 'sortable' => true],
            ['name' => 'Value', 'key' => 'value', 'sortable' => true],
            ['name' => 'Type', 'key' => 'type', 'sortable' => true]
        ],
        'actions' => ['edit', 'view', 'delete'],
        'showAddButton' => true,
        'addButtonUrl' => '/add-top-up',
        'showCheckboxes' => true,
        'showBatchDelete' => true,
        'showEditModal' => true,
        'showViewModal' => true
    ])

    <script>
        const storedTopups = JSON.parse(sessionStorage.getItem('topups') || '[]');
        if (storedTopups.length > 0) {
            const tableConfig = window.tableConfig || {};
            tableConfig.data = [...tableConfig.data, ...storedTopups];
            window.renderTable();
            window.renderPagination();
        }
    </script>
@endsection