@extends('views.layouts.master')
@section('content')
<!-- start of :: wrap -->
<div id="wrap" class="sub community event view">
	<div class="blog-details-part">
		<div class="container">
			<div class="row justify-content-center">
				<div class="col-lg-12 col-xl-10">
				    <div class="blog-details">
						<div class="blog-details-thumb">
							<img src="{{ msset($event['TurboMiddles']) }}" alt="blog">
						</div>
                        <div class="blog-details-content">
							<ul class="blog-details-meta">												
								<li class="date">
									<i class="fa-regular fa-calendar-days"></i>{{ $event['Pc4'] }} ~ {{ $event['Pc5'] }}
								</li>
								<li class="agency_name">{{ $event['Pc1'] }}</li>				
								<li>
									@foreach($event['AttachedFiles'] ?? [] as $file)
										<a href="{{ msset($file) }}" download
											class="file">
											{{ $file }}
										</a>
									@endforeach
								</li>
							</ul>
							<h2 class="blog-details-title">{{ $event['PostTitle'] }}</h2>
							<div class="blog_cont_wrap fr-view">
								{!! $event['PostContents'] !!}
							</div>
						</div>
						<div class="blog_bottom">	                    
							<div class="blog-details-navigate">
								@foreach ($event['PostPrenexts'] ?? [] as $prenext)
									@if ($prenext['Prenext'] === 'prev')
										<div class="blog-details-prev">
											<a class="nav-arrow" href="{{ route('status-details', $prenext['Slug']) }}"><i class="fas fa-arrow-left"></i>이전</a>
										</div>
									@else
										<div class="blog-details-next">
											<a class="nav-arrow" href="{{ route('status-details', $prenext['Slug']) }}">다음<i class="fas fa-arrow-right"></i></a>
										</div>
									@endif
								@endforeach
							</div>
							<div class="btn_wrap">
								<button type="button" class="btn btn_primary" onclick="location.href='/event'">목록</button>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

@endsection

@push('js')

    <script>
        $(document).on('click', '.agency_top button,.agency_bttom button', function() {
            let agencyId = $(this).data("agency");
            localStorage.setItem("agencyID", agencyId);
            window.location = "/agency-detail";
        });

        $(window).on('pageshow', function(event) {
            $.getJSON("/themes/point2u/pro/resources/assets/data/agency-data.json", function (data) {
                var html = '';
                $('.agency_top,.agency_bttom').empty();

                var startIndex = 0; // 시작 인덱스
                var endIndex = 30;
                var paginatedData = data.slice(startIndex, endIndex);

                $.each(paginatedData, function(i, entry) {
                    html += `<button data-agency="${entry.id}">
                      <img src="${entry.로고이미지}" alt="" />
                    </button>`;
                });
                $('.agency_top').append(html);

                startIndex = 31; // 시작 인덱스
                endIndex = data.length;
                paginatedData = data.slice(startIndex, endIndex);

                html = '';
                $.each(paginatedData, function(i, entry) {
                    html += `<button data-agency="${entry.id}">
                      <img src="${entry.로고이미지}" alt="" />
                    </button>`;
                });

                $('.agency_bttom').append(html);

            });
        });


        function agency_list(e) {
            const searchKey = $('#selopt :selected').val();
            const key = $('#txtagency').val(); // 검색어

            const id = e.id;
            $.getJSON("/themes/point2u/pro/resources/assets/data/agency-data.json", function (data) {

                var html = ''; // HTML을 저장할 변수 초기화
                var shouldInclude = function(text, key) {
                    return text.includes(key);
                };

                $('.agency_top,.agency_bttom').empty();  // .agency_top 내의 요소를 모두 비움

                var filteredData = [];
                if(key.length > 0){
                    filteredData = data.filter(function(entry) {
                        return (
                            (searchKey === 'n' && shouldInclude(entry.id, key)) ||
                            (searchKey === 'm' && entry.main.some(function(tag) { return shouldInclude(tag, key); })) ||
                            (searchKey === 'c' && entry.charge.some(function(tag) { return shouldInclude(tag, key); }))
                        );
                    });
                }else{
                    filteredData = data;
                }
                var startIndex = 0; // 시작 인덱스
                var endIndex = 30;

                var paginatedData = filteredData.slice(startIndex, endIndex);

                $.each(paginatedData, function(i, entry) {
                    html += `<button data-agency="${entry.id}">
                        <img src="${entry.로고이미지}" alt="" />
                      </button>`;
                });

                $('.agency_top').html(html); // 생성된 HTML을 .agency_top에 추가


                startIndex = 31; // 시작 인덱스
                endIndex = data.length;
                paginatedData = filteredData.slice(startIndex, endIndex);

                html = '';
                $.each(paginatedData, function(i, entry) {
                    html += `<button data-agency="${entry.id}">
                      <img src="${entry.로고이미지}" alt="" />
                    </button>`;
                });

                $('.agency_bttom').append(html);
            });
        }

        $(document).on('click', '.show_write', function() {
            $(this).parent().next().toggle();
        });

    </script>


@endpush
