@extends('layouts.app') @push('styles') @endpush @php // جلب بيانات المحطة مباشرة من الرابط المخصص مع تضمين المحلات والمقالات بناءً على طلبك $stationId = request()->route('id') ?? request()->id; $station = null; $citiesMap = []; // خريطة ID المدينة => اسم المدينة if ($stationId) { $apiBase = config('app.map_api_base') ?? 'https://darbcp.sys.newtouch.sa/api/pages'; // جلب بيانات المحطة $response = \Illuminate\Support\Facades\Http::timeout(10)->get("{$apiBase}/interactive-map/stations/{$stationId}?include=shops,articals"); if ($response->ok()) { $fetchedData = $response->json(); $station = $fetchedData['data'] ?? $fetchedData; } // جلب قائمة المدن لترجمة رقم المدينة إلى اسمها try { $citiesResponse = \Illuminate\Support\Facades\Http::timeout(8)->get("{$apiBase}/interactive-map/cities"); if ($citiesResponse->ok()) { $citiesData = $citiesResponse->json(); $citiesList = $citiesData['data'] ?? $citiesData ?? []; if (is_array($citiesList)) { foreach ($citiesList as $city) { if (isset($city['id'])) { $citiesMap[(string) $city['id']] = $city['name'] ?? ''; } } } } } catch (\Throwable $e) { // تجاهل الخطأ، سيظهر رقم المدينة كاحتياطي } } @endphp @section('title', $station ? (json_decode($station['name'], true)['ar'] ?? 'تفاصيل المحطة') : __('map.station_details_title')) @section('meta_title', $station ? (json_decode($station['name'], true)['ar'] ?? 'تفاصيل المحطة') : __('map.station_details_title')) @section('description', $station ? ($station['about'] ?? $station['description'] ?? __('map.station_details_description')) : __('map.station_details_description')) @section('keywords', 'محطة درب, خدمات الطرق, ' . ($station ? (json_decode($station['name'], true)['ar'] ?? '') : '')) @section('og:title', $station ? (json_decode($station['name'], true)['ar'] ?? 'تفاصيل المحطة') : 'تفاصيل المحطة') @section('og:description', $station ? ($station['about'] ?? $station['description'] ?? 'معلومات تفصيلية عن محطة درب') : 'معلومات تفصيلية عن محطة درب') @section('og_image', $station && !empty($station['station_images']) ? (is_array($station['station_images']) ? ($station['station_images'][0] ?? asset('images/RFav.png')) : $station['station_images']) : asset('images/RFav.png')) @push('styles') @endpush @section('content')
@if(!$station)

{{ __('map.station_details_error_title') }}

{{ __('map.station_details_error_message') }}

@else @php $locale = app()->getLocale(); $stationNameDecoded = json_decode($station['name'] ?? '{}', true) ?: []; $stationName = $stationNameDecoded[$locale] ?? $stationNameDecoded['ar'] ?? $station['name'] ?? __('map.darb_station'); $stationTitleDecoded = json_decode($station['title'] ?? '{}', true) ?: []; $stationTitle = $stationTitleDecoded[$locale] ?? $stationTitleDecoded['ar'] ?? $stationTitleDecoded['en'] ?? null; $stationSummaryDecoded = json_decode($station['summary'] ?? '{}', true) ?: []; $stationSummary = $stationSummaryDecoded[$locale] ?? $stationSummaryDecoded['ar'] ?? $stationSummaryDecoded['en'] ?? null; // حل اسم المدينة من خريطة المدن (API يعيد city كرقم فقط مثل "6") $cityId = (string) ($station['city'] ?? ''); $cityName = '-'; if ($cityId && isset($citiesMap[$cityId])) { $rawCityName = $citiesMap[$cityId]; $decoded = is_string($rawCityName) ? json_decode($rawCityName, true) : null; if (is_array($decoded)) { $cityName = $decoded[$locale] ?? $decoded['ar'] ?? $decoded['en'] ?? $rawCityName; } elseif ($rawCityName) { $cityName = $rawCityName; } } elseif ($cityId) { $cityName = $cityId; } $address = $station['street'] ?? $station['address'] ?? '-'; $stationCode = $station['code'] ?? $station['station_code'] ?? '-'; $locationUrl = $station['location_url'] ?? null; $status = strtolower(trim($station['status'] ?? '')); $statusLabel = ($status === 'closed' || $status === '0' || $status === 'false') ? __('map.closed') : __('map.open'); $statusClass = $statusLabel === __('map.open') ? 'open' : ''; $imagesRaw = $station['station_images'] ?? []; if (is_string($imagesRaw)) { $decodedImages = json_decode($imagesRaw, true); if (is_array($decodedImages)) { $imagesRaw = $decodedImages; } else { $imagesRaw = array_filter(array_map('trim', explode(',', $imagesRaw))); } } $images = []; if (is_array($imagesRaw)) { foreach ($imagesRaw as $imgItem) { if (is_string($imgItem) && trim($imgItem)) { $images[] = trim($imgItem); } elseif (is_array($imgItem) || is_object($imgItem)) { $item = is_object($imgItem) ? (array) $imgItem : $imgItem; $url = $item['url'] ?? $item['path'] ?? $item['link'] ?? $item['image'] ?? $item['thumbnail'] ?? $item['thumb'] ?? ''; if ($url) { $images[] = trim($url); } } } } $images = array_values(array_filter($images)); $heroImage = $images[0] ?? asset('images/logo.gif'); $descriptionRaw = $stationSummary ?: $station['description'] ?? $station['details'] ?? $station['about'] ?? ''; if (is_string($descriptionRaw)) { $description = $descriptionRaw; } else { $descriptionDecoded = is_array($descriptionRaw) ? $descriptionRaw : (json_decode($descriptionRaw, true) ?: []); $description = is_array($descriptionDecoded) ? ($descriptionDecoded[$locale] ?? $descriptionDecoded['ar'] ?? $descriptionDecoded['en'] ?? '') : ''; } $shopsRaw = $station['shops'] ?? $station['shops_data'] ?? $station['services'] ?? []; if (is_string($shopsRaw)) { $shopsDecoded = json_decode($shopsRaw, true); $shopsRaw = is_array($shopsDecoded) ? $shopsDecoded : []; } $shops = is_array($shopsRaw) ? array_values($shopsRaw) : []; $availableShops = array_values(array_filter($shops, function ($shop) { if (!is_array($shop)) { return false; } $statusData = $shop['shop_status_option_data'] ?? null; if (is_string($statusData)) { $statusData = json_decode($statusData, true); } if (is_array($statusData) && isset($statusData['id']) && $statusData['id'] == 908) { return true; } $statusLabel = $shop['shop_status_label'] ?? ''; if ($statusLabel === 'Vacant' || $statusLabel === 'شاغر') { return true; } $statusValue = $shop['shop_status'] ?? ''; if ($statusValue === 'opt_1775048228180_40zg') { return true; } return false; })); $serviceIconMap = [ 'restaurant' => 'fa-utensils', 'cafe' => 'fa-mug-hot', 'market' => 'fa-shop', 'car_service' => 'fa-car', 'fuel' => 'fa-gas-pump', 'pharmacy' => 'fa-pills', 'other' => 'fa-star', ]; $shopsTypeCount = $station['shops_type_count'] ?? []; if (is_object($shopsTypeCount)) { $shopsTypeCount = (array) $shopsTypeCount; } if (is_string($shopsTypeCount)) { $shopsTypeCount = json_decode($shopsTypeCount, true) ?: []; if (is_object($shopsTypeCount)) { $shopsTypeCount = (array) $shopsTypeCount; } } $serviceCounts = is_array($shopsTypeCount) ? $shopsTypeCount : []; if (empty($serviceCounts)) { $servicesRaw = $station['services'] ?? $station['station_services'] ?? []; if (is_string($servicesRaw)) { $decodedServices = json_decode($servicesRaw, true); $servicesRaw = is_array($decodedServices) ? $decodedServices : []; } if (is_array($servicesRaw) && count($servicesRaw)) { foreach ($servicesRaw as $service) { $type = is_array($service) ? ($service['type'] ?? $service['service_type'] ?? 'other') : ($service ?: 'other'); $serviceCounts[$type] = ($serviceCounts[$type] ?? 0) + 1; } } else { foreach ($shops as $shop) { if (!is_array($shop)) { continue; } $type = $shop['type'] ?? $shop['category'] ?? $shop['service_type'] ?? 'other'; $serviceCounts[$type] = ($serviceCounts[$type] ?? 0) + 1; } } } $serviceIcons = []; foreach ($serviceCounts as $type => $count) { if ($count <= 0) continue; $serviceIcons[] = [ 'icon' => $serviceIconMap[$type] ?? $serviceIconMap['other'], 'label' => ucfirst(str_replace('_', ' ', $type)), 'count' => $count, ]; } if (empty($serviceIcons) && (count($shops) || ($station['shops_count'] ?? 0))) { $serviceIcons[] = [ 'icon' => 'fa-shop', 'label' => __('map.shops_count'), 'count' => $station['shops_count'] ?? count($shops), ]; } $articlesRaw = $station['articals_data'] ?? []; if (is_string($articlesRaw)) { $articlesRaw = json_decode($articlesRaw, true) ?: []; } $articles = []; if (is_array($articlesRaw)) { foreach ($articlesRaw as $article) { $articleTitleRaw = $article['title'] ?? $article['name'] ?? ''; $articleTitleDecoded = is_string($articleTitleRaw) ? json_decode($articleTitleRaw, true) : $articleTitleRaw; $articleTitle = is_array($articleTitleDecoded) ? ($articleTitleDecoded[$locale] ?? $articleTitleDecoded['ar'] ?? $articleTitleDecoded['en'] ?? '') : $articleTitleDecoded; $articleContentRaw = $article['content'] ?? ''; $articleContentDecoded = is_string($articleContentRaw) ? json_decode($articleContentRaw, true) : $articleContentRaw; $articleContent = is_array($articleContentDecoded) ? ($articleContentDecoded[$locale] ?? $articleContentDecoded['ar'] ?? $articleContentDecoded['en'] ?? '') : $articleContentDecoded; $articles[] = [ 'title' => $articleTitle ?: __('map.articles'), 'content' => $articleContent, 'facility' => $article['facility'] ?? null, ]; } } $articles = array_values(array_filter($articles, function ($item) { return !empty($item['title']) || !empty($item['content']); })); $mapLat = $station['latitude'] ?? $station['lat'] ?? null; $mapLng = $station['longitude'] ?? $station['lng'] ?? null; $mapQuery = $mapLat && $mapLng ? urlencode($mapLat . ',' . $mapLng) : urlencode($address . ' ' . $cityName); @endphp
{{ __('map.map') }} {{ __('map.breadcrumb_separator') }} {{ $stationName }}

{{ $stationTitle ?: $stationName }}

{{ $statusLabel }} @if(count($serviceIcons) > 0)
@foreach($serviceIcons as $service)
{{ $service['count'] }}
@endforeach
@endif
{{ $stationName }}

{{ __('map.station_info_title') }}

{{ __('map.city') }}{{ $cityName }}
{{ __('map.address') }}{{ $address }}
{{ __('map.station_code') }}{{ $stationCode }}
@if($locationUrl)
{{ __('map.location') }}{{ __('map.open_in_maps') }}
@endif
{{--
{{ __('map.shops_count') }}{{ $station['shops_count'] ?? count($shops) ?: '-' }}
--}} @if(!empty(strip_tags($description)))

{{ __('map.station_overview_title') }}

{{ $description }}

@endif
@if(count($images) > 0)

{{ __('map.station_images_title') }}

@foreach($images as $img)
{{ $stationName }}
@endforeach
@if(count($images) > 1)
@endif
@endif

{{ __('map.articles') }}

@if(count($articles) > 0)
@foreach($articles as $article)
@if(!empty($article['facility'])) {{ $article['title'] }} @else {{ $article['title'] }} @endif

{{ \Illuminate\Support\Str::limit($article['title'], 80) }}

{{ \Illuminate\Support\Str::limit(strip_tags($article['content']), 120) }}

@endforeach
@else

{{ __('map.no_articles') }}

@endif

{{ __('map.interest_heading') }}

{{--

{{ __('map.interest_description') }}

--}} {{ __('map.contact_now') }} {{ __('map.back_to_map') }}


@if(count($availableShops) > 0)

{{ __('map.vacant_shops_title') }}

@foreach($availableShops as $shop) @php $shopNameRaw = is_array($shop) ? ($shop['name'] ?? $shop['title'] ?? $shop['shop_name'] ?? __('map.shop')) : $shop; $shopName = is_string($shopNameRaw) ? (json_decode($shopNameRaw, true)['ar'] ?? $shopNameRaw) : $shopNameRaw; $shopType = is_array($shop) ? ($shop['type'] ?? $shop['category'] ?? '') : ''; $shopStatus = is_array($shop) ? ($shop['status'] ?? '') : ''; @endphp
{{ $shopName }}
@endforeach
@endif {{--

{{ __('map.contact_title') }}

{{ __('map.contact_desc') }}

--}}

{{ __('map.location') }}

{{ __('map.view_image') }}
@endif
@endsection @push('scripts') @endpush