<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Test Self Evaluation API</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
        }
        .message {
            margin-top: 10px;
            padding: 10px;
            background-color: #f4f4f4;
            border: 1px solid #ddd;
        }
    </style>
</head>
<body>
    <h2>Test Self Evaluation API</h2>

    <h3>Get Self Evaluation</h3>
    <label for="user_id_get">User ID:</label>
    <input type="number" id="user_id_get" min="1" placeholder="Enter user ID">
    <button onclick="getSelfEvaluation()">Get Self Evaluation</button>
    
    <div id="get-result" class="message"></div>

    <h3>Update Self Evaluation</h3>
    <label for="user_id_post">User ID:</label>
    <input type="number" id="user_id_post" min="1" placeholder="Enter user ID">
    <br><br>
    <label for="strengths">Strengths:</label>
    <textarea id="strengths" placeholder="Enter your strengths"></textarea>
    <br><br>
    <label for="weaknesses">Weaknesses:</label>
    <textarea id="weaknesses" placeholder="Enter your weaknesses"></textarea>
    <br><br>
    <label for="study_attitude">Study Attitude:</label>
    <textarea id="study_attitude" placeholder="Enter your study attitude"></textarea>
    <br><br>
    <label for="future_plans">Future Plans:</label>
    <textarea id="future_plans" placeholder="Enter your future plans"></textarea>
    <br><br>
    <button onclick="updateSelfEvaluation()">Update Self Evaluation</button>

    <div id="post-result" class="message"></div>

    <script>
        // Function to get self evaluation via GET request
        function getSelfEvaluation() {
            const userId = document.getElementById('user_id_get').value;
            const resultDiv = document.getElementById('get-result');

            if (!userId) {
                resultDiv.textContent = "Please enter a valid user ID.";
                return;
            }

            fetch(`/ec_user/self_evaluation/api/`, {
                method: 'GET',
                headers: {
                    'Content-Type': 'application/json',
                    'token': '486ef8198bb10ba6878eba95771c064ff64db81a'
                },
            })
            .then(response => response.json())
            .then(data => {
                if (data.error) {
                    resultDiv.textContent = `Error: ${data.error}`;
                } else {
                    resultDiv.textContent = `Strengths: ${data.strengths}, Weaknesses: ${data.weaknesses}, Study Attitude: ${data.study_attitude}, Future Plans: ${data.future_plans}`;
                }
            })
            .catch(error => {
                resultDiv.textContent = `Error: ${error.message}`;
            });
        }

        // Function to update self evaluation via POST request
        function updateSelfEvaluation() {
            const userId = document.getElementById('user_id_post').value;
            const strengths = document.getElementById('strengths').value;
            const weaknesses = document.getElementById('weaknesses').value;
            const studyAttitude = document.getElementById('study_attitude').value;
            const futurePlans = document.getElementById('future_plans').value;
            const resultDiv = document.getElementById('post-result');

            if (!userId || !strengths || !weaknesses || !studyAttitude || !futurePlans) {
                resultDiv.textContent = "Please fill out all fields.";
                return;
            }

            const postData = {
                strengths: strengths,
                weaknesses: weaknesses,
                study_attitude: studyAttitude,
                future_plans: futurePlans
            };

            fetch(`/ec_user/self_evaluation/api/`, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                    'token': '486ef8198bb10ba6878eba95771c064ff64db81a'
                },
                body: JSON.stringify(postData)
            })
            .then(response => response.json())
            .then(data => {
                if (data.error) {
                    resultDiv.textContent = `Error: ${data.error}`;
                } else {
                    resultDiv.textContent = data.message;
                }
            })
            .catch(error => {
                resultDiv.textContent = `Error: ${error.message}`;
            });
        }
    </script>
</body>
</html>
