{{-- Content block component (supports with_sidebar layout)
     Usage: @include('themes-manager::components.web.sections.content-block', ['sectionKey' => 'homepage_content_sidebar'])
--}}
@php
    $ts = themeService()->boot();
    $section = $ts->section($sectionKey ?? '');
    if (!$section) return;

    $settings = $ts->settings($sectionKey);
    $heading = $ts->trans($sectionKey, 'heading');
    $body = $ts->trans($sectionKey, 'body');
    $buttonText = $ts->trans($sectionKey, 'button_text');
    $buttonUrl = $ts->config($sectionKey, 'button_url', '');
    $layout = $settings['layout'] ?? 'full';
    $menuId = $settings['menu_id'] ?? null;
    $sidebarMenuTag = null;

    if ($layout === 'with_sidebar' && $menuId) {
        $sidebarMenu = \ViartasCore\Core\Models\Menu::find($menuId);
        $sidebarMenuTag = $sidebarMenu?->tag;
    }
@endphp

<section class="content-section"
    @if($settings['background_color'] ?? false)
        style="background-color: {{ $settings['background_color'] }};
               @if($settings['text_color'] ?? false) color: {{ $settings['text_color'] }}; @endif"
    @endif
>
    <div class="container-fluid-lg">
        @if($layout === 'with_sidebar')
            <div class="row g-4">
                {{-- Sidebar menu --}}
                @if($sidebarMenuTag)
                <div class="col-xxl-3 col-xl-3 d-none d-xl-block">
                    <div class="left-sidebar-box">
                        {!! menu($sidebarMenuTag) !!}
                    </div>
                </div>
                @endif

                {{-- Content --}}
                <div class="{{ $sidebarMenuTag ? 'col-xxl-9 col-xl-9' : 'col-12' }}">
                    @if($heading)
                        <div class="section-title">
                            <h2>{{ $heading }}</h2>
                        </div>
                    @endif
                    @if($body)
                        <div class="content-body">{!! $body !!}</div>
                    @endif

                    {{-- If this section has products too --}}
                    @if(isset($productsSlot))
                        {{ $productsSlot }}
                    @endif

                    @if($buttonText && $buttonUrl)
                        <a href="{{ $buttonUrl }}" class="btn theme-bg-color text-white btn-md mt-3">
                            {{ $buttonText }}
                        </a>
                    @endif
                </div>
            </div>
        @else
            @if($heading)
                <div class="section-title"><h2>{{ $heading }}</h2></div>
            @endif
            @if($body)
                <div class="content-body">{!! $body !!}</div>
            @endif
            @if($buttonText && $buttonUrl)
                <a href="{{ $buttonUrl }}" class="btn theme-bg-color text-white btn-md mt-3">{{ $buttonText }}</a>
            @endif
        @endif
    </div>
</section>
