@using OurUmbraco.Project.Services
@inherits Umbraco.Web.Macros.PartialViewMacroPage

@{
    
    var projectId = Request["Id"];
    int id = 0;
}

@if (!string.IsNullOrEmpty(projectId) && int.TryParse(projectId, out id))
{
    var project = Umbraco.TypedContent(projectId);

    var openForCollab = project.GetPropertyValue<bool>("openForCollab");


    var cs = new ContributionService(ApplicationContext.Current.DatabaseContext);

    var contris = cs.GetContributors(id).ToList();
    <style>
        .profile-settings { margin-bottom: 50px; }
        #add-contri { margin-top: 20px; }
    </style>
    <div class="profile-settings">
        <strong>@project.Name</strong>
        <div class="profile-settings-forms">

            <div class="profile-input">
                <label for="open-for-collab">Is open for collaboration</label>
                @if (openForCollab)
                {
                    <input checked="checked" id="open-for-collab" name="open-for-collab" type="checkbox" data-id="@projectId">
                }
                else
                {
                    <input id="open-for-collab" name="open-for-collab" type="checkbox" data-id="@projectId">
                }
            </div>

        </div>


        <strong>Current contributors</strong>
        <div class="profile-settings-forms">
            <ul id="contris">
                @foreach (var contri in contris)
                {
                    var member = Members.GetById(contri.MemberId);
                    if (member != null)
                    {
                        <li>
                            <a class="contri-name" href="/member/@member.Id">@member.Name</a> <a data-projectid="@contri.ProjectId" data-memberid="@member.Id" class="remove-contri" href="#"><i class="icon-Delete-key"></i><span>Remove</span></a>
                        </li>
                    }
                }
            </ul>
        </div>

        <strong>Add contributor</strong>
        <div class="profile-settings-forms">

            <div class="profile-input">
                <label for="contri-email">Email</label>
                <input type="text" id="contri-email" name="contri-email"/>
            </div>
            <span id="contri-feedback"></span><br/>
            <a class="button green tiny" id="add-contri" data-id="@projectId">Add</a>
            
        </div>
    </div>
}