<%--
 ~
 ~ Copyright (c) 2021, WSO2 Inc. (http://www.wso2.com). All Rights Reserved.
 ~
 ~ This software is the property of WSO2 Inc. and its suppliers, if any.
 ~ Dissemination of any information or reproduction of any material contained
 ~ herein in any form is strictly forbidden, unless permitted by WSO2 expressly.
 ~ You may not alter or remove any copyright or other notice from copies of this content."
 ~
--%>

<%@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">
                    <div class="ui header text-center">
                        <h3>
                            <b>Complete your profile</b>
                        </h3>
                    </div>
                    <div class="ui text-center login-portal-app-des2-font">
                        <p>
                            <strong style="color: #ff8e32;" class="text-capitalize"><%=Encode.forHtmlContent(appName)%></strong> 
                            needs the following details that are missing in your profile.
                        </p>
                    </div>
                    <form class="ui large form" action="<%=commonauthURL%>" method="post" id="claimForm">
                        <div class="segment-form mt-4">
                            <%-- <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);
                                        if (claim.contains("claims/dob")) {
                                            claimDisplayName="Date of Birth (yyyy-mm-dd)";
                                        }
                                    %>
                                    <div class="mt-2">
                                        <%-- <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="mt-5">
                                <button class="ui primary fluid large button"
                                        type="submit">
                                    <%=AuthenticationEndpointUtil.i18n(resourceBundle, "continue")%>
                                </button>

                        </div>
                        </div>
                    </form>
                </div>
            </div>
        </main>
         <!-- 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"/>
        <% } %>
    </div>
    <!-- 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>
