{{--<div class="bg-white dark:bg-gray-800 rounded-xl shadow-lg border-t-4 border-cyan-500">--}}
{{--    <div class="p-6">--}}
{{--        <h3 class="text-lg font-semibold text-gray-900 dark:text-white">--}}
{{--            <i class="fa fa-bullhorn text-cyan-500 ml-2"></i>--}}
{{--            بورد اطلاعیه‌های تیم--}}
{{--        </h3>--}}

{{--        <div class="mt-4 space-y-4">--}}
{{--            @forelse ($announcements as $announcement)--}}
{{--                @php--}}
{{--                    $levelClasses = [--}}
{{--                        'info' => 'bg-blue-50 dark:bg-blue-900/50 border-blue-400',--}}
{{--                        'warning' => 'bg-yellow-50 dark:bg-yellow-900/50 border-yellow-400',--}}
{{--                        'danger' => 'bg-red-50 dark:bg-red-900/50 border-red-400',--}}
{{--                    ][$announcement->level] ?? 'bg-gray-50 dark:bg-gray-700/50 border-gray-400';--}}
{{--                @endphp--}}
{{--                --}}{{-- [NEW] Added Alpine.js data for toggling --}}
{{--                <div x-data="{ expanded: false }" class="p-4 rounded-lg border-r-4 {{ $levelClasses }}">--}}
{{--                    <div class="flex items-center justify-between">--}}
{{--                        <p class="font-semibold text-gray-800 dark:text-gray-200">{{ $announcement->title }}</p>--}}
{{--                        @if($announcement->is_pinned)--}}
{{--                            <x-lucide-pin class="w-4 h-4 text-gray-500" />--}}
{{--                        @endif--}}
{{--                    </div>--}}

{{--                    --}}{{-- [NEW] Text container with line-clamp --}}
{{--                    <p class="mt-2 text-sm text-gray-600 dark:text-gray-300"--}}
{{--                       x-ref="body"--}}
{{--                       :class="{ 'line-clamp-2': !expanded }">--}}
{{--                        {{ $announcement->body }}--}}
{{--                    </p>--}}

{{--                    --}}{{-- [NEW] "Read More" button that only shows if text is long --}}
{{--                    <div x-data="{ isClamped: false }"--}}
{{--                         x-init="isClamped = ($refs.body.scrollHeight > $refs.body.clientHeight)"--}}
{{--                         x-show="isClamped"--}}
{{--                         class="mt-2">--}}
{{--                        <button @click="expanded = !expanded" class="text-xs font-semibold text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-300">--}}
{{--                            <span x-show="!expanded">بیشتر بخوانید</span>--}}
{{--                            <span x-show="expanded" style="display: none;">بستن</span>--}}
{{--                        </button>--}}
{{--                    </div>--}}

{{--                    <p class="mt-3 text-xs text-gray-500 dark:text-gray-400 text-left">--}}
{{--                        توسط {{ $announcement->user->name }} در تیم {{ $announcement->team->name }} - {{ verta($announcement->created_at)->formatDifference() }}--}}
{{--                    </p>--}}
{{--                </div>--}}
{{--            @empty--}}
{{--                <div class="text-center py-8">--}}
{{--                    <i class="fa fa-check-circle text-gray-400 text-4xl mx-auto"></i>--}}
{{--                    <p class="mt-2 text-sm text-gray-500">در حال حاضر اطلاعیه جدیدی وجود ندارد.</p>--}}
{{--                </div>--}}
{{--            @endforelse--}}
{{--        </div>--}}
{{--    </div>--}}
{{--</div>--}}
<div class="bg-white dark:bg-gray-800 rounded-xl shadow-lg border-t-4 border-cyan-500">
    <div class="p-6">
        <h3 class="text-lg font-semibold text-gray-900 dark:text-white">
            <i class="fa fa-bullhorn text-cyan-500 ml-2"></i>
            بورد اطلاعیه‌های تیم
        </h3>

        <div class="mt-4 space-y-4">
            @forelse ($announcements as $announcement)
                @php
                    $levelClasses = [
                        'info' => 'bg-blue-50 dark:bg-blue-900/50 border-blue-400',
                        'warning' => 'bg-yellow-50 dark:bg-yellow-900/50 border-yellow-400',
                        'danger' => 'bg-red-50 dark:bg-red-900/50 border-red-400',
                    ][$announcement->level] ?? 'bg-gray-50 dark:bg-gray-700/50 border-gray-400';
                @endphp
                <div x-data="{ expanded: false }" class="p-4 rounded-lg border-r-4 {{ $levelClasses }}">
                    <div class="flex items-center justify-between">
                        <p class="font-semibold text-gray-800 dark:text-gray-200">{{ $announcement->title }}</p>
                        @if($announcement->is_pinned)
                            <x-lucide-pin class="w-4 h-4 text-gray-500" />
                        @endif
                    </div>

                    <p class="mt-2 text-sm text-gray-600 dark:text-gray-300"
                       x-ref="body"
                       :class="{ 'line-clamp-2': !expanded }">
                        {{ $announcement->body }}
                    </p>

                    <div x-data="{ isClamped: false }"
                         x-init="isClamped = ($refs.body.scrollHeight > $refs.body.clientHeight)"
                         x-show="isClamped"
                         class="mt-2">
                        <button @click="expanded = !expanded" class="text-xs font-semibold text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-300">
                            <span x-show="!expanded">بیشتر بخوانید</span>
                            <span x-show="expanded" style="display: none;">بستن</span>
                        </button>
                    </div>

                    {{-- [NEW] Attachment Download Link --}}
                    @if($announcement->attachment_path)
                        <div class="mt-3 pt-3 border-t border-gray-200 dark:border-gray-600">
                            <a href="{{ Storage::url($announcement->attachment_path) }}" target="_blank" class="inline-flex items-center text-xs font-medium text-blue-600 hover:underline">
                                <x-lucide-paperclip class="w-3 h-3 ml-1" />
                                دانلود فایل پیوست ({{ $announcement->attachment_name }})
                            </a>
                        </div>
                    @endif

                    <p class="mt-3 text-xs text-gray-500 dark:text-gray-400 text-left">
                        توسط {{ $announcement->user->name }} در تیم {{ $announcement->team->name }} - {{ verta($announcement->created_at)->formatDifference() }}
                    </p>
                </div>
            @empty
                <div class="text-center py-8">
                    <i class="fa fa-check-circle text-gray-400 text-4xl mx-auto"></i>
                    <p class="mt-2 text-sm text-gray-500">در حال حاضر اطلاعیه جدیدی وجود ندارد.</p>
                </div>
            @endforelse
        </div>
    </div>
</div>
