<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('文件校对')" />
    <style>
        .file-check-container {
            display: flex;
            width: 100%;
            height: 600px;
            border: 1px solid #e6e6e6;
            border-radius: 4px;
        }
        .original-file {
            flex: 1.5;
            padding: 15px;
            overflow-y: auto;
            border-right: 1px solid #e6e6e6;
            background-color: #fafafa;
        }
        .check-result {
            flex: 1;
            padding: 15px;
            overflow-y: auto;
            background-color: #fff;
        }
        .file-title {
            font-size: 18px;
            font-weight: bold;
            margin-bottom: 15px;
            color: #333;
        }
        .file-content {
            line-height: 1.6;
            white-space: pre-wrap;
            padding: 10px;
            background-color: #fff;
            border: 1px solid #eee;
            border-radius: 4px;
            height: calc(100% - 40px);
            overflow-y: auto;
        }
        .error-section {
            margin-top: 20px;
            padding: 10px;
            background-color: #fff8f8;
            border-left: 3px solid #ff4d4f;
        }
        .error-title {
            font-weight: bold;
            color: #ff4d4f;
            margin-bottom: 10px;
        }
        .error-item {
            margin-bottom: 8px;
            padding-left: 15px;
            position: relative;
        }
        .error-item:before {
            content: "•";
            position: absolute;
            left: 0;
            color: #ff4d4f;
        }
        .suggestion-table {
            width: 100%;
            margin-top: 5px;
            border-collapse: collapse;
        }
        .suggestion-table th, .suggestion-table td {
            padding: 5px;
            border: 1px solid #ddd;
        }
        .suggestion-table th {
            background-color: #f5f5f5;
            width: 80px;
        }
    </style>
</head>
<body class="white-bg">
<form id="form-filejiaodui-edit" th:object="${trsFileInfo}">
    <input type="hidden" name="doccontent" th:field="*{doccontent}">
    <input type="hidden" name="docname" id="docname" th:field="*{docname}">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <div class="file-check-container">
            <!-- 左侧原始文件内容 -->
            <div class="original-file">
                <div class="file-title">文件内容</div>
                <div class="file-content" id="file-content-display" th:text="${trsFileInfo.doccontent}"></div>
            </div>

            <!-- 右侧校对结果 -->
            <div class="check-result">
                <div class="file-title">校对结果</div>
                <div id="check-results-container" style="height: calc(100% - 40px); overflow-y: auto;">
                    <!-- 动态内容将在这里显示 -->
                </div>
            </div>
        </div>
    </div>
</form>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var prefix = ctx + "project/filejiaodui";
    var prefixjiaodui = ctx + "project/jiaodui";
    $("#form-filejiaodui-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            //确定按钮
            $.modal.close();
            //$.operate.save(prefix + "/edit", $('#form-filejiaodui-edit').serialize());
        }
    }

    $(function() {
        var content = $('#file-content-display').text();
        $('input[name="doccontent"]').val(content);
        jiaodui();
    });

    function jiaodui() {
        var content = $('#file-content-display').text();
        var title = $('#docname').val();
        var data = { "content": content, "title" : title, "type": "1" };
        $.get(prefixjiaodui + "/jiaodui", data, function(result) {
            if (result.code == web_status.SUCCESS) {
                let errorData = result.data;
                let errorHtml = '';

                if (errorData && errorData.length > 0) {
                    errorHtml += `
                        <div class="error-section">
                            <div class="error-title">字词错误（${errorData.length}）</div>`;

                    errorData.forEach(error => {
                        errorHtml += `
                            <div class="error-item">
                                <strong>${error.wrongWord}</strong> → <strong>${error.correctWord}</strong>
                                <table class="suggestion-table">
                                    <tr>
                                        <th>位置</th>
                                        <td>${error.content}</td>
                                    </tr>
                                    <tr>
                                        <th>建议</th>
                                        <td>${error.suggestion || error.correctWord}</td>
                                    </tr>
                                </table>
                            </div>`;
                    });

                    errorHtml += `</div>`;
                } else {
                    errorHtml = `<div class="no-errors">未发现错误</div>`;
                }

                $('#check-results-container').html(errorHtml);
            } else {
                $.modal.alertError(result.msg);
            }
            $.modal.closeLoading();
        });
    }
</script>
</body>
</html>