<%@ page extends="oneit.servlets.jsp.JSPInclude" %>
<%@ include file="/inc/stdimports50.jsp" %><%-- This is in cougar --%>
<%@ include file="/inc/stdcms.jsp" %><%-- This is in cougar --%>

<%@ include file="/extensions/performa/inc/stdimports.jsp" %>

<oneit:dynIncluded>
<%
//    String              nextPage        =   WebUtils.getSamePageInRenderMode(request, WebUtils.EDIT_CLIENT);
    String          usersPage       =   WebUtils.getSamePageInRenderMode(request, "Page");
    UserSortOption  userSortOpt     =   (UserSortOption) process.getAttribute("UserSortOption");
    CompanyUser[]   companyUsers    =   (CompanyUser[]) process.getAttribute("CompanyUsers");
    
    if( request.getParameter("UserSortOption") != null)
    {
        userSortOpt =   UserSortOption.forName((String) request.getParameter("UserSortOption"));
    }
    
    if(userSortOpt == null)
    {
        userSortOpt   =   UserSortOption.ALPHA_A_Z;
    }
    
    if(companyUsers == null)
    {
        companyUsers    =   CompanyUser.SearchByAllCompanyUsers()
                                        .byReferenceExtension(CompanyUser.REFERENCE_CompanyUser)
                                        .search(transaction);
        
        process.setAttribute("CompanyUsers", companyUsers);
    }
    
    List<CompanyUser>   sortedUsers =   Utils.getUsersSorted(companyUsers, userSortOpt);
    
    process.setAttribute("UserSortOption", userSortOpt);
%>
    <oneit:form name="listUsers" method="post"    enctype="multipart/form-data">

        <div class="dashboard-content-area second-part">
                        
            <oneit:dynInclude   page="/extensions/applicantportal/inc/multifieldtext.jsp"   data="<%= CollectionUtils.EMPTY_MAP%>"/>

            <div class="eq-justify-content">
                <div class="manage-user-left">
                    <div class="jobs-list-shorting">
                        <div class="d-job-title all-jobs-title">Manage Users</div>
                        <div class="shorting-dropdown">
                            <span class="order-label">order by</span>
                            <select class="form-control"    onChange="location=this.value">
                            <%
                                for (UserSortOption  sortOption : UserSortOption.getUserSortOptionArray())
                                {
                                    String  optionLink  =    usersPage + "&UserSortOption=" + sortOption.getName() ;
                            %>
                                    <option <%= (userSortOpt != null && userSortOpt == sortOption ? "selected" : "" )%>  value="<%= optionLink %>">
                                        <oneit:toString value="<%= sortOption.getDescription() %>"   mode="EscapeHTML"/>
                                    </option>
                            <%
                                }
                            %>
                            </select>
                        </div>
                    </div>
                    <div class="main-manage-userlist">
                    <%
                        for(CompanyUser companyUser : companyUsers)
                        {
                            SecUser user    =   companyUser.getUser();
                    %>
                            <div class="user-list-row">
                                <div class="m-user-left">
                                    <div class="m-user-icon"><img src="images/user-list-icon.png"></div>
                                    <div class="m-user-info">
                                        <div class="m-user-name">
                                            <oneit:toString value="<%= user.getName() %>"   mode="EscapeHTML" />
                                        </div>
                                        <div class="m-user-email">
                                            <oneit:toString value="<%= user.getEmail() %>"  mode="EscapeHTML" />
                                        </div>
                                    </div>
                                </div>
                                <div class="m-user-right">
                                    <select class="form-control">
                                        <option>Admin</option>
                                        <option>Standard</option>
                                    </select>
                                </div>
                            </div>
                    <%
                        }
                    %>
                        <div class="user-list-row">
                            <div class="m-save-user">
                                <input type="text" placeholder="First Name" class="form-control" />
                                <input type="text" placeholder="Surname" class="form-control" />
                                <input type="text" placeholder="Email" class="form-control" />
                            </div>
                            <div class="save-button">
                                <input type="button" class="btn btn-save" value="save">
                            </div>
                        </div>
                        <div class="user-list-row">
                            <div class="m-user-left">
                                <div class="m-user-icon"><img src="images/user-list-icon.png"></div>
                                <div class="m-user-info">
                                    <div class="m-user-name">Janis Stein</div>
                                    <div class="m-user-email">janisstein@gmail.com</div>
                                </div>
                            </div>
                            <div class="m-user-right invite-combo">
                                <select class="form-control" disabled="">
                                    <option>Invitation sent</option>
                                </select>
                            </div>
                            <div class="resend-link"><a href="#">Re-send invitation to Janis</a></div>
                        </div>
                    </div>
                </div>
                <div class="manage-user-right">
                    <div class="sidebar-title">
                        Invite a user
                    </div>
                    <div class="form-group">
                        <label>Email address</label>
                        <input type="text" name="" class="form-control" />    
                    </div>
                    <div class="form-group">
                        <label>First name</label>
                        <input type="text" name="" class="form-control" />
                    </div>
                    <div class="form-group">
                        <label>Last name</label>
                        <input type="text" name="" class="form-control" />
                    </div>
                    <div class="form-group">
                        <label>Role</label>
                        <select class="form-control">
                            <option>Admin</option>
                            <option>Standard</option>
                        </select>
                    </div>
                    <div class="invite-btn">
                        <input type="button" name="" class="btn btn-invite" value="Invite" />
                    </div>
                </div>
            </div>
        </div>
    </oneit:form>
</oneit:dynIncluded>
