@using Shared.DTOs
@inject HttpClient _hc
@layout EmptyLayout
@page "/BlogDetails/{ItemID:int}"
@inject NavigationManager Navigation
<PageTitle>@Item?.Title</PageTitle>

<HeadContent>
    <!-- Place favicon.ico in the root directory -->
    <link rel="shortcut icon" type="image/x-icon" href="img/favicon.png">

    <!-- CSS here -->
    <link rel="stylesheet" href="css/bootstrap.rtl.min.css">
    <link rel="stylesheet" href="css/animate.css">
    <link rel="stylesheet" href="css/custom-animation.css">
    <link rel="stylesheet" href="css/slick.css">
    <link rel="stylesheet" href="css/nice-select.css">
    <link rel="stylesheet" href="css/flaticon.css">
    <link rel="stylesheet" href="css/swiper-bundle.css">
    <link rel="stylesheet" href="css/meanmenu.css">
    <link rel="stylesheet" href="css/font-awesome-pro.css">
    <link rel="stylesheet" href="css/magnific-popup.css">
    <link rel="stylesheet" href="css/spacing.css">
    <link rel="stylesheet" href="css/Lanstyle.css">
    <link rel="stylesheet" href="css/rtl.css">


    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="language" content="FA" />
    <meta name="description" content="@description" />
</HeadContent>
<LBlogheader />
<div id="smooth-wrapper">
    <div id="smooth-content">
        <main>

            <!-- breadcrumb-area-start -->
            <div style="border-radius: .8em;" 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" width="400" height="400" alt="@Item?.Title">
                            </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">

                                        @((MarkupString)Item?.Text)


                                    </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__search">
                                            <form action="#">
                                                <div class="sidebar__search-input-2">

                                                    <InputText @bind-Value="strSearch" type="text" class="inputText" placeholder="کلمه ای را بنویسید ..." />
                                             
                                                    <button @onclick="SearchClick">
                                                        <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
                                                            <path d="M8.01371 15.2219C11.9525 15.2219 15.1456 12.0382 15.1456 8.11096C15.1456 4.18368 11.9525 1 8.01371 1C4.07488 1 0.881836 4.18368 0.881836 8.11096C0.881836 12.0382 4.07488 15.2219 8.01371 15.2219Z" stroke="#5F6168" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
                                                            <path d="M16.9287 16.9996L13.0508 13.1331" stroke="#5F6168" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
                                                        </svg>
                                                    </button>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                                <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>

                                    </div>

                                </div>
                                @if (Item != null && !string.IsNullOrEmpty(Item.Tags))
                                {
                                    <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="tagcloud">
                                                @foreach (var item in Item.Tags.Split('-'))
                                                {
                                                    string P = "/ListBlog/" + item;
                                                    <NavLink rel="tag" href="@P">@item</NavLink>
                                                }


                                            </div>
                                        </div>
                                    </div>
                                }



                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- postbox area end -->



        </main>
        <Lfooter />
    </div>
</div>






@code {
    //meta tags
    public string description { get; set; }
    //---------------------
    public string strSearch { get; set; }
    [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 await GenerateTags();
        }

        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 SearchClick()
    {
        if (!string.IsNullOrEmpty(strSearch))
            Navigation.NavigateTo("/SearchBlog/" + strSearch);
    }
    public async Task<BlogDtoFull?> GetItems()
    {
        var response = await _hc.GetAsync($"Base/GetBlogByID/{ItemID}");

        if (!response.IsSuccessStatusCode)
            return null;


        return await response.Content.ReadFromJsonAsync<BlogDtoFull>();
    }
    public async Task GenerateTags()
    {
    
        description = Item.Description ?? Item.Title;

    }
}
