@using Front.Services
@using Shared.DTOs
@inject HttpClientController hc;
<Modal @ref="modal" title=@Ticket.Title IsVerticallyCentered="true">
    <BodyTemplate>
        <Badge Color="@badgeColor" IndicatorType="BadgeIndicatorType.RoundedPill">@Ticket.MsgStatus</Badge>
        <Lchat Ticket="Ticket" />
    </BodyTemplate>
    <FooterTemplate>
        <Button Color="ButtonColor.Secondary" @onclick="OnHideModalClick">Close</Button>
        @if (Ticket.Status == StatusTicket.Awaitingreview || Ticket.Status == StatusTicket.Read_Checking
        || Ticket.Status == StatusTicket.hasbeenanswered)
        {
            <Button Color="ButtonColor.Danger" @onclick="OnCloseTicket">بستن تیکت</Button>
        }
       
    </FooterTemplate>
</Modal>

<li class="list-group-item" data-toggle="modal" data-target="#issue">
    <div class="row">
        <div class="col-md-2">
            <a style="cursor:pointer" @onclick="OnShowModalClick"><br />#@Ticket.TicketID</a>
        </div>
        <div class="col-md-5">
            <h6 style="cursor:pointer; color: #4793AF;" @onclick="OnShowModalClick">@Ticket.Title</h6>
            <Badge Color="@badgeColor" IndicatorType="BadgeIndicatorType.RoundedPill">@Ticket.MsgStatus</Badge>

        </div>

        @if (!string.IsNullOrEmpty(Ticket.EndDate))
        {
            
        <div style="text-align:center;" class="col-md-2">
            <p>تاریخ شروع <br /> @Ticket.CreateDate</p>
        </div>

            <div style="text-align:center;" class="col-md-2">
                <p>تاریخ پایان <br /> @Ticket.EndDate</p>
            </div>
        }
        else
        {

            <div style="text-align:center;" class="col-md-4">
                <br />  <p>تاریخ شروع  @Ticket.CreateDate</p>
            </div>
        }

    </div>
  
</li>

@code {
    [Parameter]
    public TicketDTO Ticket { get; set; }
    [Parameter]
    public EventCallback<int> OnMultipleOfThree { get; set; }
    public BadgeColor badgeColor = BadgeColor.Light;

    protected override async Task OnParametersSetAsync()
    {
        switch (Ticket.Status)
        {
            case StatusTicket.Awaitingreview:
                badgeColor = BadgeColor.Warning;
                break;
            case StatusTicket.Read_Checking:
                badgeColor = BadgeColor.Primary;
                break;
            case StatusTicket.hasbeenanswered:
                badgeColor = BadgeColor.Success;
                break;
            case StatusTicket.End:
                badgeColor = BadgeColor.Secondary;
                break;
            case StatusTicket.optout:
                badgeColor = BadgeColor.Danger;
                break;
            default:
                badgeColor = BadgeColor.Light;
                break;
        }
        await base.OnParametersSetAsync();
    }
    //-----------
    private Modal modal = default!;
    private async Task OnShowModalClick()
    {
        await modal.ShowAsync();
    }
    private async Task OnCloseTicket()
    {
        var rsp = await hc.Put($"Ticket/CancelTicket/{Ticket.TicketID}");
        if (rsp.IsSuccessStatusCode)
        {
         //  await Search(1);
            await modal.HideAsync();
           await OnMultipleOfThree.InvokeAsync(1);
        }
      


    }
    private async Task OnHideModalClick()
    {
        await modal.HideAsync();
        await OnMultipleOfThree.InvokeAsync(1);
    }
}
