<%
  var inputName = "" ;
  var inputEmail = "";
  var inputRecipeName = "";
  var inputDescription= "";
  if(typeof(keepReqFormData) != "undefined")
  {
    inputName = keepReqFormData.rName;
    inputEmail = keepReqFormData.rEmail;
    inputRecipeName= keepReqFormData.rRecipeName;
    inputDescription = keepReqFormData.rDescription;
  };
%>
<!DOCTYPE html>
<html lang="en">
    <head>
        <%- include("partials/meta.ejs")  %> 
        <title>RecipEasy : Submit Recipe</title>
    </head>
    <body>
        <div class="container">
            <%- include('partials/header-nav.ejs') %> 
            <main>
                <section class="request_page">
                    <% if (typeof(rRecipeName) != "undefined") { %> 
                        <h1> Thank you</h1>
                        <p>Your recipe has been successfully submitted!</p>
                    <% }else{ %>
                    <form action="/add-recipe" method="post" enctype="multipart/form-data">
                        <h2>Submit Recipe</h2>
                        <div class="labelwrapper">
                            <div class="fieldwrapper">
                                <label for="rRecipeName">Recipe Name*: </label>
                                <div>
                                    <input type="text" id="rRecipeName" name="rRecipeName" value="<%=inputRecipeName%>">
                                    <% if (typeof(rErrorsMap) != "undefined" && typeof(rErrorsMap.rRecipeName) != "undefined"){%> 
                                        <p> <%= rErrorsMap.rRecipeName.msg %> </p> 
                                    <% }%> 
                                </div>
                            </div>
                            <div class="fieldwrapper ">
                                <label for="rPhoto">Photo: </label>
                                <input type="file" id="rPhoto" name="rPhoto">
                            </div>
                            <div class="fieldwrapper">
                                <label for="rDescription">Description*: </label>
                                <div>
                                    <input type="text" id="rDescription" name="rDescription" value="<%=inputDescription%>">
                                    <% if (typeof(rErrorsMap) != "undefined" && typeof(rErrorsMap.rDescription) != "undefined"){%> 
                                        <p> <%= rErrorsMap.rDescription.msg %> </p> 
                                    <% }%> 
                                </div>
                            </div>
                        </div>
                        <div class="submission">
                            <input type="submit" value="Submit">
                            <input type="reset" value="Clear">
                        </div>
                    </form>
                    <% } %> 
                </section>
            </main>
            <%- include("partials/footer.ejs")  %> 
        </div>

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
        <script src="/js/tinymce/tinymce.min.js"></script>
        <script>
          tinymce.init({
            selector: '#rDescription'
          })
        </script>
    </body>
</html>