@using Front.Services
@using Shared.DTOs
@inject HttpClientController hc;
@inject Fixedvalues fv;
<Modal @ref="cusmodal" />
<Modal @ref="codmodal" />
<div class="col-md-6 col-lg-4 col-xl-4 order-0 mb-4">
    <div class="card h-51">
        <div class="card-header d-flex align-items-center justify-content-between pb-0">
            <div class="card-title mb-0">
                <h5 class="m-0 me-2">آخرین</h5>
            </div>
        </div>
        <div class="card-body">
            <div class="d-flex justify-content-between align-items-center mb-3">
                <div class="d-flex flex-column align-items-center gap-1">
                </div>
                <div id="orderStatisticsChart"></div>
            </div>
            <ul class="p-0 m-0">
                @if (dashBoard!=null && dashBoard.lastActivitiesSevices.Any(w => w.PermissionID == 3))
                {
                    <li class="d-flex mb-4 pb-1">
                        <div class="avatar flex-shrink-0"><img src="assets/img/icons/unicons/cc-success.png" alt="User" class="rounded"></div>
                        <div class="d-flex w-100 flex-wrap align-items-center justify-content-between gap-2">
                            <div class="me-2">
                                @{int invoid = Convert.ToInt32(dashBoard?.lastActivitiesSevices.Where(w => w.PermissionID == 3).Select(s => s.ID).First());}

                                <button @onclick="()=>InvoiceItem(invoid)" type="button" class="btn btn-link">صورتحساب</button>
                                <small>مربوط به مشتری @dashBoard?.lastActivitiesSevices.Where(w => w.PermissionID == 3).Select(s => s.Name).First() در وضعیت @dashBoard.lastActivitiesSevices.Where(w => w.PermissionID == 3).Select(s => s.TypeTitle).First()</small>
                            </div>
                        </div>
                    </li>
                }
                @if (dashBoard != null && dashBoard.lastActivitiesSevices.Any(w => w.PermissionID == 4))
                {
                    <li class="d-flex mb-4 pb-1">
                        <div class="avatar flex-shrink-0"><img src="assets/img/icons/unicons/wallet-info.png" alt="chart success" class="rounded"></div>
                        <div class="d-flex w-100 flex-wrap align-items-center justify-content-between gap-2">
                            <div class="me-2">
                                @{
                                    int codid = Convert.ToInt32(dashBoard?.lastActivitiesSevices.Where(w => w.PermissionID == 4).Select(s => s.ID).First());
                                }
                                <button @onclick="()=>CODItem(codid)" type="button" class="btn btn-link">کالا</button>
                             
                                <small>با عنوان @dashBoard?.lastActivitiesSevices.Where(w => w.PermissionID == 4).Select(s => s.Name).First()</small>
                            </div>
                        </div>
                    </li>
                }
                @if (dashBoard != null && dashBoard.lastActivitiesSevices.Any(w => w.PermissionID == 8))
                {
                    <li class="d-flex mb-4 pb-1">
                        <div class="avatar flex-shrink-0"><img src="assets/img/icons/unicons/cc-primary.png" alt="chart success" class="rounded"></div>
                        <div class="d-flex w-100 flex-wrap align-items-center justify-content-between gap-2">
                            <div class="me-2">
                                @{ int cusid = Convert.ToInt32(dashBoard?.lastActivitiesSevices.Where(w => w.PermissionID == 8).Select(s => s.ID).First());}
                                <button @onclick="()=>CustomerItem(cusid)" type="button" class="btn btn-link">مشتری</button>
                             <small>با نام @dashBoard?.lastActivitiesSevices.Where(w => w.PermissionID == 8).Select(s => s.Name).First()</small>
                            </div>
                        </div>
                    </li>
                }
            </ul>
        </div>
    </div>
</div>

@code {
    [Parameter] public DashBoardDTO? dashBoard { get; set; }
    private Modal cusmodal = default!;
    private Modal codmodal = default!;
}
@functions{
    public async Task CallBackCustomerItem(ActionInResultComponent result)
    {

    }
    public async Task InvoiceItem(int ID) => hc._nav.NavigateTo($"InvoiceDetails/{ID}");
    public async Task CustomerItem(int ID)
    {
        var rsp = await hc.Get($"Customer/GetCustomer/{ID}");
        if (rsp.IsSuccessStatusCode)
        {
            var cus = await rsp.Content.ReadFromJsonAsync<RCustomer>();
            var parameters = new Dictionary<string, object>();
            parameters.Add("Cus", cus);
            parameters.Add("OnMultipleOfThree", EventCallback.Factory.Create<ActionInResultComponent>(this, CallBackCustomerItem));
            await cusmodal.ShowAsync<CUSComponent.CustomerItem>(title: "ویرایش اطلاعات", parameters: parameters);
        }
    }
    public async Task CallBackCodItem(ActionInResultComponent result){}
    public async Task CODItem(int ID){
        var rsp = await hc.Get($"Cod/GetCod/{ID}");
        if (rsp.IsSuccessStatusCode)
        {
            var cod = await rsp.Content.ReadFromJsonAsync<RCOD>();
            var parameters = new Dictionary<string, object>();
            var Unitrequest = await fv.GetUnits();
            parameters.Add("Cod", cod);
            parameters.Add("Unitrequest", Unitrequest);
            parameters.Add("OnMultipleOfThree", EventCallback.Factory.Create<ActionInResultComponent>(this, CallBackCodItem));
            await codmodal.ShowAsync<CUSComponent.CodItem>(title: "ویرایش اطلاعات", parameters: parameters);
        
        }
       
    }
}