

<?php $__env->startSection('meta_title', 'Mesajı Düzenle - Forum'); ?>
<?php $__env->startSection('meta_description', 'Forum mesajını düzenleyin'); ?>

<?php $__env->startSection('styles'); ?>
<link rel="stylesheet" href="https://cdn.quilljs.com/1.3.7/quill.snow.css">
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
<style>
/* Edit Post Form */
.edit-post-container {
    max-width: 900px;
    margin: 0 auto;
}

.edit-header {
    background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 50%, #1d4ed8 100%);
    color: white;
    padding: 28px 32px;
    border-radius: 14px;
    margin-bottom: 24px;
    box-shadow: 0 15px 35px rgba(15, 23, 42, 0.25);
}

.edit-header h1 {
    font-size: 22px;
    font-weight: 800;
    margin-bottom: 8px;
}

.edit-header p {
    font-size: 13px;
    opacity: 0.85;
}

.edit-form {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 700;
    color: #334155;
    margin-bottom: 8px;
}

.form-textarea {
    width: 100%;
    min-height: 200px;
    padding: 14px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    font-size: 14px;
    font-family: inherit;
    color: #1e293b;
    outline: none;
    resize: vertical;
    line-height: 1.6;
    transition: all 0.2s;
    background: #fafbfc;
}

.form-textarea:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    background: white;
}

/* Quill container */
#edit-editor-container {
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    overflow: hidden;
    background: #fafbfc;
}
#edit-editor-container .ql-toolbar {
    border: none;
    background: #f8fafc;
    padding: 10px 14px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
}
#edit-editor-container .ql-toolbar .ql-formats {
    display: flex;
    align-items: center;
    gap: 4px;
}
#edit-editor-container .ql-toolbar button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
#edit-editor-container .ql-container {
    border: none;
    font-size: 14px;
    font-family: inherit;
}
#edit-editor-container .ql-editor {
    min-height: 200px;
    background: #fafbfc;
}
#edit-editor-container .ql-editor:focus {
    background: white;
}
#edit-editor-container .ql-editor.ql-blank::before {
    color: #94a3b8;
    font-style: normal;
}

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.btn-submit {
    padding: 12px 28px;
    background: linear-gradient(135deg, #1d4ed8 0%, #3b82f6 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 12px rgba(29, 78, 216, 0.25);
}

.btn-submit:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(29, 78, 216, 0.35);
}

.btn-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-cancel {
    padding: 12px 20px;
    background: white;
    color: #64748b;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
}

.btn-cancel:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
}

.notice {
    background: #fef3c7;
    border: 1px solid #fde68a;
    border-radius: 10px;
    padding: 16px 20px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: #92400e;
}

.notice-icon {
    font-size: 18px;
}

.original-content {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 16px;
    margin-bottom: 20px;
    max-height: 200px;
    overflow-y: auto;
}

.original-content-label {
    font-size: 12px;
    font-weight: 700;
    color: #64748b;
    margin-bottom: 8px;
    display: block;
}

.original-content-text {
    font-size: 13px;
    color: #475569;
    line-height: 1.6;
}

@media (max-width: 640px) {
    .edit-header {
        padding: 20px;
    }

    .edit-header h1 {
        font-size: 18px;
    }

    .edit-form {
        padding: 16px;
    }

    .form-actions {
        flex-direction: column;
    }

    .btn-submit,
    .btn-cancel {
        width: 100%;
        justify-content: center;
    }
}
</style>

<div class="edit-post-container">
    
    <div class="breadcrumb">
        <a href="<?php echo e(route('forum.index')); ?>">Forum</a>
        <span class="breadcrumb-sep">/</span>
        <a href="<?php echo e(route('forum.category', $category->slug)); ?>"><?php echo e($category->name); ?></a>
        <span class="breadcrumb-sep">/</span>
        <a href="<?php echo e(route('forum.topic', [$category->slug, $topic->slug])); ?>"><?php echo e(Str::limit($topic->title, 45)); ?></a>
        <span class="breadcrumb-sep">/</span>
        <span>Mesajı Düzenle</span>
    </div>

    
    <div class="edit-header">
        <h1>✏️ Mesajı Düzenle</h1>
        <p>Mesajınızı güncelleyin. Tüm değişiklikler kaydedilecektir.</p>
    </div>

    
    <div class="notice">
        <div class="notice-icon">ℹ️</div>
        <div>Mesajınızı düzenledikten sonra tüm kullanıcılar düzenlendi olduğunu görecekler.</div>
    </div>

    
    <?php if($post->content): ?>
    <div class="original-content">
        <span class="original-content-label">📝 Orijinal Mesaj:</span>
        <div class="original-content-text">
            <?php echo nl2br(e(Str::limit($post->content, 500))); ?>

        </div>
    </div>
    <?php endif; ?>

    
    <div class="edit-form">
        <form action="<?php echo e(route('forum.posts.update', [$category->slug, $topic->slug, $post->id])); ?>" method="POST" id="edit-form">
            <?php echo csrf_field(); ?>
            <?php echo method_field('PUT'); ?>

            <div class="form-group">
                
                <div id="edit-editor-container"></div>
                
                <textarea name="content" id="edit-content" style="display:none;" required minlength="5"><?php echo e($post->content); ?></textarea>
                <?php $__errorArgs = ['content'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                    <div style="color:#dc2626;font-size:12px;margin-top:4px;"><?php echo e($message); ?></div>
                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
            </div>

            <div class="form-actions">
                <button type="submit" class="btn-submit" id="submit-btn">
                    ✅ Değişiklikleri Kaydet
                </button>
                <a href="<?php echo e(route('forum.topic', [$category->slug, $topic->slug])); ?>" class="btn-cancel">
                    İptal
                </a>
            </div>
        </form>
    </div>
</div>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
<script src="https://cdn.quilljs.com/1.3.7/quill.min.js"></script>
<script>
var editEditor = null;

function setupImageUpload(editor) {
    var toolbar = editor.getModule('toolbar');
    toolbar.addHandler('image', function() {
        var input = document.createElement('input');
        input.setAttribute('type', 'file');
        input.setAttribute('accept', 'image/jpeg,image/jpg,image/png,image/gif,image/webp');
        input.click();
        input.onchange = function() {
            var file = input.files[0];
            if (!file) return;
            if (file.size > 5 * 1024 * 1024) { alert('Görsel en fazla 5MB olabilir.'); return; }
            var formData = new FormData();
            formData.append('image', file);
            formData.append('_token', document.querySelector('meta[name="csrf-token"]').getAttribute('content'));
            var range = editor.getSelection(true);
            editor.insertText(range.index, '⏳ Yükleniyor...', 'user');
            fetch('<?php echo e(url('forum/upload-image')); ?>', { method: 'POST', body: formData })
                .then(function(r) { return r.json(); })
                .then(function(data) {
                    editor.deleteText(range.index, '⏳ Yükleniyor...'.length);
                    if (data && data.url) {
                        editor.insertEmbed(range.index, 'image', data.url, 'user');
                        editor.setSelection(range.index + 1);
                    } else { alert('Görsel yüklenemedi.'); }
                })
                .catch(function() { editor.deleteText(range.index, '⏳ Yükleniyor...'.length); alert('Hata oluştu.'); });
        };
    });
}

document.addEventListener('DOMContentLoaded', function () {
    var existingContent = document.getElementById('edit-content').value || '';

    editEditor = new Quill('#edit-editor-container', {
        theme: 'snow',
        placeholder: 'Mesajınızı düzenleyin...',
        modules: {
            toolbar: [
                [{ 'header': [2, 3] }],
                ['bold', 'italic', 'underline', 'strike'],
                ['blockquote', 'code-block'],
                [{ 'list': 'ordered'}, { 'list': 'bullet' }],
                ['link', 'image', 'video'],
                ['clean']
            ]
        }
    });

    setupImageUpload(editEditor);

    if (existingContent.trim()) {
        if (/<[a-z][\s\S]*>/i.test(existingContent)) {
            editEditor.clipboard.dangerouslyPasteHTML(existingContent);
        } else {
            editEditor.setText(existingContent);
        }
    }
});

document.getElementById('edit-form')?.addEventListener('submit', function() {
    if (editEditor) {
        var ta = document.getElementById('edit-content');
        if (ta) ta.value = editEditor.root.innerHTML;
    }
    var btn = document.getElementById('submit-btn');
    if (btn) { btn.disabled = true; btn.textContent = 'Kaydediliyor...'; }
});
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.public', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\askeribilgiler\resources\views\forum\edit-post.blade.php ENDPATH**/ ?>