File size: 6,113 Bytes
8f0fa74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<!DOCTYPE html>
<html lang="ko">
<head>
  <meta charset="UTF-8" />
  <title>AZ-104 CBT โ€ข ์˜ค๋‹ต & ๋ณต์Šต ๋…ธํŠธ</title>
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <style>
    :root {
      --brand: #0a6bdf;
      --brand-dark: #0850a7;
      --warn: #ffcc00;
      --bg: #f5f7fa;
      --ok: #178a00;
      --bad: #d12929;
      --card: #fff;
      --muted: #6b7280;
    }
    body {
      margin: 0;
      background: var(--bg);
      font-family: system-ui, -apple-system, Segoe UI, Roboto, Apple SD Gothic Neo, Noto Sans KR, Arial, sans-serif;
      padding: 24px;
      display: flex;
      justify-content: center;
    }
    .wrap { width: 100%; max-width: 900px; }
    .topbar {
      display: flex; align-items: center; justify-content: space-between;
      margin-bottom: 16px; gap: 12px; flex-wrap: wrap;
    }
    .progress { color: var(--muted); font-size: 14px; }
    .pill {
      font-size: 12px; padding: 6px 10px; border-radius: 999px;
      background: #f3f4f6; color: #374151;
    }
    .card {
      background: var(--card); border-radius: 14px; padding: 22px;
      box-shadow: 0 8px 24px rgba(0,0,0,.08);
      min-height: 260px;
    }
    .qid { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
    .qtext { font-size: 18px; line-height: 1.5; margin: 0 0 14px; }
    .options { display: grid; gap: 10px; margin-top: 14px; }
    .opt {
      display: flex; align-items: center; gap: 10px; padding: 12px 14px;
      border: 1px solid #e5e7eb; border-radius: 10px; background: #fff;
    }
    .opt.correct { border-color: #b8e3c1; background: #effaf2; }
    .opt.wrong { border-color: #f1b7b7; background: #fff1f1; }
    .opt.chosen { border: 2px solid var(--warn); }
    .exp {
      display: none; margin-top: 14px; padding: 12px 14px; border-left: 5px solid var(--brand);
      background: #eef6ff; border-radius: 8px;
    }
    .exp.show { display: block; }
    .nav {
      margin-top: 18px; display: flex; align-items: center; gap: 14px;
      background: #fff; border-radius: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.08);
      padding: 16px 18px;
    }
    .spacer { flex: 1; }
    button.btn {
      border: 0; padding: 10px 18px; border-radius: 10px; color: #fff; background: var(--brand);
      cursor: pointer; font-weight: 600; transition: background .15s;
    }
    button.btn:hover { background: var(--brand-dark); }
    button.outline { background: #fff; color: #111827; border: 1px solid #e5e7eb; }
    button.delete { background: var(--bad); }
    .loading { text-align: center; padding: 40px; color: var(--muted); }
  </style>
</head>

<body>
<div class="wrap">
  <div class="topbar">
    <div class="pill">CBT โ€ข ์˜ค๋‹ต & ๋ณต์Šต ๋…ธํŠธ</div>
    <div class="progress" id="progress">0 / 0</div>
  </div>

  <div class="card">
    <div id="loading" class="loading">๋ถˆ๋Ÿฌ์˜ค๋Š” ์ค‘...</div>
    <div id="qContainer" style="display:none;">
      <div class="qid" id="qid"></div>
      <h2 class="qtext" id="qtext"></h2>
      <div class="options" id="options"></div>
      <div class="exp" id="exp"></div>
    </div>
  </div>

  <div class="nav">
    <button class="btn outline" id="homeBtn">๐Ÿ  ํ™ˆ</button>
    <button class="btn outline" id="prevBtn">โ† ์ด์ „</button>
    <button class="btn outline" id="nextBtn">๋‹ค์Œ โ†’</button>
    <div class="spacer"></div>
    <button class="btn" id="showExpBtn">์ •๋‹ต ๋ณด๊ธฐ</button>
    <button class="btn delete" id="deleteBtn">๐Ÿ—‘๏ธ ์ œ๊ฑฐ</button>
  </div>
</div>

<script>
  let list = [];
  let currentIndex = 0;

  async function load() {
    const res = await fetch("/api/wrong_review"); // โœ… ํ†ตํ•ฉ API ์‚ฌ์šฉ
    const data = await res.json();
    list = data.items || [];

    if (list.length === 0) {
      document.getElementById("loading").textContent = "โœ… ์˜ค๋‹ต / ๋ณต์Šต ๋ชฉ๋ก์ด ์—†์Šต๋‹ˆ๋‹ค!";
      return;
    }
    show();
  }

  function show() {
    const q = list[currentIndex];

    document.getElementById("progress").textContent = `${currentIndex+1} / ${list.length}`;
    document.getElementById("qid").textContent = `๋ฌธ์ œ ID ${q.question_id}`;
    document.getElementById("qtext").textContent = q.stem;

    const optsEl = document.getElementById("options");
    optsEl.innerHTML = "";
    for (const [k, v] of Object.entries(q.options)) {
      const d = document.createElement("div");
      d.className = "opt";
      if (k === q.answer) d.classList.add("correct");
      if (q.chosen && k === q.chosen && k !== q.answer) d.classList.add("wrong");
      if (q.chosen && k === q.chosen) d.classList.add("chosen");
      d.innerHTML = `<b>${k}</b>. ${v}`;
      optsEl.appendChild(d);
    }

    const expEl = document.getElementById("exp");
    expEl.innerHTML = `<div class="title bad">์ •๋‹ต: ${q.answer}</div><div>${q.explanation || "ํ•ด์„ค ์—†์Œ"}</div>`;
    expEl.classList.remove("show");

    document.getElementById("loading").style.display = "none";
    document.getElementById("qContainer").style.display = "block";
  }

  document.getElementById("showExpBtn").onclick = () => {
    document.getElementById("exp").classList.add("show");
  };

  document.getElementById("prevBtn").onclick = () => {
    if (currentIndex > 0) { currentIndex--; show(); }
  };

  document.getElementById("nextBtn").onclick = () => {
    if (currentIndex < list.length - 1) { currentIndex++; show(); }
  };

  document.getElementById("homeBtn").onclick = () => {
    window.location.href = "/";
  };

  document.getElementById("deleteBtn").onclick = async () => {
    const q = list[currentIndex];

    await fetch("/api/wrong_remove", {
      method:"POST",
      headers:{"Content-Type":"application/json"},
      body:JSON.stringify({question_id:q.question_id})
    });
    await fetch("/api/review_remove", {
      method:"POST",
      headers:{"Content-Type":"application/json"},
      body:JSON.stringify({question_id:q.question_id})
    });

    list.splice(currentIndex,1);
    if (list.length === 0) location.reload();
    if (currentIndex >= list.length) currentIndex = list.length - 1;
    show();
  };

  load();
</script>
</body>
</html>