@using Shared.DTOs
@inject HttpClient _hc
@layout BlogLayout
@page "/BlogDetails/{ItemID:int}"
@inject NavigationManager Navigation
<PageTitle>دانشنامه</PageTitle>

<main>

    <!-- breadcrumb-area-start -->
    <div class="breadcrumb__area breadcrumb-ptb-4 p-relative blue-bg-2">
        <div class="breadcrumb__shape-1">
            <img src="img/breadcrumb/breadcrumb-shape-1.png" alt="">
        </div>
        <div class="breadcrumb__shape-2">
            <img src="img/breadcrumb/breadcrumb-shape-2.png" alt="">
        </div>
        <div class="container">
            <div class="row align-items-end">
                <div class="col-xl-9 col-lg-9 col-md-9">
                    <div class="blog-details-banner z-index-2">
                        <div class="blog-details-title-box">
                            <div class="tp-blog-meta d-flex align-items-center">
                                <div class="tp-blog-category category-color-1"><span>@Item?.Title.Split(':')[0]</span></div><!--!-->
                                <div class="tp-blog-date"><span>@Item?.Date</span></div>
                            </div>
                            <h4 class="blog-details-banner-title">@Item?.Title.Split(':')[1]</h4>
                        </div>
                        <div class="tp-blog-author-info-box d-flex align-items-center">
                            <div class="tp-blog-avata">
                                <img src="img/avata/blog-avata-Publisher.png" alt="">
                            </div>
                            <div class="tp-blog-author-info">
                                <h5>مهدی ربیع نژاد</h5>
                                <span>مدیر سایت</span>
                            </div>
                        </div>
                    </div>
                </div>
              
            </div>
        </div>
    </div>
    <!-- breadcrumb-area-end -->
    <!-- breadcrumb-banner-start -->
    <div class="blog-details-img-area mb-80">
        <div class="container">
            <div class="row">
                <div class="col-xl-12">
                    <div class="blog-details-big-img z-index-2">
                        <img src="img/blog/@Item?.Photo" alt="">
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- breadcrumb-banner-end -->
    <!-- postbox area start -->
    <div class="postbox__area pt-100 pb-100">
        <div class="container">
            <div class="row">
                <div class="col-xxl-8 col-xl-8 col-lg-8">
                    <div class="postbox__details-wrapper pr-20">
                        <article>
                           
                            <div class="postbox__details-title-box pb-30">
                          
                                <p>
                                    @Item?.Text
                                </p>
                               
                            </div>
                    
         
                            <div class="postbox__details-qoute mb-30">
                                <blockquote class="d-flex align-items-start">
                                    <div class="postbox__details-qoute-icon">
                                        <svg width="37" height="27" viewBox="0 0 37 27" fill="none" xmlns="http://www.w3.org/2000/svg">
                                            <path d="M35.046 0.402002C32.4553 2.01 30.222 3.97534 28.346 6.298C26.5593 8.53133 25.3533 10.8093 24.728 13.132C25.3533 12.596 26.0233 12.194 26.738 11.926C27.542 11.5687 28.3013 11.39 29.016 11.39C31.16 11.39 32.9467 12.1493 34.376 13.668C35.8053 15.0973 36.52 16.884 36.52 19.028C36.52 21.172 35.7607 22.9587 34.242 24.388C32.8127 25.8173 31.026 26.532 28.882 26.532C26.6487 26.532 24.8173 25.7727 23.388 24.254C21.9587 22.7353 21.244 20.77 21.244 18.358C21.244 15.142 22.1373 11.7027 23.924 8.04C25.8 4.288 27.8993 1.608 30.222 0H35.046V0.402002ZM13.802 0.402002C11.2113 2.01 8.978 3.97534 7.102 6.298C5.31533 8.53133 4.10933 10.8093 3.484 13.132C4.10933 12.596 4.77933 12.194 5.494 11.926C6.298 11.5687 7.05733 11.39 7.772 11.39C9.916 11.39 11.7027 12.1493 13.132 13.668C14.5613 15.0973 15.276 16.884 15.276 19.028C15.276 21.172 14.5167 22.9587 12.998 24.388C11.5687 25.8173 9.782 26.532 7.638 26.532C5.40467 26.532 3.57333 25.7727 2.144 24.254C0.714667 22.7353 0 20.77 0 18.358C0 15.142 0.893333 11.7027 2.68 8.04C4.556 4.288 6.65533 1.608 8.978 0H13.802V0.402002Z" fill="#CDCECF"></path>
                                        </svg>
                                    </div>
                                    <div class="postbox__details-qoute-text">
                                        <p>“تیم در سافت تک فوق العاده اختصاصی ، دانش و مفید است.</p>
                                        <span>سقراط</span>
                                    </div>
                                </blockquote>
                            </div>
               
                          
               
                            
                          
                
                        </article>
                    </div>
                </div>
                <div class="col-xxl-4 col-xl-4 col-lg-4">
                    <div class="sidebar__wrapper">
            
                        <div class="sidebar__widget mb-40">
                            <div class="sidebar__widge-title-box">
                                <h3 class="sidebar__widget-title">پست های اخیر</h3>
                            </div>
                            <div class="sidebar__widget-content">
                                <div class="sidebar__post rc__post">
                                    @foreach (var item in collectionitem)
                                    {
                                        <ItemBlog___v2 Item="item"/>
                                    }
                      
                              
                                </div><a href="blog-details.html">
                                </a>
                            </div><a href="blog-details.html">
                            </a>
                        </div><a href="blog-details.html">
                        </a>
                      
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- postbox area end -->
  


</main>

@code {
    [Parameter]
    public int? ItemID { get; set; }

    public List<BlogDto> collectionitem { get; set; } = new List<BlogDto>();
    public BlogDtoFull? Item { get; set; }
    protected override async Task OnParametersSetAsync()
    {
        if (ItemID != null)
        {
            Item = await GetItems();
            if (Item==null)
                Navigation.NavigateTo("/");

        }

        else
            Navigation.NavigateTo("/");
        await base.OnParametersSetAsync();
    }
    protected override async Task OnInitializedAsync()
    {
        
        var request = await _hc.GetFromJsonAsync<PagingDto<BlogDto>>($"Base/LastBlog?PageIndex=1&PageSize=3");
        if (request !=null)
        collectionitem = request.list;
        
        await base.OnInitializedAsync();
    }
}
@functions{
    public async Task<BlogDtoFull?> GetItems()
    {
        var response = await _hc.GetAsync($"Base/GetBlogByID/{ItemID}");

        if (!response.IsSuccessStatusCode)
        return null;
        

        return await response.Content.ReadFromJsonAsync<BlogDtoFull>();
    }
}
