@if(!\Auth::check())
    @if($page_header)
        @if($page_header->html_code)
            <div class="community-info-page">
                <div class="additional-page-container">
                    <link rel="stylesheet" href="{{\URL::to('/')}}/themes/frontend/default/css/htmleditor/bulma.min.css">
                    <link rel="stylesheet" href="{{\URL::to('/')}}/themes/frontend/default/css/htmleditor/style.css">
                    <link rel="stylesheet" href="{{\URL::to('/')}}/themes/frontend/default/css/htmleditor/fontawesome-all.min.css">
                    
                    <div class="cmpage-description page-htmleditor">
                       <?php
							$contents=$page_header->html_code;
						?>   
						<?php
							$contents = communityTranslate(0,'websitepage-data-'.$page_header->id,$contents);
							$contents = replaceCommunityHeaderTokens($contents, $community ?? null, $homecontents ?? null, $pages ?? null);
						?>
						{!! $contents !!}	
                     </div>    	
                </div>	
            </div>
        @endif 
        
        @if($page_header->show_default_header==0)
             <style type="text/css">
                #top{
                    display:none !important;
                }
                body{
                    padding-top: 0px;
                }
             </style>	
        @endif   
        
        <style type="text/css">		            
            *, body, h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {
              font-family: 'Source Sans Pro', sans-serif;
            }
        </style>
    @endif
@endif

@php
    $imgUrl = function ($path) {
        $path = (string) $path;
        if ($path === '') {
            return '';
        }
        try {
            return (string) \Image::url($path);
        } catch (\Throwable $e) {
            return $path;
        }
    };

    $defaultHero = Theme::asset()->img('theme/images/page/display.jpg');
    $logo = $imgUrl($business->business_logo_square ?? '');
    $rectLogo = $imgUrl($business->business_logo_rectangle ?? '');
    $hero = $imgUrl($business->hero_photo ?? '');
    if ($hero === '') {
        $hero = $imgUrl($business->business_logo_rectangle ?? '');
    }
    if ($hero === '') {
        $hero = $logo;
    }
    if ($hero === '') {
        $hero = $defaultHero;
    }

    $title = (string) ($business->organization_name ?? '');
    $address = (string) ($business->organization_address ?? '');
    $email = (string) ($business->organization_email ?? '');
    $website = (string) ($business->website ?? '');
    $contact = (string) ($business->contact ?? '');
    $about = (string) ($business->about_organization ?? '');

    $normalizeUrl = function ($url) {
        $url = trim((string) $url);
        if ($url === '') {
            return '';
        }
        if (!preg_match('/^https?:\/\//i', $url)) {
            return 'http://' . $url;
        }
        return $url;
    };

    $websiteHref = $normalizeUrl($website);

    $categoriesList = $categories ?? [];
    $catId = $business->category_id ?? $business->category ?? null;
    $catId = is_numeric($catId) ? (int) $catId : 0;
    $categoryTitle = '';
    if (!empty($categoriesList) && $catId > 0) {
        foreach ($categoriesList as $cat) {
            if ((int) ($cat->id ?? 0) === $catId) {
                $categoryTitle = (string) ($cat->title ?? '');
                break;
            }
        }
    }

    $social = [
        'x_link' => (string) ($business->x_link ?? ''),
        'facebook_link' => (string) ($business->facebook_link ?? ''),
        'linkedin_link' => (string) ($business->linkedin_link ?? ''),
        'instagram_link' => (string) ($business->instagram_link ?? ''),
        'tiktok_link' => (string) ($business->tiktok_link ?? ''),
        'youtube_link' => (string) ($business->youtube_link ?? ''),
    ];
    foreach ($social as $k => $v) {
        $social[$k] = $normalizeUrl($v);
    }

    $mapQuery = trim($address);
    $mapSrc = '';
    if ($mapQuery !== '') {
        $mapSrc = 'https://www.google.com/maps?q=' . rawurlencode($mapQuery) . '&output=embed';
    }
@endphp

<style type="text/css">
	body{
		background:none !important;
	}
</style>

<div class="container page-content clearfix" style="padding-left:0px; background:#fff !important;">
    <div class="box idh-chamber-biz-box">
        <div class="box-content">
            <div class="idh-chamber-biz-layout">
                <div class="idh-chamber-biz-left">
                    <div class="idh-chamber-biz-header">
                        @if($logo !== '')
                            <div class="idh-chamber-biz-logo">
                                <img src="{{ $logo }}" alt="{{ e($title) }}" />
                            </div>
                        @endif

                        <div class="idh-chamber-biz-name">{{ $title }}</div>
                        @if($categoryTitle !== '')
                            <div class="idh-chamber-biz-category">{{ $categoryTitle }}</div>
                        @endif
                    </div>

                    <div class="idh-chamber-biz-section">
                        <div class="idh-chamber-biz-section-title">Contact Information</div>
                        <div class="idh-chamber-biz-contact">
                            @if($address !== '')
                                <div class="idh-chamber-biz-contact-row">{!! nl2br(e($address)) !!}</div>
                            @endif
                            @if($websiteHref !== '')
                                <div class="idh-chamber-biz-contact-row">Website: <a href="{{ $websiteHref }}" target="_blank" rel="noopener">{{ $website }}</a></div>
                            @endif
                            @if($contact !== '')
                                <div class="idh-chamber-biz-contact-row">Contact: @if($contact) +{{ $business->carrier_code }}@endif {{ $contact }}</div>
                            @endif
                            @if($email !== '')
                                <div class="idh-chamber-biz-contact-row">Email: <a href="mailto:{{ $email }}">{{ $email }}</a></div>
                            @endif
                        </div>

                        <div class="idh-chamber-biz-social">
                            @if($social['facebook_link'] !== '')
                                <a class="idh-chamber-biz-social-link" href="{{ $social['facebook_link'] }}" target="_blank" rel="noopener" aria-label="Facebook"><i class="fa fa-facebook-square"></i></a>
                            @endif
                            @if($social['instagram_link'] !== '')
                                <a class="idh-chamber-biz-social-link" href="{{ $social['instagram_link'] }}" target="_blank" rel="noopener" aria-label="Instagram"><i class="fa fa-instagram"></i></a>
                            @endif
                            @if($social['x_link'] !== '')
                                <a class="idh-chamber-biz-social-link" href="{{ $social['x_link'] }}" target="_blank" rel="noopener" aria-label="X" style="font-size:21px">X</a>
                            @endif
                            @if($social['linkedin_link'] !== '')
                                <a class="idh-chamber-biz-social-link" href="{{ $social['linkedin_link'] }}" target="_blank" rel="noopener" aria-label="LinkedIn"><i class="fa fa-linkedin-square"></i></a>
                            @endif
                            @if($social['tiktok_link'] !== '')
                                <a class="idh-chamber-biz-social-link" href="{{ $social['tiktok_link'] }}" target="_blank" rel="noopener" aria-label="TikTok"><i class="fa fa-music"></i></a>
                            @endif
                            @if($social['youtube_link'] !== '')
                                <a class="idh-chamber-biz-social-link" href="{{ $social['youtube_link'] }}" target="_blank" rel="noopener" aria-label="YouTube"><i class="fa fa-youtube-play"></i></a>
                            @endif
                        </div>
                    </div>

                    @if($mapSrc !== '')
                        <div class="idh-chamber-biz-map">
                            <iframe src="{{ $mapSrc }}" loading="lazy" referrerpolicy="no-referrer-when-downgrade" allowfullscreen></iframe>
                        </div>
                    @endif

                    {{-- Hours of Operation (commented out for now) --}}
                    {{---
                    <div class="idh-chamber-biz-section idh-chamber-biz-hours">
                        <div class="idh-chamber-biz-section-title">Hours of Operation</div>
                        <div class="idh-chamber-biz-hours-body">-</div>
                    </div>
                    ---}}
                </div>

                <div class="idh-chamber-biz-right">
                    <div class="idh-chamber-biz-top">
                        <div class="idh-chamber-biz-about">
                            @if($about !== '')
                                <div class="idh-chamber-biz-about-body">{!! $about !!}</div>
                            @else
                                <div class="idh-chamber-biz-about-body">-</div>
                            @endif

                            @if($rectLogo !== '')
                                <div class="idh-chamber-biz-rectlogo">
                                    <img src="{{ $rectLogo }}" alt="{{ e($title) }}" />
                                </div>
                            @endif
                        </div>
                        <div class="idh-chamber-biz-hero">
                            <img src="{{ $hero }}" alt="{{ e($title) }}" />
                        </div>
                    </div>

                    {{-- Reviews intentionally skipped as requested --}}
                </div>
            </div>
        </div>
    </div>
</div>