@extends('layouts.app')

@section('page_title', 'Fuels')

@section('content')
    @php
        $fuels = [
            [
                'id' => 1,
                'fuelName' => 'Unleaded 91',
                'dateCreated' => '2025-01-01',
                'dateModified' => '2025-04-01'
            ],
            [
                'id' => 2,
                'fuelName' => 'Unleaded 95',
                'dateCreated' => '2025-02-01',
                'dateModified' => '2025-04-10'
            ],
            [
                'id' => 3,
                'fuelName' => 'Diesel',
                'dateCreated' => '2025-03-01',
                'dateModified' => '2025-03-01'
            ],
            [
                'id' => 4,
                'fuelName' => 'Premium Unleaded 98',
                'dateCreated' => '2025-01-15',
                'dateModified' => '2025-04-05'
            ],
            [
                'id' => 5,
                'fuelName' => 'Kerosene',
                'dateCreated' => '2025-02-15',
                'dateModified' => '2025-02-15'
            ],
            [
                'id' => 6,
                'fuelName' => 'Biofuel E10',
                'dateCreated' => '2025-03-15',
                'dateModified' => '2025-04-12'
            ]
        ];
    @endphp

    @include('components.table-component', [
        'pageTitle' => 'Fuels',
        'data' => $fuels,
        'columns' => [
            ['name' => 'Fuel Name', 'key' => 'fuelName', 'sortable' => true],
            ['name' => 'Date Created', 'key' => 'dateCreated', 'sortable' => true],
            ['name' => 'Date Modified', 'key' => 'dateModified', 'sortable' => true]
        ],
        'allFields' => [
            ['name' => 'Fuel Name', 'key' => 'fuelName', 'type' => 'text', 'required' => true]
        ],
        'actions' => ['edit', 'delete'],
        'showAddButton' => true,
        'addButtonUrl' => '/add-fuels',
        'showCheckboxes' => false,
        'showBatchDelete' => false,
        'showEditModal' => true,
        'showViewModal' => false
    ])

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