@foreach($choice['childs'] as $option)
@php
$option = (array)$option;
$firstWord = explode(' ', $option['choices_name'])[0];
$hasImage = isset($option['choices_image']) && $option['choices_image'];
$imgSrc = $hasImage ? ($imagesBaseUrl ?? '') .'uploads/'.env('accountId').'/choices/original/'.$option['choices_image'] : '';
// Safe retrieval of show_name with explicit casting
$showName = 1; // Default to 1 (Show Name)
if (isset($choice['choices_show_name']) && $choice['choices_show_name'] !== null && $choice['choices_show_name'] !== '') {
$showName = (int)$choice['choices_show_name'];
}
// Determine Display Mode
// 1. Full (Name + Image): ShowName=1 && HasImage
// 2. Circle Only (Image): ShowName=0 && HasImage
// 3. Text Only: !HasImage (Fallback to text even if ShowName=0)
$isFull = ($showName === 1 && $hasImage);
$isCircleOnly = ($showName === 0 && $hasImage);
$isTextOnly = (!$hasImage);
$containerClass = 'choice-item d-flex align-items-center justify-content-center position-relative cursor-pointer';
if ($isFull) $containerClass .= ' has-icon';
if ($isTextOnly) $containerClass .= ' text-only';
if ($isCircleOnly) $containerClass .= ' circle-only';
@endphp
{{-- Icon / Circle Wrapper --}}
@if(!$isTextOnly)
@if($hasImage)
![{{ $option['choices_name'] }}]({{ $imgSrc }})
{{-- Fallback if image fails to load --}}
{{ $firstWord }}
@else
{{-- Fallback for Circle Only Mode when no image exists in DB --}}
{{ $firstWord }}
@endif
@endif
{{-- Text Label (Show if Full OR Text Only) --}}
@if(!$isCircleOnly)
{{ $option['choices_name'] }}
@endif
@endforeach