@extends('layouts.app')

@section('page_title', 'Card Types')

@section('content')
    @php
        $cardTypes = [
            [
                'id' => 1,
                'cardCode' => 'VISA01',
                'cardTypeDescription' => 'Visa Platinum Card',
                'cardTypeShortDescription' => 'Premium Visa card',
                'cardTypeImage' => '',
                'virtualCardFontColor' => 'White',
                'cardTypeCoverImage' => '',
                'idNumberRequired' => 'Yes',
                'idNumberDescription' => 'Government-issued ID required',
                'termsAndConditions' => 'Valid for 5 years. Annual fee applies.',
                'faqs' => 'Q: What is the credit limit? A: Up to $10,000.'
            ],
            [
                'id' => 2,
                'cardCode' => 'MC02',
                'cardTypeDescription' => 'MasterCard Gold',
                'cardTypeShortDescription' => 'Gold MasterCard',
                'cardTypeImage' => '',
                'virtualCardFontColor' => 'Black',
                'cardTypeCoverImage' => '',
                'idNumberRequired' => 'No',
                'idNumberDescription' => '',
                'termsAndConditions' => 'No annual fee for first year.',
                'faqs' => 'Q: Can I use it abroad? A: Yes, globally accepted.'
            ],
            [
                'id' => 3,
                'cardCode' => 'AMEX03',
                'cardTypeDescription' => 'Amex Rewards Card',
                'cardTypeShortDescription' => 'Amex Rewards',
                'cardTypeImage' => '',
                'virtualCardFontColor' => 'White',
                'cardTypeCoverImage' => '',
                'idNumberRequired' => 'Yes',
                'idNumberDescription' => 'Passport or driver’s license',
                'termsAndConditions' => 'Earn 2x points on travel.',
                'faqs' => 'Q: How to redeem points? A: Via app.'
            ],
            [
                'id' => 4,
                'cardCode' => 'VISA04',
                'cardTypeDescription' => 'Visa Classic Card',
                'cardTypeShortDescription' => 'Basic Visa card',
                'cardTypeImage' => '',
                'virtualCardFontColor' => 'Black',
                'cardTypeCoverImage' => '',
                'idNumberRequired' => 'No',
                'idNumberDescription' => '',
                'termsAndConditions' => 'Standard rates apply.',
                'faqs' => 'Q: Is there a fee? A: No hidden fees.'
            ],
            [
                'id' => 5,
                'cardCode' => 'MC05',
                'cardTypeDescription' => 'MasterCard Premium',
                'cardTypeShortDescription' => 'Premium MasterCard',
                'cardTypeImage' => '',
                'virtualCardFontColor' => 'White',
                'cardTypeCoverImage' => '',
                'idNumberRequired' => 'Yes',
                'idNumberDescription' => 'ID for verification',
                'termsAndConditions' => 'Free lounge access.',
                'faqs' => 'Q: Lounge access? A: At major airports.'
            ],
            [
                'id' => 6,
                'cardCode' => 'AMEX06',
                'cardTypeDescription' => 'Amex Business Card',
                'cardTypeShortDescription' => 'Business Amex',
                'cardTypeImage' => '',
                'virtualCardFontColor' => 'Black',
                'cardTypeCoverImage' => '',
                'idNumberRequired' => 'No',
                'idNumberDescription' => '',
                'termsAndConditions' => 'For business expenses.',
                'faqs' => 'Q: Tax benefits? A: Consult accountant.'
            ]
        ];
    @endphp

    @include('components.table-component', [
        'pageTitle' => 'Card Types',
        'data' => $cardTypes,
        'columns' => [
            ['name' => 'Card Type Code', 'key' => 'cardCode', 'sortable' => true],
            ['name' => 'Card Type Description', 'key' => 'cardTypeDescription', 'sortable' => true]
        ],
        'allFields' => [
            ['name' => 'Card Code', 'key' => 'cardCode', 'type' => 'text', 'required' => true],
            ['name' => 'Card Type Description', 'key' => 'cardTypeDescription', 'type' => 'text', 'required' => true],
            ['name' => 'Card Type Short Description', 'key' => 'cardTypeShortDescription', 'type' => 'text', 'required' => true],
            ['name' => 'Card Type Image', 'key' => 'cardTypeImage', 'type' => 'file'],
            ['name' => 'Virtual Card Font Color', 'key' => 'virtualCardFontColor', 'type' => 'select', 'options' => ['White', 'Black'], 'required' => true],
            ['name' => 'Card Type Cover Image', 'key' => 'cardTypeCoverImage', 'type' => 'file'],
            ['name' => 'ID Number Required?', 'key' => 'idNumberRequired', 'type' => 'select', 'options' => ['Yes', 'No'], 'required' => true],
            ['name' => 'ID Number Description', 'key' => 'idNumberDescription', 'type' => 'text'],
            ['name' => 'Terms and Conditions', 'key' => 'termsAndConditions', 'type' => 'textarea', 'required' => true],
            ['name' => 'FAQs', 'key' => 'faqs', 'type' => 'textarea', 'required' => true]
        ],
        'actions' => ['edit', 'view', 'delete'],
        'showAddButton' => true,
        'addButtonUrl' => '/add-card-types',
        'showCheckboxes' => true,
        'showBatchDelete' => true,
        'showEditModal' => true,
        'showViewModal' => true
    ])

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