#pragma checksum "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\Pages\Projects.razor" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "b85f43099b5a41e9cf7e3314e3ccd49c99e331d7"
// <auto-generated/>
#pragma warning disable 1591
#pragma warning disable 0414
#pragma warning disable 0649
#pragma warning disable 0169

namespace SPWA.Pages
{
    #line hidden
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Components;
#nullable restore
#line 2 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\_Imports.razor"
using System.Net.Http;

#line default
#line hidden
#nullable disable
#nullable restore
#line 3 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\_Imports.razor"
using Microsoft.AspNetCore.Authorization;

#line default
#line hidden
#nullable disable
#nullable restore
#line 4 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\_Imports.razor"
using Microsoft.AspNetCore.Components.Authorization;

#line default
#line hidden
#nullable disable
#nullable restore
#line 5 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\_Imports.razor"
using Microsoft.AspNetCore.Components.Forms;

#line default
#line hidden
#nullable disable
#nullable restore
#line 6 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\_Imports.razor"
using Microsoft.AspNetCore.Components.Routing;

#line default
#line hidden
#nullable disable
#nullable restore
#line 7 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\_Imports.razor"
using Microsoft.AspNetCore.Components.Web;

#line default
#line hidden
#nullable disable
#nullable restore
#line 8 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\_Imports.razor"
using Microsoft.JSInterop;

#line default
#line hidden
#nullable disable
#nullable restore
#line 9 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\_Imports.razor"
using SPWA;

#line default
#line hidden
#nullable disable
#nullable restore
#line 10 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\_Imports.razor"
using SPWA.Shared;

#line default
#line hidden
#nullable disable
#nullable restore
#line 11 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\_Imports.razor"
using MatBlazor;

#line default
#line hidden
#nullable disable
#nullable restore
#line 12 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\_Imports.razor"
using BlazorInputFile;

#line default
#line hidden
#nullable disable
#nullable restore
#line 14 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\_Imports.razor"
using Microsoft.AspNetCore.DataProtection;

#line default
#line hidden
#nullable disable
#nullable restore
#line 15 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\_Imports.razor"
using SPWA.LoginFeatures.Account.Pages.GoogleLogin;

#line default
#line hidden
#nullable disable
#nullable restore
#line 2 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\Pages\Projects.razor"
using Project.Data;

#line default
#line hidden
#nullable disable
#nullable restore
#line 3 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\Pages\Projects.razor"
using Project.Data.Project;

#line default
#line hidden
#nullable disable
#nullable restore
#line 4 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\Pages\Projects.razor"
using Microsoft.AspNetCore.Identity;

#line default
#line hidden
#nullable disable
#nullable restore
#line 5 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\Pages\Projects.razor"
using SPWA.DataAccess.Data;

#line default
#line hidden
#nullable disable
    [Microsoft.AspNetCore.Components.RouteAttribute("/projects")]
    public partial class Projects : OwningComponentBase<ProjectService>
    {
        #pragma warning disable 1998
        protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
        {
        }
        #pragma warning restore 1998
#nullable restore
#line 225 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\Pages\Projects.razor"
       
    // AuthenticationState is available as a CascadingParameter
    [CascadingParameter]
    private Task<AuthenticationState> authenticationStateTask { get; set; }
    System.Security.Claims.ClaimsPrincipal CurrentUser;

    // Options to display in the approved dropdown when editing a Project
    List<string> Options = new List<string>() { "Approved", "Rejected" };
    ApplicationUser objUser = new ApplicationUser();
    public UserManager<ApplicationUser> UserManager { get; private set; }
    List<Project> projects;
    List<ApplicationUser> ColUsers = new List<ApplicationUser>();

    protected override async Task OnInitializedAsync()
    {
        await GetUsers();
        // Get the current user
        var user = (await authenticationStateTask).User;
        // Get the Projects for the current user
        // We access ProjectService using @Service
        projects = await @Service.GetProjectAsync();
        CurrentUser = (await authenticationStateTask).User;
    }
    bool lockPop = false;
    Project objProject = new Project();
    bool ShowPopup = false;
    bool ReadMorePopup = false;
    bool addMember = false;
    string userToAddToProject = "";

    void ClosePopup()
    {
        // Close the Popup
        ShowPopup = false;
    }


    public async Task GetUsers()
    {
        // Collection to hold users
        ColUsers = new List<ApplicationUser>();
        // get users from _UserManager
        var user = _UserManager.Users.Select(x => new ApplicationUser
        {
            Id = x.Id,
            UserName = x.UserName,
            Email = x.Email,
            PasswordHash = "*****"
        });
        foreach (var item in user)
        {
            var UserResult = await _UserManager.IsInRoleAsync(item, "Administrators");
            if (!UserResult)
            {
                ColUsers.Add(item);
            }
        }
    }
    void AddNewProject()
    {
        //System.Diagnostics.Debug.WriteLine("read value =" + ReadMorePopup);
        // Make new Project
        objProject = new Project();
        // Set Id to 0 so we know it is a new record
        objProject.Id = 0;
        // Open the Popup
        ShowPopup = true;
    }
    async Task SaveProject()
    {

        // Close the Popup
        ShowPopup = false;
        // Get the current user
        var user = (await authenticationStateTask).User;
        // A new Proejct will have the Id set to 0
        if (objProject.Id == 0)
        {
            // Create new Project
            Project objNewProject = new Project();
            objNewProject.Title = objProject.Title;
            objNewProject.Details = objProject.Details;
            objNewProject.MaxStudents = objProject.MaxStudents;
            objNewProject.IsActive = objProject.IsActive;
            objNewProject.isLock = false;

            //objNewProject.TemperatureF =
            //Convert.ToInt32(objProject.TemperatureF);
            objNewProject.OwnerId = user.Identity.Name;
            // Save the result
            var result =
            @Service.CreateProjectAsync(objNewProject);
        }
        else
        {

            // This is an update
            var result =
            @Service.UpdateProjectAsync(objProject);
        }
        // Get the Projects for the current user
        projects =
        await @Service.GetProjectAsync();
    }

    void EditProject(Project project)
    {
        System.Diagnostics.Debug.WriteLine("read value =" + ReadMorePopup);
        // Set the selected project
        // as the current project
        objProject = project;
        // Open the Popup
        ShowPopup = true;
    }


    void ReadProject(Project project)
    {
        System.Diagnostics.Debug.WriteLine("In Readmorepopup ");
        // Set the selected project
        // as the current project
        objProject = project;
        // Open the Popup
        ReadMorePopup = true;
        System.Diagnostics.Debug.WriteLine(ReadMorePopup);
    }

    void LockProject(Project project)
    {
        lockPop = true;

        objProject = project;

    }



    async Task ConfirmLockProject()
    {
        var user = (await authenticationStateTask).User;
        //var currentUser = await UserManager.GetUserAsync(user);


        objProject.UserLockID = user.Identity.Name;
        objProject.isLock = true;

        var result =
            @Service.UpdateProjectAsync(objProject);
        lockPop = false;
    }


    void NavigateToProject(int projectId)
    {
        NavigationManager.NavigateTo(uri: ("/ProjectDetails/" + projectId));

    }


    void AddUserToProject(Project project)
    {
        lockPop = true;

        objProject = project;
    }


    async Task AddUserToProject()
    {


        var userToADD = await _UserManager.FindByNameAsync(userToAddToProject);
        if (userToADD != null)
        {

        }



        //var user = (await authenticationStateTask).User;
        //var currentUser = await UserManager.GetUserAsync(user);


        //objProject.UserLockID = user.Identity.Name;
        //objProject.isLock = true;

        var result =
            @Service.UpdateProjectAsync(objProject);
        lockPop = false;
    }



    async Task ReleaseProject()
    {



        objProject.UserLockID = "";
        objProject.isLock = false;
        System.Diagnostics.Debug.WriteLine("In Realese Project isLock value =" + objProject.isLock);
        var result =
            @Service.UpdateProjectAsync(objProject);
        lockPop = false;
    }


#line default
#line hidden
#nullable disable
        [global::Microsoft.AspNetCore.Components.InjectAttribute] private AuthenticationStateProvider AuthenticationStateProvider { get; set; }
        [global::Microsoft.AspNetCore.Components.InjectAttribute] private UserManager<ApplicationUser> _UserManager { get; set; }
        [global::Microsoft.AspNetCore.Components.InjectAttribute] private NavigationManager NavigationManager { get; set; }
    }
}
#pragma warning restore 1591
