<?php

namespace App\Exports;

use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithTitle;

class ProfileDataExport implements FromCollection, WithTitle, WithHeadings, WithMapping
{
    use Exportable;

    protected $data;
    protected $profileType;

    public function __construct(Collection $data, string $profileType)
    {
        $this->data = $data;
        $this->profileType = $profileType;
    }

    public function collection()
    {
        return $this->data;
    }

    public function headings(): array
    {
        $commonHeadings = [
            __('Name'),
            __('Full name'),
            __('Email'),
            __('About'),
            __('About short'),
            __('Motivation'),
            __('Website'),
            __('Phone'),
            str_replace('@PLATFORM_NAME@', platform_name(), __('Visible for registered @PLATFORM_NAME@ users')),
            __('Location'),
            __('Social media'),
            __('Profile photo'),
            __('Language preference'),
            __('Created at'),
            __('Updated at'),
            __('Last login'),
            __('Last login') . ' ' . 'IP',
        ];

        return $commonHeadings;
    }

    public function map($profile): array
    {
        return [
            $profile['name'] ?? '',
            $profile['full_name'] ?? '',
            $profile['email'] ?? '',
            $profile['about'] ?? '',
            $profile['about_short'] ?? '',
            $profile['motivation'] ?? '',
            $profile['website'] ?? '',
            $profile['phone'] ?? '',
            $profile['phone_public'] ? __('Yes') : __('No'),
            $profile['location_first'] ?? '',
            $profile['social_media'] ?? '',
            $profile['profile_photo_path'] ?? '',
            $profile['lang_preference'] ?? '',
            $profile['created_at'] ?? '',
            $profile['updated_at'] ?? '',
            $profile['last_login_at'] ?? '',
            $profile['last_login_ip'] ?? '',
        ];
    }

    public function title(): string
    {
        return __('Profile data');
    }
}
