<!doctype html>
<html lang="ko">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <%- include('partials/favicon') %>
    <title>콘텐츠 수정 - NCue</title>
    <link rel="stylesheet" href="/public/styles.css" />
  </head>
  <body>
    <% var adminBasePath = typeof adminBasePath !== 'undefined' ? adminBasePath : '/admin'; %>
    <% var navMenu = typeof navActiveMenu !== 'undefined' ? navActiveMenu : 'learning'; %>
    <div class="app-shell">
      <%- include('partials/nav', { activeMenu: navMenu }) %>
      <div class="content-area">
        <header class="topbar">
          <h1>콘텐츠 수정</h1>
          <a class="top-action-link" href="<%= adminBasePath %>?<%= returnQuery %>">목록으로</a>
        </header>
        <main class="container">
          <section class="panel">
            <h2><% if (lecture.type === 'youtube') { %>유튜브<% } else if (lecture.type === 'news') { %>뉴스 URL<% } else if (lecture.type === 'link') { %>웹 링크<% } else if (lecture.type === 'video') { %>동영상 파일<% } else { %>PDF/PPT<% } %> 수정</h2>
            <form action="/lectures/<%= lecture.id %>/update" method="post" class="form-grid">
              <input type="hidden" name="token" value="<%= tokenRaw %>" />
              <input type="hidden" name="returnTo" value="<%= adminBasePath %>?<%= returnQuery %>" />
              <label>제목 <input type="text" name="title" value="<%= lecture.title %>" required /></label>
              <% if (lecture.type === 'youtube') { %>
              <label>유튜브 링크 <input type="url" name="youtubeUrl" value="<%= lecture.youtubeUrl || '' %>" placeholder="https://www.youtube.com/watch?v=..." required /></label>
              <% } else if (lecture.type === 'news') { %>
              <label>뉴스 URL <input type="url" name="newsUrl" value="<%= lecture.newsUrl || '' %>" placeholder="https://..." required /></label>
              <% } else if (lecture.type === 'link') { %>
              <label>웹 링크 URL <input type="url" name="newsUrl" value="<%= lecture.newsUrl || '' %>" placeholder="https://..." required /></label>
              <% } else if (lecture.type === 'video') { %>
              <label class="full">동영상 파일 <span class="muted">(변경 불가)</span> <input type="text" value="<%= lecture.originalName || lecture.fileName || '' %>" disabled /></label>
              <% } else { %>
              <label class="full">PDF/PPT 파일 <span class="muted">(변경 불가)</span> <input type="text" value="<%= lecture.originalName || lecture.fileName || '' %>" disabled /></label>
              <% } %>
              <label class="full">설명 <textarea name="description" rows="3"><%= lecture.description || '' %></textarea></label>
              <label class="full">카테고리
                <div class="category-radios-inline">
                  <% 
                    const cats = ['AX 사고 전환','AI 툴 활용','AI Agent','바이브 코딩'];
                    const lectureTags = lecture.tags || [];
                    const cat = cats.find(function(c){ return lectureTags.indexOf(c) >= 0; });
                    const otherTags = lectureTags.filter(function(t){ return cats.indexOf(t) < 0; });
                  %>
                  <label><input type="radio" name="category" value="" <%= !cat ? 'checked' : '' %> />선택 안함</label>
                  <label><input type="radio" name="category" value="AX 사고 전환" <%= cat === 'AX 사고 전환' ? 'checked' : '' %> />AX 사고 전환</label>
                  <label><input type="radio" name="category" value="AI 툴 활용" <%= cat === 'AI 툴 활용' ? 'checked' : '' %> />AI 툴 활용</label>
                  <label><input type="radio" name="category" value="AI Agent" <%= cat === 'AI Agent' ? 'checked' : '' %> />AI Agent</label>
                  <label><input type="radio" name="category" value="바이브 코딩" <%= cat === '바이브 코딩' ? 'checked' : '' %> />바이브 코딩</label>
                </div>
              </label>
              <label class="full">태그 (쉼표 구분) <input type="text" name="tags" value="<%= otherTags.join(', ') %>" placeholder="예: AI에이전트, 바이브코딩" /></label>
              <div class="form-actions">
                <button type="submit">저장</button>
                <a href="<%= adminBasePath %>?<%= returnQuery %>" class="link-muted">취소</a>
              </div>
            </form>
          </section>
        </main>
      </div>
    </div>
  </body>
</html>
