@extends('layouts.nova')

@section('title', $page_title . ' — Skinbase')

@section('content')
<div class="container-fluid legacy-page">
    <div class="page-heading">
        <h1 class="page-header"><i class="fa fa-stream"></i> {{ $page_title }}</h1>
    </div>

    {{-- Tab bar --}}
    <ul class="nav nav-tabs mb-3">
        <li class="nav-item">
            <a class="nav-link {{ $active_tab === 'global' ? 'active' : '' }}"
               href="{{ route('community.activity', ['type' => 'global']) }}">
                <i class="fa fa-globe"></i> Global
            </a>
        </li>
        @auth
        <li class="nav-item">
            <a class="nav-link {{ $active_tab === 'following' ? 'active' : '' }}"
               href="{{ route('community.activity', ['type' => 'following']) }}">
                <i class="fa fa-user-group"></i> Following
            </a>
        </li>
        @endauth
    </ul>

    <div class="activity-feed">
        @forelse($enriched as $event)
            <div class="activity-event media mb-3 p-2 rounded bg-dark-subtle">
                <div class="media-body">
                    <span class="fw-semibold">
                        <a href="{{ $event['actor']['url'] ?? '#' }}">{{ $event['actor']['name'] ?? 'Someone' }}</a>
                    </span>

                    @switch($event['type'])
                        @case('upload')
                            uploaded
                            @break
                        @case('comment')
                            commented on
                            @break
                        @case('favorite')
                            favourited
                            @break
                        @case('award')
                            awarded
                            @break
                        @case('follow')
                            started following
                            @break
                        @default
                            interacted with
                    @endswitch

                    @if($event['target'])
                        @if($event['target_type'] === 'artwork')
                            <a href="{{ $event['target']['url'] }}">{{ $event['target']['title'] }}</a>
                            @if(!empty($event['target']['thumb']))
                                <img src="{{ $event['target']['thumb'] }}" alt="" class="ms-2 rounded" style="height:36px;width:auto;vertical-align:middle;">
                            @endif
                        @elseif($event['target_type'] === 'user')
                            <a href="{{ $event['target']['url'] ?? '#' }}">{{ $event['target']['name'] ?? $event['target']['username'] ?? '' }}</a>
                        @endif
                    @endif

                    <small class="text-muted ms-2">{{ \Carbon\Carbon::parse($event['created_at'])->diffForHumans() }}</small>
                </div>
            </div>
        @empty
            <div class="alert alert-info">
                @if($active_tab === 'following')
                    Follow some creators to see their activity here.
                @else
                    No activity yet. Be the first!
                @endif
            </div>
        @endforelse
    </div>

    {{-- Pagination --}}
    <div class="mt-3">
        {{ $events->links() }}
    </div>
</div>
@endsection
