

<?php $__env->startSection('header-title', 'Blog Yazısını Düzenle'); ?>

<?php $__env->startPush('styles'); ?>
<link href="https://cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet">
<style>
    /* Blog Edit Page - Scoped Styles (prefixed with .be- to avoid admin layout conflicts) */

    .be-header {
        background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
        padding: 2rem;
        border-radius: 12px;
        margin-bottom: 1.5rem;
        color: white;
        box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    }

    .be-header h1 {
        font-size: 1.75rem;
        font-weight: 700;
        margin: 0 0 0.5rem 0;
    }

    .be-header p {
        font-size: 0.95rem;
        opacity: 0.85;
        margin: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .be-layout {
        display: grid;
        grid-template-columns: 1fr 340px;
        gap: 1.5rem;
        align-items: start;
    }

    @media (max-width: 1200px) {
        .be-layout { grid-template-columns: 1fr; }
    }

    .be-card {
        background: #ffffff;
        border: 1px solid #e2e8f0;
        border-radius: 12px;
        padding: 1.5rem;
        margin-bottom: 1.5rem;
        box-shadow: 0 1px 2px 0 rgba(0,0,0,0.05);
    }

    .be-card-title {
        font-size: 1rem;
        font-weight: 600;
        color: #0f172a;
        margin: 0 0 1rem 0;
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }

    .be-card-title svg {
        width: 18px;
        height: 18px;
        color: #3b82f6;
        flex-shrink: 0;
    }

    .be-field {
        margin-bottom: 1.25rem;
    }

    .be-field:last-child {
        margin-bottom: 0;
    }

    .be-label {
        display: block;
        font-weight: 500;
        color: #334155;
        margin-bottom: 0.5rem;
        font-size: 0.875rem;
    }

    .be-label.required::after {
        content: ' *';
        color: #ef4444;
    }

    .be-input,
    .be-textarea,
    .be-select {
        width: 100%;
        padding: 0.75rem 1rem;
        border: 1.5px solid #cbd5e1;
        border-radius: 8px;
        font-size: 0.9375rem;
        font-family: inherit;
        color: #1e293b;
        background: #ffffff;
        transition: border-color 0.15s ease, box-shadow 0.15s ease;
        box-sizing: border-box;
    }

    .be-input:focus,
    .be-textarea:focus,
    .be-select:focus {
        outline: none;
        border-color: #3b82f6;
        box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
    }

    .be-textarea {
        resize: vertical;
        min-height: 90px;
        line-height: 1.6;
    }

    .be-hint {
        font-size: 0.8rem;
        color: #64748b;
        margin-top: 0.375rem;
    }

    .be-error {
        color: #ef4444;
        font-size: 0.8rem;
        margin-top: 0.375rem;
        display: flex;
        align-items: center;
        gap: 4px;
    }

    .be-char-count {
        font-size: 0.75rem;
        color: #94a3b8;
        margin-top: 0.375rem;
        text-align: right;
    }

    /* Editor */
    .be-editor-wrap {
        border: 1.5px solid #cbd5e1;
        border-radius: 12px;
        overflow: hidden;
        background: #ffffff;
    }

    .be-editor-toolbar {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.625rem 1rem;
        background: #f8fafc;
        border-bottom: 1px solid #e2e8f0;
    }

    .be-mode-toggle {
        display: flex;
        background: #e2e8f0;
        border-radius: 7px;
        padding: 3px;
        gap: 2px;
    }

    .be-mode-btn {
        padding: 0.3rem 0.75rem;
        font-size: 0.8rem;
        font-weight: 500;
        border: none;
        background: transparent;
        color: #475569;
        cursor: pointer;
        border-radius: 5px;
        transition: all 0.15s ease;
    }

    .be-mode-btn:hover { color: #1e293b; }

    .be-mode-btn.active {
        background: #ffffff;
        color: #3b82f6;
        box-shadow: 0 1px 2px rgba(0,0,0,0.08);
    }

    .be-quill {
        min-height: 380px;
        background: #ffffff;
    }

    .be-quill .ql-toolbar.ql-snow {
        border: none;
        border-bottom: 1px solid #e2e8f0;
        background: #f8fafc;
        padding: 0.625rem;
    }

    .be-quill .ql-container.ql-snow {
        border: none;
        font-size: 0.9375rem;
        line-height: 1.75;
        font-family: inherit;
    }

    .be-quill .ql-editor {
        padding: 1.25rem;
        min-height: 340px;
    }

    .be-source {
        display: none;
        width: 100%;
        min-height: 380px;
        padding: 1rem;
        font-size: 0.85rem;
        font-family: 'Fira Code', 'Consolas', 'Monaco', monospace;
        border: none;
        background: #1e1e2e;
        color: #cdd6f4;
        resize: vertical;
        box-sizing: border-box;
    }

    /* Image Upload */
    .be-img-drop {
        border: 2px dashed #cbd5e1;
        border-radius: 10px;
        padding: 2rem 1.5rem;
        text-align: center;
        cursor: pointer;
        transition: all 0.2s ease;
    }

    .be-img-drop:hover {
        border-color: #3b82f6;
        background: rgba(59,130,246,0.03);
    }

    .be-img-drop svg {
        width: 48px;
        height: 48px;
        color: #94a3b8;
        margin: 0 auto 0.75rem;
        display: block;
    }

    .be-img-drop p {
        font-size: 0.875rem;
        color: #64748b;
        margin: 0;
    }

    .be-img-drop p strong { color: #3b82f6; }

    .be-img-drop small {
        font-size: 0.75rem;
        color: #94a3b8;
        display: block;
        margin-top: 0.375rem;
    }

    .be-img-preview { margin-top: 1rem; }

    .be-img-preview img {
        width: 100%;
        border-radius: 8px;
        margin-bottom: 0.75rem;
        display: block;
    }

    /* Radio */
    .be-radio-group { display: flex; flex-direction: column; gap: 0.5rem; }

    .be-radio-item {
        display: flex;
        align-items: center;
        gap: 0.625rem;
        padding: 0.625rem 0.875rem;
        border-radius: 8px;
        cursor: pointer;
        transition: background 0.15s ease;
    }

    .be-radio-item:hover { background: #f8fafc; }

    .be-radio-item input[type="radio"] {
        width: 1.1rem;
        height: 1.1rem;
        accent-color: #3b82f6;
    }

    .be-badge {
        display: inline-flex;
        align-items: center;
        gap: 0.3rem;
        padding: 0.3rem 0.7rem;
        border-radius: 999px;
        font-size: 0.8rem;
        font-weight: 500;
    }

    .be-badge.draft   { background: rgba(148,163,184,0.15); color: #475569; }
    .be-badge.live    { background: rgba(16,185,129,0.12);  color: #059669; }
    .be-badge.archive { background: rgba(100,116,139,0.12); color: #64748b; }

    /* Buttons */
    .be-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        padding: 0.75rem 1.5rem;
        font-size: 0.9rem;
        font-weight: 500;
        border: none;
        border-radius: 8px;
        cursor: pointer;
        transition: all 0.2s ease;
        text-decoration: none;
        font-family: inherit;
    }

    .be-btn-primary {
        background: #3b82f6;
        color: white;
    }

    .be-btn-primary:hover {
        background: #2563eb;
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(59,130,246,0.3);
        color: white;
        text-decoration: none;
    }

    .be-btn-ghost {
        background: #f1f5f9;
        color: #334155;
    }

    .be-btn-ghost:hover {
        background: #e2e8f0;
        color: #1e293b;
        text-decoration: none;
    }

    .be-btn-group {
        display: flex;
        gap: 0.75rem;
    }

    .be-btn-full { width: 100%; }

    .be-btn:disabled {
        opacity: 0.55;
        cursor: not-allowed;
        transform: none !important;
    }

    /* Quick Actions */
    .be-actions-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
        margin-bottom: 0.75rem;
    }

    .be-action-btn {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 0.375rem;
        padding: 0.75rem 0.5rem;
        background: #f8fafc;
        border: 1px solid #e2e8f0;
        border-radius: 8px;
        font-size: 0.75rem;
        font-weight: 500;
        color: #475569;
        cursor: pointer;
        transition: all 0.15s ease;
        font-family: inherit;
    }

    .be-action-btn:hover {
        background: #f1f5f9;
        border-color: #cbd5e1;
        color: #1e293b;
    }

    .be-action-btn svg {
        width: 20px;
        height: 20px;
        color: #3b82f6;
    }

    /* SEO */
    .be-seo-card {
        background: #f8fafc;
        border-radius: 8px;
        padding: 1rem;
        margin-top: 0.75rem;
    }

    .be-seo-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 0.875rem;
    }

    .be-seo-grade {
        width: 52px;
        height: 52px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.2rem;
        font-weight: 700;
        color: white;
    }

    .be-seo-grade.grade-a { background: #10b981; }
    .be-seo-grade.grade-b { background: #3b82f6; }
    .be-seo-grade.grade-c { background: #f59e0b; }
    .be-seo-grade.grade-d { background: #f97316; }
    .be-seo-grade.grade-e,
    .be-seo-grade.grade-f { background: #ef4444; }

    .be-seo-row {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0.4rem 0;
        border-bottom: 1px solid #e2e8f0;
        font-size: 0.82rem;
    }

    .be-seo-row:last-child { border-bottom: none; }

    .be-seo-bar {
        width: 70px;
        height: 5px;
        background: #e2e8f0;
        border-radius: 3px;
        overflow: hidden;
        margin: 0 0.625rem;
    }

    .be-seo-bar-fill {
        height: 100%;
        border-radius: 3px;
        transition: width 0.3s ease;
    }

    /* Checklist */
    .be-check-item {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        padding: 0.4rem 0;
        font-size: 0.83rem;
        color: #334155;
    }

    .be-check-item svg { width: 16px; height: 16px; flex-shrink: 0; }
    .be-check-item.pass svg { color: #10b981; }
    .be-check-item.fail svg { color: #ef4444; }

    /* AdSense */
    .be-ad-zone {
        display: flex;
        align-items: center;
        gap: 0.625rem;
        padding: 0.625rem 0.75rem;
        border: 1px solid #e2e8f0;
        border-radius: 8px;
        margin-bottom: 0.5rem;
        font-size: 0.85rem;
    }

    .be-ad-zone input[type="checkbox"] {
        width: 1rem;
        height: 1rem;
        accent-color: #3b82f6;
    }

    /* Warnings */
    .be-dup-warning {
        background: #fef2f2;
        border: 1px solid #fecaca;
        border-radius: 8px;
        padding: 0.75rem;
        margin-top: 0.75rem;
        font-size: 0.83rem;
    }

    .be-dup-warning a { color: #3b82f6; text-decoration: none; font-weight: 500; }
    .be-dup-warning a:hover { text-decoration: underline; }

    /* Empty state */
    .be-empty {
        padding: 1.5rem;
        text-align: center;
        background: #f8fafc;
        border-radius: 8px;
        border: 1px dashed #cbd5e1;
    }

    .be-empty p { color: #64748b; font-size: 0.875rem; margin-bottom: 0.625rem; }
    .be-empty a { color: #3b82f6; text-decoration: none; font-weight: 500; }

    /* Spinner */
    .be-spin {
        display: inline-block;
        width: 14px;
        height: 14px;
        border: 2px solid rgba(255,255,255,0.3);
        border-top-color: white;
        border-radius: 50%;
        animation: be-spin 0.7s linear infinite;
    }

    @keyframes be-spin { to { transform: rotate(360deg); } }

    .be-hint-box {
        background: #eff6ff;
        border: 1px solid #bfdbfe;
        border-radius: 6px;
        padding: 0.625rem 0.875rem;
        font-size: 0.8rem;
        color: #1d4ed8;
        margin-top: 0.75rem;
    }

    .be-sug-item {
        padding: 0.6rem 0.75rem;
        border-radius: 6px;
        margin-bottom: 0.4rem;
        font-size: 0.8rem;
    }

    .be-sug-item.error   { background: #fef2f2; color: #991b1b; }
    .be-sug-item.warning { background: #fffbeb; color: #92400e; }
    .be-sug-item.info    { background: #eff6ff; color: #1e40af; }
</style>
<?php $__env->stopPush(); ?>

<?php $__env->startSection('content'); ?>
<div class="be-header">
    <h1>✏️ Blog Yazısını Düzenle</h1>
    <p><?php echo e($blog->title); ?></p>
</div>

<form action="<?php echo e(route('admin.blog.update', $blog)); ?>" method="POST" enctype="multipart/form-data" id="blogForm">
    <?php echo csrf_field(); ?>
    <?php echo method_field('PUT'); ?>

    <div class="be-layout">
        
        <div>
            
            <div class="be-card">
                <div class="be-field">
                    <label class="be-label required" for="post_title">Başlık</label>
                    <input type="text" name="title" id="post_title"
                           value="<?php echo e(old('title', $blog->title)); ?>"
                           required placeholder="Blog yazısı başlığını girin..."
                           class="be-input">
                    <?php $__errorArgs = ['title'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <div class="be-error"><?php echo e($message); ?></div>
                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    <div id="duplicate_warning"></div>
                </div>

                <div class="be-field">
                    <label class="be-label" for="post_excerpt">Özet</label>
                    <textarea name="excerpt" id="post_excerpt" rows="3"
                              placeholder="Kısa bir özet yazın..."
                              class="be-textarea"><?php echo e(old('excerpt', $blog->excerpt)); ?></textarea>
                    <div class="be-hint">Arama sonuçlarında ve sosyal medyada gösterilir.</div>
                    <?php $__errorArgs = ['excerpt'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <div class="be-error"><?php echo e($message); ?></div>
                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                </div>
            </div>

            
            <div class="be-card">
                <div class="be-card-title">
                    <svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                              d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"/>
                    </svg>
                    İçerik
                </div>

                <input type="hidden" name="content" id="editor_hidden">

                <?php
                    $existingContent = '';
                    if (old('content')) {
                        $existingContent = old('content');
                    } elseif ($blog->content) {
                        if (is_array($blog->content)) {
                            $existingContent = $blog->content['html'] ??
                                (is_string($blog->content[0] ?? null) ? implode('', $blog->content) : '');
                        } else {
                            $existingContent = $blog->content;
                        }
                    }
                ?>

                <div class="be-editor-wrap">
                    <div class="be-editor-toolbar">
                        <span class="be-label" style="margin:0; font-size:0.8rem;">Editör Modu</span>
                        <div class="be-mode-toggle">
                            <button type="button" class="be-mode-btn active" id="btn_visual" onclick="switchToVisual()">
                                👁️ Görsel
                            </button>
                            <button type="button" class="be-mode-btn" id="btn_source" onclick="switchToSource()">
                                &lt;/&gt; HTML
                            </button>
                        </div>
                    </div>
                    <div id="quill_editor" class="be-quill"></div>
                    <textarea id="source_editor" class="be-source"
                              placeholder="HTML kodunu buraya yazın..."></textarea>
                </div>

                <?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 class="be-error"><?php echo e($message); ?></div>
                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
            </div>

            
            <div class="be-card">
                <div class="be-card-title">
                    <svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                              d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"/>
                    </svg>
                    SEO Ayarları
                </div>

                <div class="be-field">
                    <label class="be-label" for="meta_title">Meta Başlığı</label>
                    <input type="text" name="meta_title" id="meta_title"
                           value="<?php echo e(old('meta_title', $blog->meta_title)); ?>"
                           placeholder="Arama motorları için başlık (max 60 karakter)..."
                           class="be-input">
                    <div class="be-char-count" id="meta_title_count">
                        <?php echo e(mb_strlen(old('meta_title', $blog->meta_title))); ?>/60
                    </div>
                    <?php $__errorArgs = ['meta_title'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <div class="be-error"><?php echo e($message); ?></div>
                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                </div>

                <div class="be-field">
                    <label class="be-label" for="meta_description">Meta Açıklaması</label>
                    <textarea name="meta_description" id="meta_description" rows="3"
                              placeholder="Arama sonuçlarında gösterilecek açıklama (max 160 karakter)..."
                              class="be-textarea"><?php echo e(old('meta_description', $blog->meta_description)); ?></textarea>
                    <div class="be-char-count" id="meta_desc_count">
                        <?php echo e(mb_strlen(old('meta_description', $blog->meta_description))); ?>/160
                    </div>
                    <?php $__errorArgs = ['meta_description'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <div class="be-error"><?php echo e($message); ?></div>
                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                </div>
            </div>
        </div>

        
        <div>
            
            <div class="be-card" style="padding:1rem;">
                <div class="be-actions-grid">
                    <button type="button" class="be-action-btn" id="seo_btn" onclick="checkSeo()">
                        <svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                  d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"/>
                        </svg>
                        SEO Analizi
                    </button>
                    <button type="button" class="be-action-btn" id="check_btn" onclick="checkPublish()">
                        <svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                  d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
                        </svg>
                        Yayın Kontrolü
                    </button>
                </div>
                <div id="seo_result"></div>
                <div id="publish_checklist"></div>
            </div>

            
            <div class="be-card">
                <div class="be-card-title">
                    <svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                              d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/>
                    </svg>
                    Öne Çıkan Görsel
                </div>

                <input type="file" name="featured_image" accept="image/*"
                       id="featured_image" style="display:none;">
                <label for="featured_image" class="be-img-drop">
                    <svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                              d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/>
                    </svg>
                    <p><strong>Görsel seç</strong> veya sürükle</p>
                    <small>JPEG, PNG, WebP, GIF (max 2MB)</small>
                </label>

                <div id="image-preview" class="be-img-preview">
                    <?php if($blog->featured_image): ?>
                        <img src="<?php echo e(asset('storage/' . $blog->featured_image)); ?>" alt="Görsel">
                        <button type="button" onclick="removeImage()"
                                style="width:100%;padding:8px;background:rgba(239,68,68,.1);color:#ef4444;border:none;border-radius:6px;font-size:13px;cursor:pointer;">
                            Kaldır
                        </button>
                    <?php endif; ?>
                </div>
            </div>

            
            <div class="be-card">
                <div class="be-card-title">
                    <svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                              d="M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z"/>
                    </svg>
                    Kategori
                </div>
                <select name="category_id" required class="be-select">
                    <option value="">Kategori seçin...</option>
                    <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($category->id); ?>"
                            <?php echo e(old('category_id', $blog->category_id) == $category->id ? 'selected' : ''); ?>>
                            <?php echo e($category->name); ?>

                        </option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
                <?php $__errorArgs = ['category_id'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                    <div class="be-error"><?php echo e($message); ?></div>
                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
            </div>

            
            <div class="be-card">
                <div class="be-card-title">
                    <svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                              d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"/>
                    </svg>
                    Yayın Durumu
                </div>
                <div class="be-radio-group">
                    <label class="be-radio-item">
                        <input type="radio" name="status" value="draft"
                               <?php echo e(old('status', $blog->status) === 'draft' ? 'checked' : ''); ?>>
                        <span class="be-badge draft">📝 Taslak</span>
                    </label>
                    <label class="be-radio-item">
                        <input type="radio" name="status" value="published"
                               <?php echo e(old('status', $blog->status) === 'published' ? 'checked' : ''); ?>

                               id="status_published">
                        <span class="be-badge live">🚀 Yayında</span>
                    </label>
                    <label class="be-radio-item">
                        <input type="radio" name="status" value="archived"
                               <?php echo e(old('status', $blog->status) === 'archived' ? 'checked' : ''); ?>>
                        <span class="be-badge archive">📦 Arşiv</span>
                    </label>
                </div>
            </div>

            
            <div class="be-card">
                <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:1rem;">
                    <div class="be-card-title" style="margin:0;">
                        <svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                  d="M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
                        </svg>
                        AdSense
                    </div>
                    <a href="<?php echo e(route('admin.adsense.index')); ?>" target="_blank"
                       style="color:#3b82f6;text-decoration:none;font-size:0.8rem;font-weight:500;">
                        Yönet →
                    </a>
                </div>
                <?php if($adSenseZones->count() > 0): ?>
                    <?php $__currentLoopData = $adSenseZones; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $zone): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <div class="be-ad-zone">
                            <input type="checkbox" name="adsense_zones[]"
                                   value="<?php echo e($zone->id); ?>" id="zone_<?php echo e($zone->id); ?>"
                                   <?php if($blog->adSenseZones && $blog->adSenseZones->contains($zone->id)): ?> checked <?php endif; ?>>
                            <label for="zone_<?php echo e($zone->id); ?>" style="flex:1;cursor:pointer;margin:0;">
                                <strong><?php echo e($zone->name); ?></strong>
                                <span style="color:#94a3b8;font-size:0.75rem;margin-left:4px;">(<?php echo e($zone->location); ?>)</span>
                            </label>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                <?php else: ?>
                    <div class="be-empty">
                        <p>Henüz aktif AdSense alanı yok</p>
                        <a href="<?php echo e(route('admin.adsense.create')); ?>" target="_blank">İlk alanı oluştur →</a>
                    </div>
                <?php endif; ?>
            </div>

            
            <div class="be-btn-group">
                <button type="submit" class="be-btn be-btn-primary be-btn-full">
                    <svg style="width:18px;height:18px;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>
                    </svg>
                    Güncelle
                </button>
                <a href="<?php echo e(route('admin.blog.index')); ?>" class="be-btn be-btn-ghost be-btn-full">
                    İptal
                </a>
            </div>
        </div>
    </div>
</form>

<script src="https://cdn.quilljs.com/1.3.6/quill.js"></script>
<script>
var existingContentHtml = <?php echo json_encode($existingContent, 15, 512) ?>;
let currentImageFile = null;
let duplicateCheckTimeout = null;
let quillEditor = null;
let currentMode = 'visual';

document.addEventListener('DOMContentLoaded', function() {
    quillEditor = new Quill('#quill_editor', {
        theme: 'snow',
        modules: {
            toolbar: [
                [{ 'header': [1, 2, 3, 4, 5, 6, false] }],
                ['bold', 'italic', 'underline', 'strike'],
                [{ 'align': [] }],
                [{ 'list': 'ordered'}, { 'list': 'bullet' }],
                ['blockquote', 'code-block'],
                ['link', 'image'],
                [{ 'color': [] }, { 'background': [] }],
                ['clean']
            ]
        },
        placeholder: 'Blog yazısının içeriğini yazın...'
    });

    if (existingContentHtml) {
        quillEditor.clipboard.dangerouslyPasteHTML(existingContentHtml);
    }
});

// Meta counters
document.getElementById('meta_title').addEventListener('input', function() {
    document.getElementById('meta_title_count').textContent = this.value.length + '/60';
});

document.getElementById('meta_description').addEventListener('input', function() {
    document.getElementById('meta_desc_count').textContent = this.value.length + '/160';
});

// Duplicate title check
document.getElementById('post_title').addEventListener('input', function() {
    clearTimeout(duplicateCheckTimeout);
    const title = this.value.trim();
    if (title.length < 5) {
        document.getElementById('duplicate_warning').innerHTML = '';
        return;
    }
    duplicateCheckTimeout = setTimeout(() => checkDuplicate(title), 600);
});

async function checkDuplicate(title) {
    try {
        const res = await fetch('<?php echo e(route('admin.blog.check_duplicate')); ?>', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': '<?php echo e(csrf_token()); ?>' },
            body: JSON.stringify({ title, exclude_id: <?php echo e($blog->id); ?> })
        });
        const result = await res.json();
        if (result.success && result.has_duplicates) {
            let html = '<div class="be-dup-warning"><strong>⚠️ Benzer başlıklar:</strong><ul style="margin:6px 0 0 18px;padding:0;">';
            result.duplicates.forEach(d => {
                html += `<li><a href="/admin/blog/${d.id}/edit" target="_blank">${d.title}</a></li>`;
            });
            document.getElementById('duplicate_warning').innerHTML = html + '</ul></div>';
        } else {
            document.getElementById('duplicate_warning').innerHTML = '';
        }
    } catch(e) { console.error(e); }
}

// Image upload
document.getElementById('featured_image').addEventListener('change', function(e) {
    const file = e.target.files[0];
    if (!file) return;
    currentImageFile = file;
    const reader = new FileReader();
    reader.onload = (e) => {
        document.getElementById('image-preview').innerHTML =
            '<img src="' + e.target.result + '" alt="Önizleme">' +
            '<button type="button" onclick="removeImage()" style="width:100%;padding:8px;background:rgba(239,68,68,.1);color:#ef4444;border:none;border-radius:6px;font-size:13px;cursor:pointer;margin-top:4px;">Kaldır</button>';
    };
    reader.readAsDataURL(file);
});

function removeImage() {
    document.getElementById('featured_image').value = '';
    document.getElementById('image-preview').innerHTML = '';
    currentImageFile = null;
}

// SEO Check
async function checkSeo() {
    const btn = document.getElementById('seo_btn');
    const div = document.getElementById('seo_result');
    btn.disabled = true;
    btn.innerHTML = '<span class="be-spin"></span> Analiz...';

    try {
        const res = await fetch('<?php echo e(route('admin.tools.seo_score')); ?>', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': '<?php echo e(csrf_token()); ?>' },
            body: JSON.stringify({
                title:            document.getElementById('post_title').value,
                excerpt:          document.getElementById('post_excerpt').value,
                content:          quillEditor.root.innerHTML,
                meta_title:       document.getElementById('meta_title').value,
                meta_description: document.getElementById('meta_description').value,
            })
        });
        const result = await res.json();
        if (result.success) renderSeo(result.data);
        else div.innerHTML = '<p style="color:#ef4444;font-size:.82rem;">Hata: ' + result.message + '</p>';
    } catch(e) {
        div.innerHTML = '<p style="color:#ef4444;font-size:.82rem;">Hata: ' + e.message + '</p>';
    }

    btn.disabled = false;
    btn.innerHTML = '<svg fill="none" stroke="currentColor" viewBox="0 0 24 24" style="width:20px;height:20px;color:#3b82f6;"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"/></svg>SEO Analizi';
}

function renderSeo(data) {
    const div = document.getElementById('seo_result');
    let rows = '';
    if (data.breakdown) {
        for (const [, item] of Object.entries(data.breakdown)) {
            const pct = (item.score / item.max) * 100;
            const c = pct >= 80 ? '#10b981' : pct >= 60 ? '#3b82f6' : pct >= 40 ? '#f59e0b' : '#ef4444';
            rows += `<div class="be-seo-row">
                <span>${item.label}</span>
                <div class="be-seo-bar"><div class="be-seo-bar-fill" style="width:${pct}%;background:${c};"></div></div>
                <span style="font-size:.75rem;font-weight:600;">${item.score}/${item.max}</span>
            </div>`;
        }
    }
    let sugs = '';
    if (data.suggestions?.length) {
        data.suggestions.forEach(s => {
            const ico = s.level === 'error' ? '❌' : s.level === 'warning' ? '⚠️' : 'ℹ️';
            sugs += `<div class="be-sug-item ${s.level}">${ico} ${s.message}</div>`;
        });
    }
    const g = (data.grade || 'F').toLowerCase();
    div.innerHTML = `<div class="be-seo-card">
        <div class="be-seo-header">
            <div>
                <div style="font-size:.78rem;color:#94a3b8;">SEO Puanı</div>
                <div style="font-size:1.5rem;font-weight:700;color:#0f172a;">${data.percentage}%</div>
            </div>
            <div class="be-seo-grade grade-${g}">${data.grade}</div>
        </div>
        ${rows}
        ${sugs ? '<div style="margin-top:.75rem;">' + sugs + '</div>' : ''}
    </div>`;
}

// Publish Checklist
async function checkPublish() {
    const btn = document.getElementById('check_btn');
    const div = document.getElementById('publish_checklist');
    btn.disabled = true;
    btn.innerHTML = '<span class="be-spin"></span> Kontrol...';

    try {
        const res = await fetch('<?php echo e(route('admin.blog.publish_checklist')); ?>', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': '<?php echo e(csrf_token()); ?>' },
            body: JSON.stringify({
                title:            document.getElementById('post_title').value,
                content:          quillEditor.root.innerHTML,
                excerpt:          document.getElementById('post_excerpt').value,
                meta_title:       document.getElementById('meta_title').value,
                meta_description: document.getElementById('meta_description').value,
                featured_image:   (currentImageFile || '<?php echo e($blog->featured_image); ?>') ? 'yes' : '',
            })
        });
        const result = await res.json();
        if (result.success) renderChecklist(result);
        else div.innerHTML = '<p style="color:#ef4444;font-size:.82rem;">Hata oluştu</p>';
    } catch(e) {
        div.innerHTML = '<p style="color:#ef4444;font-size:.82rem;">Hata: ' + e.message + '</p>';
    }

    btn.disabled = false;
    btn.innerHTML = '<svg fill="none" stroke="currentColor" viewBox="0 0 24 24" style="width:20px;height:20px;color:#3b82f6;"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>Yayın Kontrolü';
}

function renderChecklist(result) {
    const div = document.getElementById('publish_checklist');
    const cl = result.checklist;
    const ok = result.can_publish;
    const items = [
        { key: 'title',            label: 'Başlık (min 10 karakter)' },
        { key: 'content',          label: 'İçerik (min 300 kelime)' },
        { key: 'excerpt',          label: 'Özet' },
        { key: 'meta_title',       label: 'Meta Başlığı' },
        { key: 'meta_description', label: 'Meta Açıklaması' },
        { key: 'featured_image',   label: 'Öne Çıkan Görsel' },
    ];
    let html = '';
    items.forEach(item => {
        const pass = cl[item.key];
        const ico = pass
            ? `<svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/></svg>`
            : `<svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/></svg>`;
        html += `<div class="be-check-item ${pass ? 'pass' : 'fail'}">${ico}${item.label}</div>`;
    });
    div.innerHTML = `<div style="background:${ok ? '#f0fdf4' : '#fef2f2'};border:1px solid ${ok ? '#bbf7d0' : '#fecaca'};border-radius:8px;padding:1rem;margin-top:.75rem;">
        <div style="font-size:.83rem;font-weight:600;margin-bottom:.625rem;">${ok ? '✅ Yayınlamaya hazır!' : '⚠️ Düzeltmeler gerekli'}</div>
        ${html}
    </div>`;
}

// Editor mode toggle
function switchToVisual() {
    if (currentMode === 'visual') return;
    const src = document.getElementById('source_editor');
    quillEditor.clipboard.dangerouslyPasteHTML(src.value);
    document.getElementById('quill_editor').style.display = 'block';
    src.style.display = 'none';
    document.getElementById('btn_visual').classList.add('active');
    document.getElementById('btn_source').classList.remove('active');
    currentMode = 'visual';
}

function switchToSource() {
    if (currentMode === 'source') return;
    const src = document.getElementById('source_editor');
    src.value = quillEditor.root.innerHTML;
    document.getElementById('quill_editor').style.display = 'none';
    src.style.display = 'block';
    document.getElementById('btn_visual').classList.remove('active');
    document.getElementById('btn_source').classList.add('active');
    currentMode = 'source';
}

// Form submit
document.getElementById('blogForm').addEventListener('submit', function(e) {
    if (currentMode === 'source') {
        quillEditor.clipboard.dangerouslyPasteHTML(document.getElementById('source_editor').value);
    }

    const statusPublished = document.getElementById('status_published');
    if (statusPublished?.checked) {
        const text = quillEditor.getText().trim();
        const words = text.split(/\s+/).filter(w => w.length > 0).length;
        if (!document.getElementById('post_title').value.trim() || words < 300) {
            e.preventDefault();
            alert('⚠️ Yayınlamak için başlık girilmeli ve içerik en az 300 kelime olmalıdır.\n\nMevcut: ' + words + ' kelime');
            return false;
        }
    }

    document.getElementById('editor_hidden').value = quillEditor.root.innerHTML;
});
</script>
<?php $__env->stopSection(); ?>

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