@extends('layouts.app')
@section('title',@$title)
@section('content')
<section id="section3" class="container mx-auto p-12 md:py-12">
    <div class="flex flex-row gap-10">
        <div class="w-full lg:w-2/3">
            <div class="p-3 shadow-[1px_1px_5px_0px_rgba(0,0,0,0.25)] rounded-[10px]">
                <div class="flex flex-col gap-3">
                    
                    <?php
				        $image = json_decode($kegiatan->image);
				    ?>
                    <div id="carousel" class="relative w-full mx-auto">
                    <!-- Images -->
                        <div class="overflow-hidden rounded-xl relative">
                            <div id="carousel-inner" class="flex transition-transform duration-500">
                                @foreach ($image as $img)
                                    <div class="w-full flex-shrink-0">
                                        <img src="{{ asset($img) }}" class="w-full lg:w-[100%] h-100 rounded-[10px] object-cover" alt="Image">
                                    </div>
                                @endforeach
                            </div>
                        </div>

                        <!-- Prev button -->
                        <button id="prevBtn"
                            class="absolute left-2 top-1/2 -translate-y-1/2 bg-gray-800/60 text-white p-2 rounded-full">
                            ‹
                        </button>

                        <!-- Next button -->
                        <button id="nextBtn"
                            class="absolute right-2 top-1/2 -translate-y-1/2 bg-gray-800/60 text-white p-2 rounded-full">
                            ›
                        </button>

                        <!-- Indicators -->
                        <div id="indicators" class="absolute bottom-3 left-1/2 -translate-x-1/2 flex space-x-2">
                            @foreach ($image as $index => $img)
                                <button class="w-3 h-3 rounded-full {{ $index === 0 ? 'bg-white' : 'bg-gray-400' }}"></button>
                            @endforeach
                        </div>
                    </div>
                    
                    <div class="flex flex-row gap-3 items-center">
                        <span class="p-2 bg-warning text-xs rounded-[10px] text-white">Kegiatan {{ $kegiatan->kategori }}</span>
                        <span class="text-xs opacity-[50%]">{{ date('D',strtotime($kegiatan->created_at)) }}, {{ date('d M Y',strtotime($kegiatan->created_at)) }}</span>
                    </div>
                    <h1 class="text-2xl text-black font-bold mt-2">{{ $kegiatan->judul }}</h1>
                    <div class="flex items-center gap-3">
                        <span class="text-sm font-medium text-gray-600">Bagikan:</span>
                        <div class="flex gap-2">
                            <a href="#" onclick="shareToLinkedIn()" class="flex items-center justify-center w-10 h-10 bg-primary text-white rounded-full hover:bg-green-600 transition-colors">
                                <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 20 20">
                                    <path d="M16.338 16.338H13.67V12.16c0-.995-.017-2.277-1.387-2.277-1.39 0-1.601 1.086-1.601 2.207v4.248H8.014v-8.59h2.559v1.174h.037c.356-.675 1.227-1.387 2.526-1.387 2.703 0 3.203 1.778 3.203 4.092v4.711zM5.005 6.575a1.548 1.548 0 11-.003-3.096 1.548 1.548 0 01.003 3.096zm-1.337 9.763H6.34v-8.59H3.667v8.59zM17.668 1H2.328C1.595 1 1 1.581 1 2.298v15.403C1 18.418 1.595 19 2.328 19h15.34c.734 0 1.332-.582 1.332-1.299V2.298C19 1.581 18.402 1 17.668 1z"></path>
                                </svg>
                            </a>
                            <a href="#" onclick="shareToWhatsApp()" class="flex items-center justify-center w-10 h-10 bg-success text-white rounded-full hover:bg-green-600 transition-colors">
                                <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 24 24">
                                    <path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893A11.821 11.821 0 0020.525 3.507"></path>
                                </svg>
                            </a>
                            <a href="#" onclick="shareToFacebook()" class="flex items-center justify-center w-10 h-10 bg-primary text-white rounded-full hover:bg-green-600 transition-colors">
                                <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 24 24">
                                    <path d="M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z"></path>
                                </svg>
                            </a>
                            <a href="#" onclick="shareToTwitter()" class="flex items-center justify-center w-10 h-10 bg-black text-white rounded-full hover:bg-green-600 transition-colors">
                                <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 24 24">
                                    <path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"></path>
                                </svg>
                            </a>
                        </div>
                    </div>
                    <div class="text-sm opacity-[50%]">
                        {!!$kegiatan->body !!}
                    </div>
                </div>
            </div>		
        </div>
        <div class="hidden lg:block w-1/3">
            <div class="p-3 shadow-[1px_1px_5px_0px_rgba(0,0,0,0.25)] rounded-[10px]">
                <div class="flex flex-col gap-3">
                    @foreach($lainnya as $dataKeg)
                    <?php
				        $image = json_decode($dataKeg->image);
				    ?>
                    <div class="flex items-center gap-3 flex-row pb-3">
                        <div class="flex justify-end w-2/5">
                            <img src="{{ asset($image[0]) }}" class="rounded-[10px] ">
                        </div>
                        <div class="flex flex-col gap-3 justify-center w-3/5">
                            <span class="text-xs opacity-[50%]">{{ date('D',strtotime($dataKeg->created_at)) }}, {{ date('d M Y',strtotime($dataKeg->created_at)) }}</span>
                            <a href="{{ url('kegiatan/'.$dataKeg->slug) }}" class="text-xs text-black font-bold">{{ $dataKeg->judul }}</a>
                        </div>
                    </div>
                    @endforeach
                    
                </div>	
            </div>
        </div>
    </div>
</section>
@endsection
@section('js')
<script>
        function shareToFacebook() {
            const url = encodeURIComponent(window.location.href);
            const title = encodeURIComponent(document.querySelector('h1').textContent);
            window.open(`https://www.facebook.com/sharer/sharer.php?u=${url}`, '_blank', 'noopener,noreferrer,width=600,height=400');
        }

        function shareToTwitter() {
            const url = encodeURIComponent(window.location.href);
            const title = encodeURIComponent(document.querySelector('h1').textContent);
            window.open(`https://twitter.com/intent/tweet?url=${url}&text=${title}`, '_blank', 'noopener,noreferrer,width=600,height=400');
        }

        function shareToWhatsApp() {
            const url = encodeURIComponent(window.location.href);
            const title = encodeURIComponent(document.querySelector('h1').textContent);
            window.open(`https://wa.me/?text=${title}%20${url}`, '_blank', 'noopener,noreferrer');
        }

        function shareToLinkedIn() {
            const url = encodeURIComponent(window.location.href);
            const title = encodeURIComponent(document.querySelector('h1').textContent);
            window.open(`https://www.linkedin.com/sharing/share-offsite/?url=${url}`, '_blank', 'noopener,noreferrer,width=600,height=400');
        }
    </script>
    <script>
    const carouselInner = document.getElementById("carousel-inner");
    const prevBtn = document.getElementById("prevBtn");
    const nextBtn = document.getElementById("nextBtn");
    const indicators = document.querySelectorAll("#indicators button");
    const totalSlides = indicators.length;

    let currentIndex = 0;

    function updateCarousel() {
        carouselInner.style.transform = `translateX(-${currentIndex * 100}%)`;

        indicators.forEach((dot, idx) => {
            dot.classList.toggle("bg-white", idx === currentIndex);
            dot.classList.toggle("bg-gray-400", idx !== currentIndex);
        });
    }

    prevBtn.addEventListener("click", () => {
        currentIndex = (currentIndex - 1 + totalSlides) % totalSlides;
        updateCarousel();
    });

    nextBtn.addEventListener("click", () => {
        currentIndex = (currentIndex + 1) % totalSlides;
        updateCarousel();
    });

    indicators.forEach((dot, idx) => {
        dot.addEventListener("click", () => {
            currentIndex = idx;
            updateCarousel();
        });
    });
</script>

@endsection