<!DOCTYPE html>
<html lang="en">
    <head>
        <%- include("partials/meta.ejs")  %> 
        <title>Syed's Gift Shop: Edit Request</title>
    </head>
    <body>
        <%- include('partials/header-nav.ejs') %> 
        <main>
            <section class="request_page">
                <% if (typeof(request) != "undefined") { %> 
                    <h1> Thank you</h1>
                    <p>Request has been successfully edited!</p>
                <% }else{ %>
                <form action="/process-edit/<%= _id %>" method="post" enctype="multipart/form-data">
                    <h2>Edit Request</h2>
                    <div class="labelwrapper">
                        <div class="fieldwrapper">
                            <label for="rName">Name*: </label>
                            <input type="text" id="rName" name="rName" value="<%=rName%>">
                        </div>
                        <div class="fieldwrapper">
                            <label for="rEmail">Email*: </label>
                            <input type="email" id="rEmail" name="rEmail" value="<%=rEmail%>">
                        </div>
                        <% if (rPhotoName != ""){ %>
                            <div class="fieldwrapper-photo">
                                <label for="rPhoto">New Photo: </label>
                                <input type="file" id="rPhoto" name="rPhoto">
                                <img src="/uploads/<%= rPhotoName %>" alt="request photo">
                                <input type="text" id="rOldPhotoName" name="rOldPhotoName" readonly value="<%=rPhotoName%>">
                            </div>
                        <% }else{%>
                            <div class="fieldwrapper">
                                <label for="rPhoto">Photo: </label>
                                <input type="file" id="rPhoto" name="rPhoto" value="<%= rPhotoName %> ">
                            </div>
                        <% } %>   
                        <div class="fieldwrapper">
                            <label for="rSubject">Subject*: </label>
                            <input type="text" id="rSubject" name="rSubject" value="<%=rSubject%>">
                        </div>
                        <div class="fieldwrapper">
                            <label for="rDescription">Description*: </label>
                            <input type="text" id="rDescription" name="rDescription" value="<%=rDescription%>">
                        </div>
                    </div>
                    <div class="submission">
                        <input type="submit" value="Edit Request">
                    </div>
                </form>
                <% } %> 
            </section>
        </main>
        <%- include("partials/footer.ejs")  %> 
        <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>