@extends('pemerintah.main')

@section('content')
    <style>
        .information {
            padding: 20px;
            background-color: #f9f9f9;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }

        .project-info-header {
            display: flex;
            /* Use flexbox for layout */
            justify-content: space-between;
            /* Space between the header and button */
            align-items: center;
            /* Align items vertically centered */
            margin-bottom: 15px;
            /* Space below the header */
        }

        .btn.cmn-btn {
            padding: 10px 20px;
            /* Adjust padding for the button */
            border: none;
            /* Remove border */
            border-radius: 25px;
            /* Rounded button */
            background-color: #007bff;
            /* Button background color */
            color: white;
            /* Button text color */
            font-size: 1em;
            /* Font size */
            cursor: pointer;
            /* Pointer cursor on hover */
            transition: background-color 0.3s;
            /* Smooth transition for hover */
        }

        .btn.cmn-btn:hover {
            background-color: #0056b3;
            /* Darker color on hover */
        }

        .project-details {
            list-style: none;
            padding: 0;
            margin: 0;
            line-height: 1.6;
        }

        .project-details li {
            padding: 5px 0;
            border-bottom: 1px solid #e0e0e0;
        }

        .project-details li:last-child {
            border-bottom: none;
            /* Remove border for the last item */
        }

        h3 {
            margin: 0;
            /* Remove margin for the header */
            color: #333;
            /* Darker text color */
        }

        .user-profile-card {
            display: flex;
            align-items: center;
            padding: 10px;
            border: 1px solid #ddd;
            /* Light border */
            border-radius: 8px;
            /* Rounded corners */
            background-color: #fff;
            /* White background */
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
            /* Subtle shadow */
            transition: transform 0.2s;
            /* Animation on hover */
        }

        .user-profile-card:hover {
            transform: scale(1.02);
            /* Slightly enlarge on hover */
        }

        .user-profile-image {
            flex-shrink: 0;
            /* Prevent shrinking */
            margin-right: 10px;
            /* Space between image and text */
        }

        .profile-pic {
            width: 50px;
            /* Fixed size */
            height: 50px;
            /* Fixed size */
            border-radius: 50%;
            /* Circular image */
            object-fit: cover;
            /* Cover to maintain aspect ratio */
            border: 2px solid #007bff;
            /* Border color */
        }

        .user-profile-info {
            flex-grow: 1;
            /* Allow info section to take up remaining space */
        }

        .user-profile-info p {
            margin: 0;
            /* Remove default margin */
            font-size: 14px;
            /* Adjust font size */
        }


        .followers-title {
            text-align: center;
            font-size: 24px;
            font-weight: bold;
            color: #333;
            margin-bottom: 20px;
            display: block;
            /* pastikan judul ditampilkan sebagai elemen blok */
            width: 100%;
            /* lebar penuh untuk mencegah elemen lain di sebelahnya */
        }

        .followers-list {
            list-style: none;
            padding: 0;
            margin: 0;
            display: block;
            /* pastikan daftar tampil di bawah, bukan di samping */
            width: 100%;
            /* pastikan lebar penuh */
        }

        .follower-item {
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
            padding: 15px;
            margin-bottom: 15px;
            display: block;
            width: 100%;
            /* follower-item mengambil seluruh lebar yang ada */
        }

        .follower-details {
            display: flex;
            align-items: center;
            margin-bottom: 10px;
        }

        .follower-image img {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            object-fit: cover;
            margin-right: 15px;
            border: 2px solid #007bff;
        }

        .follower-info {
            display: flex;
            flex-direction: column;
        }

        .follower-name {
            font-size: 16px;
            font-weight: bold;
            margin: 0;
            color: #333;
        }

        .follower-role {
            font-size: 14px;
            color: #777;
        }

        .follower-actions {
            text-align: center;
        }

        .follow-btn {
            padding: 8px 20px;
            border: none;
            border-radius: 25px;
            background-color: #007bff;
            color: white;
            font-size: 14px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        .follow-btn:hover {
            background-color: #0056b3;
        }

        /* Responsive layout */
        @media (max-width: 400px) {
            .follower-item {
                flex-direction: column;
            }

            .follower-details {
                flex-direction: row;
                align-items: flex-start;
            }

            .follower-actions {
                margin-top: 10px;
                width: 100%;
                text-align: center;
            }
        }
    </style>

    <!-- Page Title -->
    <div class="page-title-area">
        <div class="d-table">
            <div class="d-table-cell">
                <div class="container">
                    <div class="title-item">
                        <h2>{{ $project->judul_project }}</h2>
                        <ul>
                            <li>
                                <a>{{ $project->jenis_penawaran }}</a>
                            </li>
                            <li>
                                <i class='bx bx-chevrons-right'></i>
                            </li>
                            <li>
                                <span>{{ $project->bidang_sub_sektor_ekonomi_kreatif }}</span>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- End Page Title -->

    <!-- Project Details -->
    <div class="project-details-area ptb-100">
        <div class="container">
            <div class="row">
                <div class="col-lg-8">
                    <div class="details-item">
                        <div class="details-img">
                            <img src="{{ asset('storage/' . $project->foto_proyek) }}" alt="Project Details"
                                class="project-image">

                            <div class="project-description">

                                <h3>Institusi Penelitian</h3>
                                <p class="one-p">{{ $project->riset->institusi_penelitian }}</p>

                                <h3>Deskripsi</h3>
                                <p class="one-p">{!! $project->deskripsi_project !!}</p>

                                <h3>Audiens</h3>
                                <p class="one-p">{!! $project->audiens !!}</p>

                                <h3>Bidang Penelitian</h3>
                                <p class="one-p">{{ $project->riset->bidang_penelitian }}</p>

                                <h3>Lokasi Penelitian</h3>
                                <p class="one-p">{{ $project->riset->lokasi_riset }}</p>

                                <h3>Metodologi</h3>
                                <p class="one-p">{!! $project->riset->metodologi !!}</p>


                                <h3>Hasil</h3>
                                <p class="one-p">{{ $project->riset->hasil }}</p>

                                <h3>Benefit</h3>
                                <p class="one-p">{!! $project->benefit !!}</p>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-lg-4">
                    <div class="widget-area">
                        <div class="information widget-item">
                            <div class="project-info-header">
                                <h3>Project Information</h3>
                                <button class="btn cmn-btn" type="submit">
                                    {{ $project->status }}
                                </button>
                            </div>
                            <ul>
                                <li>
                                    <span>Batas Terima Tawaran:</span>
                                    {{ $project->batas_terima_tawaran }}
                                </li>


                            </ul>
                        </div>

                        <!-- User Profile Section -->

                        <div class="widget-area">
                            <!-- User Profile Section -->
                            <div class="user-profile widget-item" style="cursor: pointer;">
                                <a href="{{ route('profile.detail', ['id' => $project->user->id]) }}"
                                    style="text-decoration: none; color: inherit;">
                                    <div class="user-profile-card">
                                        <div class="user-profile-image">
                                            @php
                                                // Get the user detail foto based on the user's role
$userFoto = null;
switch ($project->user->role) {
    case 'pemerintah':
        $userFoto =
            $project->user->pemerintahDetails->foto ?? 'default.jpg'; // Use a default image if not found
        break;
    case 'umkm':
        $userFoto = $project->user->umkmDetails->foto ?? 'default.jpg'; // Use a default image if not found
        break;
    case 'investor':
        $userFoto =
            $project->user->investorDetails->foto ?? 'default.jpg'; // Use a default image if not found
        break;
    case 'akademisi':
        $userFoto =
            $project->user->akademisiDetails->foto ?? 'default.jpg'; // Use a default image if not found
        break;
    case 'komunitas':
        $userFoto =
            $project->user->komunitasDetails->foto ?? 'default.jpg'; // Use a default image if not found
        break;
    default:
        $userFoto = 'default.jpg'; // Fallback default image
                                                        break;
                                                }
                                            @endphp
                                            <img src="{{ asset('storage/' . $userFoto) }}" alt="User Profile Picture"
                                                class="profile-pic">
                                        </div>
                                        <div class="user-profile-info">
                                            <p><strong>Name:</strong> {{ $project->user->full_name }}</p>
                                            <p><strong>Role:</strong> {{ $project->user->role }}</p>
                                            <p><strong>Institution:</strong>
                                                @if ($project->user->role == 'pemerintah')
                                                    {{ $project->user->pemerintahDetails->institution_name ?? 'N/A' }}
                                                @elseif($project->user->role == 'umkm')
                                                    {{ $project->user->umkmDetails->umkm_name ?? 'N/A' }}
                                                @elseif($project->user->role == 'investor')
                                                    {{ $project->user->investorDetails->company_name ?? 'N/A' }}
                                                @elseif($project->user->role == 'akademisi')
                                                    {{ $project->user->akademisiDetails->university_name ?? 'N/A' }}
                                                @elseif($project->user->role == 'komunitas')
                                                    {{ $project->user->komunitasDetails->community_name ?? 'N/A' }}
                                                @else
                                                    N/A
                                                @endif
                                            </p>
                                        </div>
                                    </div>
                                </a>
                            </div>

                        </div>
                        <br><br>

                        <div class="widget-area">
                            <div class="user-profile widget-item">
                                <h3 class="followers-title">Followers</h3>
                                <div class="user-profile-card">
                                    <ul class="followers-list">
                                        @foreach ($followers as $follow)
                                            <li class="follower-item">
                                                <div class="follower-details">
                                                    <div class="follower-image">
                                                        <img src="{{ asset('storage/' . ($follow->user->foto ?? 'default.jpg')) }}"
                                                            alt="Profile Picture" class="profile-pic">
                                                    </div>
                                                    <div class="follower-info">
                                                        <p class="follower-name">{{ $follow->user->full_name }}</p>
                                                        {{-- <p class="follower-role">{{ $follow->user->role }}</p> --}}
                                                        <p class="follower-role">
                                                            @if ($follow->user->role == 'pemerintah')
                                                                {{ $follow->user->pemerintahDetails->institution_name ?? 'N/A' }}
                                                            @elseif($follow->user->role == 'umkm')
                                                                {{ $follow->user->umkmDetails->umkm_name ?? 'N/A' }}
                                                            @elseif($follow->user->role == 'investor')
                                                                {{ $follow->user->investorDetails->company_name ?? 'N/A' }}
                                                            @elseif($follow->user->role == 'akademisi')
                                                                {{ $follow->user->akademisiDetails->university_name ?? 'N/A' }}
                                                            @elseif($follow->user->role == 'komunitas')
                                                                {{ $follow->user->komunitasDetails->community_name ?? 'N/A' }}
                                                            @else
                                                                N/A
                                                            @endif
                                                        </p>
                                                    </div>
                                                </div>

                                            </li>
                                        @endforeach
                                    </ul>
                                </div>
                            </div>
                        </div>
                        <br><br>

                        <div class="newsletter widget-item">
                            @php
                                // Ambil status follow untuk pengguna yang sedang login dan proyek yang bersangkutan
                                $follow = App\Models\FollowPenawaran::where('user_id', auth()->id())
                                    ->where('project_id', $project->id)
                                    ->first();
                            @endphp

                            <form id="followForm" method="POST" action="{{ route('follow.penawaran.store') }}">
                                @csrf
                                <input type="hidden" name="user_id" value="{{ auth()->id() }}">
                                <!-- ID pengguna yang sedang login -->
                                <input type="hidden" name="followed_user_id" value="{{ $project->user->id }}">
                                <!-- ID pemilik proyek -->
                                <input type="hidden" name="project_id" value="{{ $project->id }}">
                                <!-- ID proyek yang diikuti -->

                                @if ($follow)
                                    @if ($follow->status === 'pending')
                                        <button type="button" class="btn cmn-btn" disabled>Meminta</button>
                                    @elseif ($follow->status === 'accepted')
                                        <button type="button" class="btn cmn-btn" disabled>Diikuti</button>
                                    @elseif ($follow->status === 'declined')
                                        <button type="button" class="btn cmn-btn" disabled>Ditolak</button>
                                    @endif
                                @else
                                    <button type="submit" class="btn cmn-btn">Follow</button>
                                @endif
                            </form>
                        </div>
                        <div class="call widget-item">
                            <h3>Kontak</h3>
                            <a>{{ $project->kontak }}</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- End Project Details -->
@endsection
