@extends('layouts.app')

@section('title', $articleData['title'] ?? 'Sports Article - Sports Portal')
@section('meta_description', Str::limit(strip_tags(is_array($articleData['article'] ?? '') ? implode(' ', array_map(function($item) { return is_array($item) ? ($item['content'] ?? '') : $item; }, $articleData['article'])) : $articleData['article'] ?? ''), 160))

@section('content')
<div class="mx-auto">
    <!-- Breadcrumb -->
    <nav class="flex mb-6 text-sm text-gray-400" aria-label="Breadcrumb">
        <ol class="inline-flex items-center space-x-1 md:space-x-3">
            <li class="inline-flex items-center">
                <a href="{{ url('/') }}" class="inline-flex items-center hover:text-white">
                    <svg class="w-4 h-4 mr-2" fill="currentColor" viewBox="0 0 20 20"><path d="M10.707 2.293a1 1 0 00-1.414 0l-7 7a1 1 0 001.414 1.414L4 10.414V17a1 1 0 001 1h2a1 1 0 001-1v-2a1 1 0 011-1h2a1 1 0 011 1v2a1 1 0 001 1h2a1 1 0 001-1v-6.586l.293.293a1 1 0 001.414-1.414l-7-7z"></path></svg>
                    Home
                </a>
            </li>
            @if($sport)
            <li>
                <div class="flex items-center">
                    <svg class="w-6 h-6 text-gray-400" fill="currentColor" viewBox="0 0 20 20"><path fill-rule="evenodd" d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z" clip-rule="evenodd"></path></svg>
                    <a href="{{ route('sports.category', $sport) }}" class="ml-1 text-gray-400 hover:text-white md:ml-2">{{ ucfirst($sport) }}</a>
                </div>
            </li>
            @endif
            <li aria-current="page">
                <div class="flex items-center">
                    <svg class="w-6 h-6 text-gray-400" fill="currentColor" viewBox="0 0 20 20"><path fill-rule="evenodd" d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z" clip-rule="evenodd"></path></svg>
                    <span class="ml-1 text-gray-100 md:ml-2 font-medium truncate max-w-[200px] sm:max-w-xs">{{ $articleData['title'] ?? 'Article' }}</span>
                </div>
            </li>
        </ol>
    </nav>

    @if(isset($articleData) && !empty($articleData))
        <!-- Article Header -->
        <header class="mb-8">
            <div class="flex items-center gap-2 mb-4">
                @if($sport)
                <span class="bg-blue-600 text-white text-xs font-bold px-2 py-1 rounded">{{ ucfirst($sport) }}</span>
                @endif
                <span class="text-gray-400 text-sm">{{ $articleData['date'] ?? date('M d, Y') }}</span>
            </div>
            <h1 class="text-3xl md:text-4xl lg:text-5xl font-bold text-white mb-6 leading-tight">
                {{ $articleData['title'] ?? 'Sports Article' }}
            </h1>
            <div class="flex items-center gap-3 border-b border-gray-700 pb-6">
                <div class="w-10 h-10 rounded-full bg-gray-700 flex items-center justify-center text-xl">👤</div>
                <div>
                    <div class="text-white font-medium">By Admin</div>
                    <div class="text-gray-500 text-xs">Sports Journalist</div>
                </div>
            </div>
        </header>

        <!-- Featured Image -->
        @if(!empty($articleData['images']))
        <div class="mb-10 rounded-xl overflow-hidden shadow-2xl">
            <img src="{{ $articleData['images'] }}" alt="{{ $articleData['title'] ?? 'Sports Image' }}" class="w-full h-auto object-cover">
        </div>
        @endif

        <!-- Article Content -->
        <article class="prose prose-invert prose-lg max-w-none text-gray-300">
            @if(is_array($articleData['article'] ?? null))
                @foreach($articleData['article'] as $content)
                    @if(is_array($content))
                        {{-- Live blog entry --}}
                        <div class="bg-gray-800 p-6 rounded-lg mb-6 border border-gray-700">
                            @if(!empty($content['title']))
                            <h3 class="text-xl font-bold text-white mb-2">{{ $content['title'] }}</h3>
                            @endif
                            
                            <div class="flex items-start gap-3">
                                @if(!empty($content['icon']))
                                <img src="{{ $content['icon'] }}" class="w-6 h-6 mt-1" alt="Icon">
                                @endif
                                
                                @if(!empty($content['content']))
                                <div class="prose prose-invert max-w-none">
                                    {!! $content['content'] !!}
                                </div>
                                @endif
                            </div>
                        </div>
                    @else
                        {{-- Regular paragraph --}}
                        <div class="mb-4">{!! $content !!}</div>
                    @endif
                @endforeach
            @else
                <p>Content not available.</p>
            @endif
        </article>

        <!-- Share & Tags -->
        <div class="mt-12 pt-8 border-t border-gray-700">
            <h3 class="text-lg font-semibold text-white mb-4">Share this article</h3>
            <div class="flex gap-4">
                <button class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded transition">Facebook</button>
                <button class="bg-sky-500 hover:bg-sky-600 text-white px-4 py-2 rounded transition">Twitter</button>
                <button class="bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded transition">WhatsApp</button>
            </div>
        </div>

    @else
        <div class="bg-gray-800 p-8 rounded-lg text-center">
            <h4 class="text-xl font-bold text-white mb-2">Article Not Available</h4>
            <p class="text-gray-400">Unable to fetch the sports article at the moment. Please try again later.</p>
        </div>
    @endif

</div>
@endsection