<%--
  ~ Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
  ~
  ~ WSO2 Inc. licenses this file to you under the Apache License,
  ~ Version 2.0 (the "License"); you may not use this file except
  ~ in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~ http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing,
  ~ software distributed under the License is distributed on an
  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  ~ KIND, either express or implied.  See the License for the
  ~ specific language governing permissions and limitations
  ~ under the License.
  --%>

<%@page import="org.wso2.carbon.identity.application.authentication.endpoint.util.Constants" %>
<%@ page import="org.owasp.encoder.Encode" %>
<%@ page import="java.io.File" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<%@include file="includes/localize.jsp" %>
<%@include file="includes/init-url.jsp" %>

<%
    String[] missingClaimList = null;
    String appName = null;
    Boolean isFederated = false;
    if (request.getParameter(Constants.MISSING_CLAIMS) != null) {
        missingClaimList = request.getParameter(Constants.MISSING_CLAIMS).split(",");
    }
    if (request.getParameter(Constants.REQUEST_PARAM_SP) != null) {
        appName = request.getParameter(Constants.REQUEST_PARAM_SP);
    }

%>

<!doctype html>
<html>
<head>
    <!-- header -->
    <%
        File headerFile = new File(getServletContext().getRealPath("extensions/header.jsp"));
        if (headerFile.exists()) {
    %>
        <jsp:include page="extensions/header.jsp"/>
    <% } else { %>
        <jsp:include page="includes/header.jsp"/>
    <% } %>
</head>
<body class="login-portal layout authentication-portal-layout">
   <div class="page-wrapper">
        <main class="center-segment">
            <div class="ui container medium center aligned middle aligned">

                <!-- product-title -->
                <%
                    File productTitleFile = new File(getServletContext().getRealPath("extensions/product-title.jsp"));
                    if (productTitleFile.exists()) {
                %>
                    <jsp:include page="extensions/product-title.jsp"/>
                <% } else { %>
                    <jsp:include page="includes/product-title.jsp"/>
                <% } %>

                <div class="ui segment">
                    <h3 class="ui header" style="text-align: left;">
                        Provide Missing Details
                    </h3>

                    <form class="ui large form" action="<%=commonauthURL%>" method="post" id="claimForm">
                        <p style="text-align: left;">
                            Your profile is missing the following information that is requested by
                            the <strong><%=Encode.forHtmlContent(appName)%></strong> application.
                        </p>

                        <div class="field">
                        <div style="text-align: left; margin-bottom: -10px;">
                            Fill in your details:
                        </div>
                        </div>
                        <div class="segment-form">
                            <%-- <div class="ui secondary segment"> --%>
                                <div>
                                    <% for (String claim : missingClaimList) { 
                                        String claimDisplayName = claim;
                                        claimDisplayName = claimDisplayName.replaceAll(".*/", "");
                                        claimDisplayName = claimDisplayName.substring(0, 1).toUpperCase() + claimDisplayName.substring(1);
                                    %>
                                    <div class="field">
                                        <%-- <label><%=Encode.forHtmlContent(claimDisplayName)%></label> --%>
                                        <input type="text" name="claim_mand_<%=Encode.forHtmlAttribute(claim)%>"
                                            id="claim_mand_<%=Encode.forHtmlAttribute(claim)%>"  required="required" placeholder="<%=Encode.forHtmlContent(claimDisplayName)%>">
                                    </div>
                                    <% } %>
                                    <input type="hidden" name="sessionDataKey" value='<%=Encode.forHtmlAttribute
                                        (request.getParameter("sessionDataKey"))%>'/>
                                </div>
                            <%-- </div> --%>

                            <div class="ui info message mini">
                                <span> <strong>Note:</strong> If you are logging in via an external/social account, update your details in that particular account profile to avoid being asked again</span>
                            </div>
                        
                            <div class="align-right buttons">
                                <button class="ui primary large button"
                                        type="submit">
                                    <%=AuthenticationEndpointUtil.i18n(resourceBundle, "continue")%>
                                </button>
                        </div>
                        </div>
                    </form>
                </div>
            </div>
        </main>
    </div>

    <!-- product-footer -->
    <%
        File productFooterFile = new File(getServletContext().getRealPath("extensions/product-footer.jsp"));
        if (productFooterFile.exists()) {
    %>
        <jsp:include page="extensions/product-footer.jsp"/>
    <% } else { %>
        <jsp:include page="includes/product-footer.jsp"/>
    <% } %>

    <!-- footer -->
    <%
        File footerFile = new File(getServletContext().getRealPath("extensions/footer.jsp"));
        if (footerFile.exists()) {
    %>
        <jsp:include page="extensions/footer.jsp"/>
    <% } else { %>
        <jsp:include page="includes/footer.jsp"/>
    <% } %>

  <script>

  function getDiplayName(claimURI) {

    var claim = claimURI.split("/").pop();
    return claim.charAt(0).toUpperCase() + claim.slice(1);
  }

  </script>
</body>
</html>
