@extends('layouts.app')

@section('page_title', 'Terms and Privacy')

@section('content')
    @php
        $termsAndPrivacy = [
            [
                'id' => 1,
                'title' => 'User Agreement',
                'details' => 'Users must agree to use the platform responsibly and comply with all applicable laws.',
                'type' => 'Terms'
            ],
            [
                'id' => 2,
                'title' => 'Privacy Policy',
                'details' => 'We collect personal data to improve services, with consent, and protect user information.',
                'type' => 'Privacy'
            ],
            [
                'id' => 3,
                'title' => 'Service Terms',
                'details' => 'Details on how services are provided, including limitations and user obligations.',
                'type' => 'Terms'
            ],
            [
                'id' => 4,
                'title' => 'Data Protection',
                'details' => 'Our commitment to GDPR compliance and secure data handling practices.',
                'type' => 'Privacy'
            ],
            [
                'id' => 5,
                'title' => 'Refund Policy',
                'details' => 'Conditions under which refunds are issued for services or subscriptions.',
                'type' => 'Terms'
            ],
            [
                'id' => 6,
                'title' => 'Cookie Policy',
                'details' => 'How we use cookies to enhance user experience and track site usage.',
                'type' => 'Privacy'
            ]
        ];
    @endphp

    @include('components.table-component', [
        'pageTitle' => 'Terms and Privacy',
        'data' => $termsAndPrivacy,
        'columns' => [
            ['name' => 'Title', 'key' => 'title', 'sortable' => true],
            ['name' => 'Details', 'key' => 'details', 'sortable' => true],
            ['name' => 'Type', 'key' => 'type', 'sortable' => true]
        ],
        'allFields' => [
            ['name' => 'Title', 'key' => 'title', 'type' => 'text', 'required' => true],
            ['name' => 'Details', 'key' => 'details', 'type' => 'textarea', 'required' => true]
        ],
        'actions' => ['edit', 'view', 'delete'],
        'showAddButton' => true,
        'addButtonUrl' => '/add-terms-and-privacy',
        'showCheckboxes' => true,
        'showBatchDelete' => true,
        'showEditModal' => true,
        'showViewModal' => true
    ])

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