@extends('layouts.app')

@section('page_title', 'Branches')

@section('content')
    @php
        $branches = [
            [
                'id' => 1,
                'branchCode' => 'BR001',
                'branchName' => 'Main Branch',
                'details' => 'Located at downtown, open 9 AM to 5 PM.',
                'dateCreated' => '2025-01-01',
                'createdBy' => 'Admin',
                'dateModified' => '2025-04-01'
            ],
            [
                'id' => 2,
                'branchCode' => 'BR002',
                'branchName' => 'Westside Branch',
                'details' => 'Serves western district, parking available.',
                'dateCreated' => '2025-02-01',
                'createdBy' => 'Admin',
                'dateModified' => '2025-04-10'
            ],
            [
                'id' => 3,
                'branchCode' => 'BR003',
                'branchName' => 'East End Branch',
                'details' => 'Newly opened, extended hours.',
                'dateCreated' => '2025-03-01',
                'createdBy' => 'Admin',
                'dateModified' => '2025-03-01'
            ],
            [
                'id' => 4,
                'branchCode' => 'BR004',
                'branchName' => 'North Branch',
                'details' => 'Located near industrial area.',
                'dateCreated' => '2025-01-15',
                'createdBy' => 'Admin',
                'dateModified' => '2025-04-05'
            ],
            [
                'id' => 5,
                'branchCode' => 'BR005',
                'branchName' => 'South Branch',
                'details' => 'Family-friendly, open weekends.',
                'dateCreated' => '2025-02-15',
                'createdBy' => 'Admin',
                'dateModified' => '2025-02-15'
            ],
            [
                'id' => 6,
                'branchCode' => 'BR006',
                'branchName' => 'Central Branch',
                'details' => 'Central location, 24/7 ATM.',
                'dateCreated' => '2025-03-15',
                'createdBy' => 'Admin',
                'dateModified' => '2025-04-12'
            ]
        ];
    @endphp

    @include('components.table-component', [
        'pageTitle' => 'Branches',
        'data' => $branches,
        'columns' => [
            ['name' => 'Branch Code', 'key' => 'branchCode', 'sortable' => true],
            ['name' => 'Branch Name', 'key' => 'branchName', 'sortable' => true],
            ['name' => 'Details', 'key' => 'details', 'sortable' => true],
            ['name' => 'Date Created', 'key' => 'dateCreated', 'sortable' => true],
            ['name' => 'Created By', 'key' => 'createdBy', 'sortable' => true],
            ['name' => 'Date Modified', 'key' => 'dateModified', 'sortable' => true]
        ],
        'allFields' => [
            ['name' => 'Branch Code', 'key' => 'branchCode', 'type' => 'text', 'required' => true],
            ['name' => 'Branch Name', 'key' => 'branchName', 'type' => 'text', 'required' => true],
            ['name' => 'Details', 'key' => 'details', 'type' => 'textarea', 'required' => true]
        ],
        'actions' => ['edit', 'delete'],
        'showAddButton' => true,
        'addButtonUrl' => '/add-branches',
        'showCheckboxes' => false,
        'showBatchDelete' => false,
        'showEditModal' => true,
        'showViewModal' => false
    ])

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