|
1 | | -@props([ |
2 | | - 'item' => '', |
3 | | -]) |
| 1 | +@props(['item' => '']) |
4 | 2 |
|
5 | | -@use('Secondnetwork\Kompass\Models\File' , 'Files') |
| 3 | +@php |
| 4 | + // Normalizing item to object access for consistency if passed as array |
| 5 | + $item = (object) $item; |
| 6 | + $fieldData = collect($item->datafield); |
6 | 7 |
|
7 | | -@if ('download' == $item->type) |
8 | | -<div {{ $attributes }}> |
| 8 | + // Find image ID (from 'Bild' field) |
| 9 | + $imageField = $fieldData->firstWhere('type', 'image'); |
| 10 | + $imageId = null; |
| 11 | + if ($imageField) { |
| 12 | + $imageData = is_array($imageField) ? $imageField['data'] ?? null : $imageField->data ?? null; |
| 13 | + // Image data might be just an ID or an object with id |
| 14 | + if (is_numeric($imageData)) { |
| 15 | + $imageId = $imageData; |
| 16 | + } elseif (is_object($imageData) && isset($imageData->id)) { |
| 17 | + $imageId = $imageData->id; |
| 18 | + } |
| 19 | + } |
| 20 | + |
| 21 | + // Find Text content (wysiwyg) |
| 22 | + $textField = $fieldData->firstWhere('name', 'Text'); |
| 23 | + $textData = null; |
| 24 | + if ($textField) { |
| 25 | + $rawData = is_array($textField) ? $textField['data'] : $textField->data; |
| 26 | + $textData = is_array($rawData) ? (object) $rawData : json_decode($rawData); |
| 27 | + } |
| 28 | + |
| 29 | + // Find link (button) |
| 30 | + $linkField = $fieldData->firstWhere('type', 'link'); |
| 31 | + $link = null; |
| 32 | + if ($linkField) { |
| 33 | + $rawData = is_array($linkField) ? $linkField['data'] : $linkField->data; |
| 34 | + $link = is_array($rawData) ? (object) $rawData : json_decode($rawData); |
| 35 | + } |
| 36 | +@endphp |
9 | 37 |
|
10 | | - <div class=""> |
11 | | - @foreach ($item->datafield as $image) |
12 | | - |
13 | | - @php |
14 | | - $image = $image['data']; |
15 | | - |
16 | | - $file = Cache::rememberForever('kompass_imgId_'.$image, function () use ($image) { |
17 | | - return files::where('id', $image)->first(); |
18 | | - }); |
19 | | - @endphp |
20 | | - |
21 | | - <div class="bg-white p-6 mb-4 md:ml-16 rounded-lg text-black flex justify-between "> |
22 | | - {{ $file->name }} |
23 | | - <a class="flex items-center gap-4 text-black font-bold" download="" href="{{ asset('storage'.$file->path.'/'.$file->slug.'.'.$file->extension) }}">Download <x-tabler-download class="text-[var(--primary)]" /></a> |
24 | | - </div> |
25 | | - |
26 | | - @endforeach |
| 38 | +@if($item->type == 'download') |
| 39 | +<div class="p-6 rounded-lg shadow-sm flex flex-col items-center justify-between gap-6 text-center mx-5"> |
| 40 | + @if ($imageId) |
| 41 | + <div class="mt-auto"> |
| 42 | + <x-image :id="$imageId" class="w-full h-full rounded" /> |
| 43 | + </div> |
| 44 | + @endif |
| 45 | + |
| 46 | + <div class=""> |
| 47 | + @if($textData && isset($textData->blocks)) |
| 48 | + <div class="prose max-w-none"> |
| 49 | + @foreach ($textData->blocks as $block) |
| 50 | + @php $block = (object) $block; $blockData = (object) $block->data; @endphp |
| 51 | + @if($block->type === 'paragraph') |
| 52 | + <p class="text-gray-700 m-0">{!! $blockData->text !!}</p> |
| 53 | + @endif |
| 54 | + @endforeach |
| 55 | + </div> |
| 56 | + @endif |
27 | 57 | </div> |
28 | 58 |
|
29 | | - <div class="max-lg:hidden flex place-content-center -mt-20"> |
30 | | - <img src="{{ asset('images/download.svg') }}" alt="download"> |
31 | | - |
32 | | - </div> |
| 59 | + @if($link) |
| 60 | + <div class="flex-shrink-0"> |
| 61 | + <a href="{{ $link->url ?? '#' }}" class="btn btn-primary flex items-center gap-2"> |
| 62 | + {{ $link->title ?? 'Download' }} |
| 63 | + <x-tabler-download class="w-5 h-5" /> |
| 64 | + </a> |
| 65 | + </div> |
| 66 | + @endif |
33 | 67 | </div> |
34 | | - |
35 | 68 | @endif |
0 commit comments