#pragma checksum "/home/skins/projects/spanreed/Client/Pages/Room.razor" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "e9210fc4d52c122734885a31546ddcef421c3afb"
// <auto-generated/>
#pragma warning disable 1591
namespace spanreed.Client.Pages
{
    #line hidden
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Components;
#nullable restore
#line 1 "/home/skins/projects/spanreed/Client/_Imports.razor"
using System.Net.Http;

#line default
#line hidden
#nullable disable
#nullable restore
#line 2 "/home/skins/projects/spanreed/Client/_Imports.razor"
using System.Net.Http.Json;

#line default
#line hidden
#nullable disable
#nullable restore
#line 3 "/home/skins/projects/spanreed/Client/_Imports.razor"
using Microsoft.AspNetCore.Components.Forms;

#line default
#line hidden
#nullable disable
#nullable restore
#line 4 "/home/skins/projects/spanreed/Client/_Imports.razor"
using Microsoft.AspNetCore.Components.Routing;

#line default
#line hidden
#nullable disable
#nullable restore
#line 5 "/home/skins/projects/spanreed/Client/_Imports.razor"
using Microsoft.AspNetCore.Components.Web;

#line default
#line hidden
#nullable disable
#nullable restore
#line 6 "/home/skins/projects/spanreed/Client/_Imports.razor"
using Microsoft.AspNetCore.Components.Web.Virtualization;

#line default
#line hidden
#nullable disable
#nullable restore
#line 7 "/home/skins/projects/spanreed/Client/_Imports.razor"
using Microsoft.AspNetCore.Components.WebAssembly.Http;

#line default
#line hidden
#nullable disable
#nullable restore
#line 8 "/home/skins/projects/spanreed/Client/_Imports.razor"
using Microsoft.JSInterop;

#line default
#line hidden
#nullable disable
#nullable restore
#line 9 "/home/skins/projects/spanreed/Client/_Imports.razor"
using spanreed.Client;

#line default
#line hidden
#nullable disable
#nullable restore
#line 10 "/home/skins/projects/spanreed/Client/_Imports.razor"
using spanreed.Client.Shared;

#line default
#line hidden
#nullable disable
#nullable restore
#line 2 "/home/skins/projects/spanreed/Client/Pages/Room.razor"
using Microsoft.AspNetCore.SignalR.Client;

#line default
#line hidden
#nullable disable
#nullable restore
#line 3 "/home/skins/projects/spanreed/Client/Pages/Room.razor"
using spanreed.Shared;

#line default
#line hidden
#nullable disable
    [Microsoft.AspNetCore.Components.RouteAttribute("/{room}")]
    public partial class Room : Microsoft.AspNetCore.Components.ComponentBase, IDisposable
    {
        #pragma warning disable 1998
        protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
        {
            __builder.OpenElement(0, "div");
            __builder.AddAttribute(1, "class", "form-group");
            __builder.OpenElement(2, "label");
            __builder.AddMarkupContent(3, "\n        User:\n        ");
            __builder.OpenElement(4, "input");
            __builder.AddAttribute(5, "value", Microsoft.AspNetCore.Components.BindConverter.FormatValue(
#nullable restore
#line 11 "/home/skins/projects/spanreed/Client/Pages/Room.razor"
                      userInput

#line default
#line hidden
#nullable disable
            ));
            __builder.AddAttribute(6, "onchange", Microsoft.AspNetCore.Components.EventCallback.Factory.CreateBinder(this, __value => userInput = __value, userInput));
            __builder.SetUpdatesAttributeName("value");
            __builder.CloseElement();
            __builder.CloseElement();
            __builder.CloseElement();
            __builder.AddMarkupContent(7, "\n");
            __builder.OpenElement(8, "div");
            __builder.AddAttribute(9, "class", "form-group");
            __builder.OpenElement(10, "label");
            __builder.AddMarkupContent(11, "\n        Message:\n        ");
            __builder.OpenElement(12, "input");
            __builder.AddAttribute(13, "value", Microsoft.AspNetCore.Components.BindConverter.FormatValue(
#nullable restore
#line 17 "/home/skins/projects/spanreed/Client/Pages/Room.razor"
                      messageInput

#line default
#line hidden
#nullable disable
            ));
            __builder.AddAttribute(14, "onchange", Microsoft.AspNetCore.Components.EventCallback.Factory.CreateBinder(this, __value => messageInput = __value, messageInput));
            __builder.SetUpdatesAttributeName("value");
            __builder.CloseElement();
            __builder.CloseElement();
            __builder.CloseElement();
            __builder.AddMarkupContent(15, "\n");
            __builder.OpenElement(16, "button");
            __builder.AddAttribute(17, "onclick", Microsoft.AspNetCore.Components.EventCallback.Factory.Create<Microsoft.AspNetCore.Components.Web.MouseEventArgs>(this, 
#nullable restore
#line 20 "/home/skins/projects/spanreed/Client/Pages/Room.razor"
                  Send

#line default
#line hidden
#nullable disable
            ));
            __builder.AddAttribute(18, "disabled", 
#nullable restore
#line 20 "/home/skins/projects/spanreed/Client/Pages/Room.razor"
                                    !IsConnected

#line default
#line hidden
#nullable disable
            );
            __builder.AddContent(19, "Send");
            __builder.CloseElement();
            __builder.AddMarkupContent(20, "\n\n<hr>\n\n");
            __builder.OpenElement(21, "ul");
            __builder.AddAttribute(22, "id", "messagesList");
#nullable restore
#line 25 "/home/skins/projects/spanreed/Client/Pages/Room.razor"
     foreach (var message in messages)
    {

#line default
#line hidden
#nullable disable
            __builder.OpenElement(23, "li");
            __builder.OpenComponent<spanreed.Client.Pages.MessageComponent>(24);
            __builder.AddAttribute(25, "author", Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<System.String>(
#nullable restore
#line 27 "/home/skins/projects/spanreed/Client/Pages/Room.razor"
                                      message.Author

#line default
#line hidden
#nullable disable
            ));
            __builder.AddAttribute(26, "content", Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<System.String>(
#nullable restore
#line 27 "/home/skins/projects/spanreed/Client/Pages/Room.razor"
                                                              message.Content

#line default
#line hidden
#nullable disable
            ));
            __builder.AddAttribute(27, "timestamp", Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<System.DateTime>(
#nullable restore
#line 27 "/home/skins/projects/spanreed/Client/Pages/Room.razor"
                                                                                         message.Timestamp

#line default
#line hidden
#nullable disable
            ));
            __builder.CloseComponent();
            __builder.CloseElement();
#nullable restore
#line 28 "/home/skins/projects/spanreed/Client/Pages/Room.razor"
    }

#line default
#line hidden
#nullable disable
            __builder.CloseElement();
        }
        #pragma warning restore 1998
#nullable restore
#line 31 "/home/skins/projects/spanreed/Client/Pages/Room.razor"
       
    private HubConnection hubConnection;
    private List<ChatData> messages = new List<ChatData>();
    private string userInput;
    private string messageInput;
    [Parameter]
    public string room {get; set;}

    protected override async Task OnParametersSetAsync() {
        if (hubConnection != null) {
            try {
                await hubConnection.StopAsync(); 
            }
            finally {
                await hubConnection.DisposeAsync();
            }
        }

        messages.Clear();
        messageInput = "";

        hubConnection = new HubConnectionBuilder().WithUrl(NavigationManager.ToAbsoluteUri("/sendmessage")).Build();
        hubConnection.On<string, string, DateTime>("Received", (author, content, timestamp) => {
            messages.Add(new ChatData{Author = author, Content = content, Timestamp = timestamp});
            StateHasChanged();
        });
        var old_messages = await Http.GetFromJsonAsync<ChatData[]>($"Chat/{room}");

        if (old_messages != null) {
            foreach (var message in old_messages)
            {
                messages.Add(message);
            }
        }

        await hubConnection.StartAsync();

        await hubConnection.SendAsync("Connect", room);
    }

    Task Send() =>
        hubConnection.SendAsync("sendMessage", userInput, messageInput, room, DateTime.Now);

    public bool IsConnected =>
        hubConnection.State == HubConnectionState.Connected;

    public void Dispose() {
        _ = hubConnection.DisposeAsync();
    }

#line default
#line hidden
#nullable disable
        [global::Microsoft.AspNetCore.Components.InjectAttribute] private HttpClient Http { get; set; }
        [global::Microsoft.AspNetCore.Components.InjectAttribute] private NavigationManager NavigationManager { get; set; }
    }
}
#pragma warning restore 1591
