@extends('layout')

@section('title', __('store.data_privacy_title'))

@section('content')
<div class="container py-5">
    <div class="row">
        <div class="col-md-12">
            <x-clientarea.page-header
                icon="fas fa-shield-alt"
                :title="__('store.data_privacy_title')"
                :subtitle="__('store.data_privacy_description')"
            />

            {{-- Your Personal Data --}}
            <div class="card border-0 shadow-sm mb-4">
                <div class="card-body">
                    <h5 class="card-title">
                        <i class="fas fa-database me-2"></i>{{ __('store.data_privacy_your_data') }}
                    </h5>
                    <p class="text-muted">{{ __('store.data_privacy_your_data_description') }}</p>

                    <div class="table-responsive">
                        <table class="table table-hover mb-0">
                            <tbody>
                                <tr>
                                    <td class="fw-bold" style="width: 200px;">{{ __('store.data_privacy_field_name') }}</td>
                                    <td>{{ $client->first_name }} {{ $client->last_name }}</td>
                                </tr>
                                <tr>
                                    <td class="fw-bold">{{ __('store.data_privacy_field_email') }}</td>
                                    <td>{{ $client->email }}</td>
                                </tr>
                                @if($client->phone)
                                <tr>
                                    <td class="fw-bold">{{ __('store.data_privacy_field_phone') }}</td>
                                    <td>{{ $client->phone }}</td>
                                </tr>
                                @endif
                                @if($client->company_name)
                                <tr>
                                    <td class="fw-bold">{{ __('store.data_privacy_field_company') }}</td>
                                    <td>{{ $client->company_name }}</td>
                                </tr>
                                @endif
                                @if($client->address1)
                                <tr>
                                    <td class="fw-bold">{{ __('store.data_privacy_field_address') }}</td>
                                    <td>{{ $client->address1 }}{{ $client->address2 ? ', ' . $client->address2 : '' }}</td>
                                </tr>
                                @endif
                                @if($client->city)
                                <tr>
                                    <td class="fw-bold">{{ __('store.data_privacy_field_city') }}</td>
                                    <td>{{ $client->city }}</td>
                                </tr>
                                @endif
                                @if($client->country)
                                <tr>
                                    <td class="fw-bold">{{ __('store.data_privacy_field_country') }}</td>
                                    <td>{{ $client->country->name }}</td>
                                </tr>
                                @endif
                                <tr>
                                    <td class="fw-bold">{{ __('store.data_privacy_field_registration_date') }}</td>
                                    <td>{{ $client->created_at->format($dateTimeFormat) }}</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>

            {{-- Data Categories --}}
            <div class="card border-0 shadow-sm mb-4">
                <div class="card-body">
                    <h5 class="card-title">
                        <i class="fas fa-layer-group me-2"></i>{{ __('store.data_privacy_data_categories') }}
                    </h5>
                    <p class="text-muted">{{ __('store.data_privacy_data_categories_description') }}</p>

                    <div class="row g-3">
                        <div class="col-md-6">
                            <div class="d-flex align-items-start p-3 border rounded h-100">
                                <div class="me-3">
                                    <i class="fas fa-user fa-lg text-primary"></i>
                                </div>
                                <div>
                                    <h6 class="mb-1">{{ __('store.data_privacy_category_personal') }}</h6>
                                    <small class="text-muted">{{ __('store.data_privacy_category_personal_desc') }}</small>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="d-flex align-items-start p-3 border rounded h-100">
                                <div class="me-3">
                                    <i class="fas fa-file-invoice-dollar fa-lg text-success"></i>
                                </div>
                                <div>
                                    <h6 class="mb-1">{{ __('store.data_privacy_category_billing') }}</h6>
                                    <small class="text-muted">{{ __('store.data_privacy_category_billing_desc') }}</small>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="d-flex align-items-start p-3 border rounded h-100">
                                <div class="me-3">
                                    <i class="fas fa-server fa-lg text-info"></i>
                                </div>
                                <div>
                                    <h6 class="mb-1">{{ __('store.data_privacy_category_service') }}</h6>
                                    <small class="text-muted">{{ __('store.data_privacy_category_service_desc') }}</small>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="d-flex align-items-start p-3 border rounded h-100">
                                <div class="me-3">
                                    <i class="fas fa-headset fa-lg text-warning"></i>
                                </div>
                                <div>
                                    <h6 class="mb-1">{{ __('store.data_privacy_category_support') }}</h6>
                                    <small class="text-muted">{{ __('store.data_privacy_category_support_desc') }}</small>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="d-flex align-items-start p-3 border rounded h-100">
                                <div class="me-3">
                                    <i class="fas fa-history fa-lg text-secondary"></i>
                                </div>
                                <div>
                                    <h6 class="mb-1">{{ __('store.data_privacy_category_activity') }}</h6>
                                    <small class="text-muted">{{ __('store.data_privacy_category_activity_desc') }}</small>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            {{-- Data Retention Policy --}}
            <div class="card border-0 shadow-sm mb-4">
                <div class="card-body">
                    <h5 class="card-title">
                        <i class="fas fa-clock me-2"></i>{{ __('store.data_privacy_retention_policy') }}
                    </h5>
                    <p class="text-muted mb-0">{{ __('store.data_privacy_retention_policy_description') }}</p>
                </div>
            </div>

            <div class="row">
                {{-- Data Export --}}
                <div class="col-md-6 mb-4">
                    <div class="card border-0 shadow-sm h-100">
                        <div class="card-body">
                            <h5 class="card-title">
                                <i class="fas fa-download me-2"></i>{{ __('store.data_privacy_export_title') }}
                            </h5>
                            <p class="text-muted">{{ __('store.data_privacy_export_description') }}</p>

                            @if($pendingExport)
                                <div class="alert alert-info mb-3">
                                    <i class="fas fa-hourglass-half me-2"></i>
                                    {{ __('store.data_privacy_export_pending') }}
                                </div>
                            @endif

                            @if($completedExport && $completedExport->file_path)
                                <a href="{{ route('store.auth.data-privacy.download', $completedExport->id) }}" class="btn btn-success mb-3">
                                    <i class="fas fa-file-download me-2"></i>{{ __('store.data_privacy_export_download') }}
                                </a>
                            @endif

                            @if(!$pendingExport)
                                <form action="{{ route('store.auth.data-privacy.export') }}" method="POST">
                                    @csrf
                                    <button type="submit" class="btn btn-primary">
                                        <i class="fas fa-file-export me-2"></i>{{ __('store.data_privacy_export_request') }}
                                    </button>
                                </form>
                            @endif
                        </div>
                    </div>
                </div>

                {{-- Account Deletion --}}
                <div class="col-md-6 mb-4">
                    <div class="card border-0 shadow-sm h-100">
                        <div class="card-body">
                            <h5 class="card-title">
                                <i class="fas fa-user-times me-2 text-danger"></i>{{ __('store.data_privacy_deletion_title') }}
                            </h5>
                            <p class="text-muted">{{ __('store.data_privacy_deletion_description') }}</p>

                            <div class="alert alert-danger mb-3">
                                <i class="fas fa-exclamation-triangle me-2"></i>
                                {{ __('store.data_privacy_deletion_warning') }}
                            </div>

                            @if($pendingDeletion)
                                <div class="alert alert-info mb-0">
                                    <i class="fas fa-hourglass-half me-2"></i>
                                    {{ __('store.data_privacy_deletion_pending') }}
                                </div>
                            @else
                                <form action="{{ route('store.auth.data-privacy.deletion') }}" method="POST">
                                    @csrf
                                    <div class="mb-3">
                                        <label for="reason" class="form-label">{{ __('store.data_privacy_deletion_reason') }} <span class="text-danger">*</span></label>
                                        <textarea class="form-control @error('reason') is-invalid @enderror" id="reason" name="reason" rows="3"
                                                  placeholder="{{ __('store.data_privacy_deletion_reason_placeholder') }}"
                                                  required minlength="10" maxlength="1000">{{ old('reason') }}</textarea>
                                        @error('reason')
                                            <div class="invalid-feedback">{{ $message }}</div>
                                        @enderror
                                    </div>
                                    <button type="submit" class="btn btn-danger">
                                        <i class="fas fa-trash-alt me-2"></i>{{ __('store.data_privacy_deletion_request') }}
                                    </button>
                                </form>
                            @endif
                        </div>
                    </div>
                </div>
            </div>

            {{-- Request History --}}
            <div class="card border-0 shadow-sm">
                <div class="card-body">
                    <h5 class="card-title">
                        <i class="fas fa-history me-2"></i>{{ __('store.data_privacy_request_history') }}
                    </h5>

                    @if($dataRequests->count() > 0)
                        <div class="table-responsive">
                            <table class="table table-hover">
                                <thead>
                                    <tr>
                                        <th>#</th>
                                        <th>{{ __('store.data_privacy_column_type') }}</th>
                                        <th>{{ __('store.data_privacy_column_status') }}</th>
                                        <th>{{ __('store.data_privacy_column_date') }}</th>
                                        <th>{{ __('store.actions') }}</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach($dataRequests as $dataRequest)
                                    <tr>
                                        <td>{{ $dataRequest->id }}</td>
                                        <td>
                                            @if($dataRequest->type === 'export')
                                                <span class="badge bg-primary">
                                                    <i class="fas fa-download me-1"></i>{{ __('store.data_privacy_type_export') }}
                                                </span>
                                            @else
                                                <span class="badge bg-danger">
                                                    <i class="fas fa-trash-alt me-1"></i>{{ __('store.data_privacy_type_deletion') }}
                                                </span>
                                            @endif
                                        </td>
                                        <td>
                                            @switch($dataRequest->status)
                                                @case('pending')
                                                    <span class="badge bg-warning text-dark">{{ __('store.data_privacy_status_pending') }}</span>
                                                    @break
                                                @case('processing')
                                                    <span class="badge bg-info">{{ __('store.data_privacy_status_processing') }}</span>
                                                    @break
                                                @case('completed')
                                                    <span class="badge bg-success">{{ __('store.data_privacy_status_completed') }}</span>
                                                    @break
                                                @case('rejected')
                                                    <span class="badge bg-danger">{{ __('store.data_privacy_status_rejected') }}</span>
                                                    @break
                                            @endswitch
                                        </td>
                                        <td>{{ $dataRequest->created_at->format($dateTimeFormat) }}</td>
                                        <td>
                                            @if($dataRequest->type === 'export' && $dataRequest->status === 'completed' && $dataRequest->file_path)
                                                <a href="{{ route('store.auth.data-privacy.download', $dataRequest->id) }}" class="btn btn-sm btn-success">
                                                    <i class="fas fa-download me-1"></i>{{ __('store.data_privacy_export_download') }}
                                                </a>
                                            @else
                                                -
                                            @endif
                                        </td>
                                    </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                    @else
                        <div class="text-center py-4 text-muted">
                            <i class="fas fa-inbox fa-3x mb-3"></i>
                            <p class="mb-0">{{ __('store.data_privacy_no_requests') }}</p>
                        </div>
                    @endif
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
