<h1>Edit Career Page</h1>

<form action="/career/edit_data/<%= story._id %>" method="POST" enctype="multipart/form-data">

    <!-- Main Section -->
    <h3>Main Section</h3>
    <div class="mb-3">
        <label class="form-label">Main Title</label>
        <input type="text" class="form-control" name="title" value="<%= story.title %>" required>
    </div>
    <div class="mb-3">
        <label class="form-label">Main Content</label>
        <textarea class="form-control" name="content" rows="5" required><%= story.content %></textarea>
    </div> 
    <div class="mb-3">
        <label class="form-label">Hero Image</label>
        <input type="file" class="form-control" name="heroImage">
        <% if(story.heroImage) { %>
            <p class="mt-2 text-muted"> <img style="width: 100px; height: 100px;" src="<%= story.heroImage %>" target="_blank"></a></p>
        <% } %>
    </div>

    <hr>

<!-- stand for -->
     <h6>Career Growth</h6>
    <div class="mb-3">
        <textarea class="form-control" name="content1" rows="3" placeholder="stand for content ...."><%= story.content1 %></textarea>
    </div>
    
         <h6>Work Culture</h6>
    <div class="mb-3">
        <textarea class="form-control" name="content2" rows="3" placeholder="Intention content ...."><%= story.content2 %></textarea>
    </div>   

         <h6>Learning & Development</h6>
    <div class="mb-3">
        <textarea class="form-control" name="content3" rows="3" placeholder="Intention content ...."><%= story.content3 %></textarea>
    </div>   

    <hr>
     
    <!-- Journey Sections -->
    <h3 class="mt-4">Life at UB</h3>
    <div id="journeySectionsContainer">
        <% if (story.Side_Sections && story.Side_Sections.length > 0) { %>
            <% story.Side_Sections.forEach((section, index) => { %>
                <div class="card p-3 mb-3 border border-warning">
                    <div class="d-flex justify-content-between">
                        <h5>Life Section</h5>
                        <button type="button" class="btn btn-sm btn-danger" onclick="this.parentElement.parentElement.remove()">Remove</button>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Title</label>
                        <input type="text" class="form-control" name="journeyTitles[]" value="<%= section.title %>" required>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Content</label>
                        <textarea class="form-control" name="journeyContents[]" rows="3"><%= section.content %></textarea>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Image</label>
                        <input type="file" class="form-control" name="journeyImage_<%= index %>">
                        <% if (section.image) { %>
                            <small class="text-muted">Current image: <a href="<%= section.image %>" target="_blank">View</a></small>
                        <% } %>
                    </div>
                </div>
            <% }) %>
        <% } %>
    </div>
    
    <button type="button" id="addJourneyBtn" class="btn btn-warning mt-2">
        <i class="fas fa-plus"></i> Add Life Section +
    </button>

    <h3 class="mt-4">Job Openings Sections</h3>
    <div id="dynamicSectionsContainer">
        <% if (story.dynamicSections && story.dynamicSections.length > 0) { %>
            <% story.dynamicSections.forEach((section, index) => { %>
                <div class="card p-3 mb-3 border border-info">
                    <div class="d-flex justify-content-between">
                        <h5>Job Section</h5>
                        <button type="button" class="btn btn-sm btn-danger" onclick="this.parentElement.parentElement.remove()">Remove</button>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Job Name</label>
                        <input type="text" class="form-control" name="dynamicNames[]" value="<%= section.name %>" required>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Job type</label>
                        <input type="text" class="form-control" name="dynamicPosts[]" value="<%= section.post %>">
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Experience</label>
                        <input type="text" class="form-control" name="dynamicExperience[]" value="<%= section.experience %>">
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Content</label>
                        <textarea class="form-control" name="dynamicContents[]" rows="3"><%= section.content %></textarea>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Image</label>
                        <input type="file" class="form-control" name="dynamicImage_<%= index %>">
                        <% if (section.image) { %>
                            <small class="text-muted">Current image: <a href="<%= section.image %>" target="_blank">View</a></small>
                        <% } %>
                    </div>
                </div>
            <% }) %>
        <% } %>
    </div>
    
    <button type="button" id="addSectionBtn" class="btn btn-info mt-2">
        <i class="fas fa-plus"></i> Add Job +
    </button>

    <hr>

    <!-- What we are looking for -->
    <p>What we are looking for Section</p>
      <div class="mb-3">
        <label class="form-label">Title</label>
        <input type="text" class="form-control" name="title1" placeholder="left title ...." value="<%= story.title1 %>">
    </div>
    <div class="mb-3">
        <textarea class="form-control" name="content4" rows="3" placeholder="left content ...."><%= story.content4 %></textarea>
    </div>

     <h6>Ownership</h6>
    <div class="mb-3">
         <textarea class="form-control" name="content5" rows="3"><%= story.content5 %></textarea>
    </div> 

    <h6>Integrity</h6>
    <div class="mb-3">
         <textarea class="form-control" name="content6" rows="3"><%= story.content6 %></textarea>
    </div> 

    <h6>Creativity</h6>
    <div class="mb-3">
         <textarea class="form-control" name="content7" rows="3"><%= story.content7 %></textarea>
    </div> 

    <h6>Execution</h6>

    <div class="mb-3">
         <textarea class="form-control" name="content8" rows="3"><%= story.content8 %></textarea>
    </div> 

     <h6>Collaboration</h6>

    <div class="mb-3">
         <textarea class="form-control" name="content9" rows="3"><%= story.content9 %></textarea>
    </div>

    <hr>

    <div class="mt-4 mb-5">
        <button type="submit" class="btn btn-primary">
            Update Career
        </button>
    </div>
</form>

<script>
    let sectionCount = <%= story.dynamicSections ? story.dynamicSections.length : 0 %>;
    document.getElementById('addSectionBtn').addEventListener('click', function() {
        const container = document.getElementById('dynamicSectionsContainer');
        const sectionHtml = `
            <div class="card p-3 mb-3 border border-info">
                <div class="d-flex justify-content-between">
                    <h5>New Extra Section</h5>
                    <button type="button" class="btn btn-sm btn-danger" onclick="this.parentElement.parentElement.remove()">Remove</button>
                </div>
                <div class="mb-3">
                    <label class="form-label">Job Name</label>
                    <input type="text" class="form-control" name="dynamicNames[]" placeholder='civil engineer,site engineer..' required>
                </div>
                <div class="mb-3">
                    <label class="form-label">Job type</label>
                    <input type="text" class="form-control" name="dynamicPosts[]" placeholder='sales,executive....'>
                </div>
                <div class="mb-3">
                    <label class="form-label">Experience</label>
                    <input type="text" class="form-control" name="dynamicExperience[]"  placeholder="1 to 3 years...">
                </div>
                <div class="mb-3">
                    <label class="form-label">Content</label>
                    <textarea class="form-control" name="dynamicContents[]" rows="3"></textarea>
                </div>
                <div class="mb-3">
                    <label class="form-label">Image</label>
                    <input type="file" class="form-control" name="dynamicImage_${sectionCount}" required>
                </div>
            </div>
        `;
        container.insertAdjacentHTML('beforeend', sectionHtml);
        sectionCount++;
    });

    let journeyCount = <%= story.Side_Sections ? story.Side_Sections.length : 0 %>;
    document.getElementById('addJourneyBtn').addEventListener('click', function() {
        const container = document.getElementById('journeySectionsContainer');
        const sectionHtml = `
            <div class="card p-3 mb-3 border border-warning">
                <div class="d-flex justify-content-between">
                    <h5>New Journey</h5>
                    <button type="button" class="btn btn-sm btn-danger" onclick="this.parentElement.parentElement.remove()">Remove</button>
                </div>
                <div class="mb-3">
                    <label class="form-label">Title</label>
                    <input type="text" class="form-control" name="journeyTitles[]" required>
                </div>
                <div class="mb-3">
                    <label class="form-label">Content</label>
                    <textarea class="form-control" name="journeyContents[]" rows="3"></textarea>
                </div>
                <div class="mb-3">
                    <label class="form-label">Image</label>
                    <input type="file" class="form-control" name="journeyImage_${journeyCount}" required>
                </div>
            </div>
        `;
        container.insertAdjacentHTML('beforeend', sectionHtml);
        journeyCount++;
    });
</script>