fc / rotation-creator-controller.js
Althnayi's picture
Upload 56 files
cca0cf3 verified
Raw
History Blame Contribute Delete
77.2 kB
/**
* @fileoverview Content Rotation Post Creator & Modal Editor Controller
* @module controllers/rotation-creator-controller
* @description وحدة التحكم في إنشاء وتعديل منشورات مكتبة التدوير، إدارة المرفقات، وربط رسائل المتابعة التلقائية.
*/
(global => {
'use strict';
const state = global.FritreeRotationState;
/**
* بناء نافذة إضافة منشور جديد لمكتبة التدوير بالـ DOM
*/
const appendAddModalLayout = () => {
let modal = document.getElementById('s74nhbmzs5');
if (modal) return;
modal = document.createElement('div');
modal.className = 'cpzxome5dd';
modal.id = 's74nhbmzs5';
modal.style.cssText = 'position: fixed; top: 0; left: 0; width: 100%; height: 100%; backdrop-filter: blur(8px); display: none; align-items: center; justify-content: center; z-index: var(--z-modal-backdrop); background-color: rgba(15, 23, 42, 0.65); direction: rtl; text-align: right; box-sizing: border-box;';
modal.innerHTML = `
<div class="s4yvtq9394" style="max-width: min(960px, 95vw); max-height: min(92vh, 900px); border-radius: var(--radius-xl); border: 1px solid var(--border); box-shadow: var(--shadow-modal); background: var(--bg-card);">
<div class="x8pdlyq70a" style="border-bottom: 1px solid var(--border); padding: 14px 20px; display: flex; justify-content: space-between; align-items: center; background: var(--bg-subtle);">
<div class="tooau3ykdi" style="font-weight: 800; font-size: 14px; display: flex; align-items: center; gap: 8px;">
<i class="fa-solid fa-plus-circle" style="color: #0d9488;"></i>
<span>إضافة منشور جديد للمكتبة وتجهيزه للتدوير</span>
</div>
<button class="bcuz086hu4" id="anctu5etze">&times;</button>
</div>
<div class="zn6t0dl6ke" style="max-height: 80vh; overflow-y: auto; padding: clamp(14px, 1.6vw, 22px); gap: var(--space-md);">
<div class="xd506q5mar" style="display: grid; grid-template-columns: repeat(auto-fit, minmax(clamp(280px, 30vw, 1fr), 1fr)); gap: 12px; margin-bottom: 0;">
<!-- العمود الأول: نص المنشور والـ Spintax -->
<div class="d5tp7way8h" style="height: 100%; display: flex; flex-direction: column; gap: 10px; margin: 0; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--bg-card); box-sizing: border-box;">
<div class="cm41ch7urz" style="margin-bottom: 2px; font-size: 13px;">
<span><i class="fa-solid fa-file-pen" style="color: var(--primary);"></i> <span>محتوى ونص المنشور</span></span>
</div>
<div class="d0uttwsjz2" style="margin: 0;">
<label style="font-weight: 700; font-size: 11.5px;"><i class="fa-solid fa-heading"></i> <span>اسم أو عنوان المنشور للتوضيح:</span></label>
<input type="text" id="wlunjizubf" class="xy26ymifmf" placeholder="مثال: منشور عروض الصيف العقارية">
</div>
<!-- فاحص الـ Spintax ومعاينة التمويه -->
<div class="suxidgikgm" style="margin-bottom: 0;">
<div class="dcaynff6el" style="margin-bottom: 4px;">
<span class="ipbz1xlmff" style="font-size: 11px; font-weight: 700;"><i class="fa-solid fa-wand-magic-sparkles" style="color: #8b5cf6;"></i> <span>محرك فحص الـ Spintax</span></span>
<div style="display: flex; gap: 4px;">
<button type="button" id="ukgv00a6ew" class="ipxi2jz4g0" style="padding: 3px 8px; font-size: 10px; height: auto;"><i class="fa-solid fa-microchip"></i> <span>فحص الجودة</span></button>
<button type="button" id="q1oy8rpm26" class="ipxi2jz4g0" style="padding: 3px 8px; font-size: 10px; height: auto;"><i class="fa-solid fa-mask"></i> <span>معاينة التمويه</span></button>
</div>
</div>
<div style="font-size: 10.5px; font-weight: 700; color: var(--text-muted);" id="pvd3acinzt">
<i class="fa-solid fa-circle-question"></i> <span>اكتب نصك واستخدم الأقواس {} وافحص جودة التوليد والتمويه...</span>
</div>
<div id="w2d0q5j0yl" style="display:none; margin-top: 8px; padding: 10px; border: 1px dashed var(--border-strong); border-radius: var(--radius-md); font-size: 11px; direction: rtl; text-align: right; background: var(--bg-subtle);">
<strong style="display: block; margin-bottom: 4px; color: var(--text-main);"><i class="fa-solid fa-eye"></i> <span>النص بعد التمويه وحقن البيانات الحقيقية:</span></strong>
<div id="p1yahnikb8" style="white-space: pre-wrap; color: var(--text-secondary); background: var(--bg-card); padding: 8px 10px; border-radius: var(--radius-sm); border: 1px solid var(--border); max-height: 100px; overflow-y: auto; font-size: 11.5px; line-height: 1.5;"></div>
<span style="font-size: 9.5px; margin-top: 4px; display: block; color: var(--text-muted);"><i class="fa-solid fa-info-circle"></i> <span>يتم تطبيق الحروف المتجانسة والفواصل الصفرية لحماية منشورك.</span></span>
</div>
</div>
<div class="d0uttwsjz2" style="flex: 1; margin: 0; display: flex; flex-direction: column;">
<label style="font-weight: 700; margin-bottom: 4px; font-size: 11.5px;"><i class="fa-solid fa-message"></i> <span>محتوى المنشور الأصلي:</span></label>
<textarea id="tfurtfdsqf" class="f0ngq4vbzj" style="flex: 1; height: 130px; min-height: 100px;" placeholder="اكتب نص منشورك هنا... جرب استخدام الأقواس مثل: {عرض خاص|خصم كبير} والمتغيرات مثل {{USER_NAME}} أو {{USER_PHONE}} أو {{WA_LINK}}..."></textarea>
</div>
<!-- أشرطة إدراج المتغيرات السريعة -->
<div style="display: flex; gap: 4px; flex-wrap: wrap; align-items: center; border: 1px solid var(--border); padding: 6px 8px; border-radius: var(--radius-md); background: var(--bg-subtle);">
<span style="font-size: 10px; font-weight: 700; color: var(--text-muted);"><i class="fa-solid fa-plus-circle"></i> <span>المتغيرات:</span></span>
<button type="button" class="ipxi2jz4g0 ynnugi2j1w" data-var="{{USER_NAME}}" style="padding: 2px 6px; font-size: 9.5px; height: auto; font-weight: 700;"><i class="fa-solid fa-user"></i> <span>الاسم</span></button>
<button type="button" class="ipxi2jz4g0 ynnugi2j1w" data-var="{{USER_PHONE}}" style="padding: 2px 6px; font-size: 9.5px; height: auto; font-weight: 700;"><i class="fa-solid fa-phone"></i> <span>الموبايل</span></button>
<button type="button" class="ipxi2jz4g0 ynnugi2j1w" data-var="{{WA_LINK}}" style="padding: 2px 6px; font-size: 9.5px; height: auto; font-weight: 700;"><i class="fa-brands fa-whatsapp"></i> <span>رابط الواتساب</span></button>
<button type="button" class="ipxi2jz4g0 ynnugi2j1w" data-var="{{RAN_T(5)}}" style="padding: 2px 6px; font-size: 9.5px; height: auto;"><i class="fa-solid fa-font"></i> <span>نص عشوائي</span></button>
<button type="button" class="ipxi2jz4g0 ynnugi2j1w" data-var="{{RAN_D(6)}}" style="padding: 2px 6px; font-size: 9.5px; height: auto;"><i class="fa-solid fa-hashtag"></i> <span>أرقام</span></button>
<button type="button" class="ipxi2jz4g0 ynnugi2j1w" data-var="{{GROUP_NAME}}" style="padding: 2px 6px; font-size: 9.5px; height: auto;"><i class="fa-solid fa-users"></i> <span>اسم الجروب</span></button>
</div>
<div style="display: grid; grid-template-columns: 2fr 1fr; gap: 8px; align-items: center;">
<div class="d0uttwsjz2" style="margin: 0;">
<label style="font-weight: 700; font-size: 11px;"><i class="fa-solid fa-font"></i> <span>النص البديل (احتياطي):</span></label>
<input type="text" id="ttzd830v71" class="xy26ymifmf" style="padding: 6px 10px;" placeholder="اكتب النص البديل هنا...">
</div>
<div class="d0uttwsjz2" style="margin: 0;">
<label style="font-weight: 700; font-size: 11px;"><i class="fa-solid fa-arrow-up-9-1"></i> <span>الأولوية (1-100):</span></label>
<input type="number" id="dpfsbbscb8" value="50" min="1" max="100" class="xy26ymifmf" style="padding: 6px 8px; text-align: center; font-weight: 700;">
</div>
</div>
</div>
<!-- العمود الثاني: إعدادات النشر ومتابعات الواتساب -->
<div class="d5tp7way8h" style="height: 100%; display: flex; flex-direction: column; gap: 10px; margin: 0; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--bg-card); box-sizing: border-box;">
<div class="cm41ch7urz" style="margin-bottom: 2px; font-size: 13px;">
<span><i class="fa-solid fa-gears" style="color: var(--primary);"></i> <span>إعدادات الفلاتر ومواعيد النشر</span></span>
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 8px;">
<div class="d0uttwsjz2" style="margin: 0;">
<label style="font-weight: 700; font-size: 11px;"><i class="fa-solid fa-circle-info"></i> <span>حالة المنشور:</span></label>
<select id="gc2figac9w" class="x7fmsajit7" style="padding: 7px 8px; font-size: 11px;">
<option value="active" selected>نشط ومتاح في التدوير</option>
<option value="inactive">معطل مؤقتاً ومستبعد</option>
<option value="frozen">مجمد أو منتهي الصلاحية</option>
<option value="draft">مسودة غير منشورة</option>
</select>
</div>
<div class="d0uttwsjz2" style="margin: 0;">
<label style="font-weight: 700; font-size: 11px;"><i class="fa-solid fa-sticky-note"></i> <span>ملاحظات داخلية:</span></label>
<input type="text" id="sdpu7v53bc" class="xy26ymifmf" style="padding: 7px 8px; font-size: 11px;" placeholder="اكتب ملاحظة...">
</div>
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 8px 10px; border-radius: var(--radius-md); border: 1px solid var(--border); background: var(--bg-subtle);">
<div class="d0uttwsjz2" style="margin: 0;">
<label style="font-size: 10px; font-weight: 700;"><i class="fa-solid fa-calendar-check"></i> <span>بدء التفعيل:</span></label>
<input type="datetime-local" id="nxkipeaxy3" class="xy26ymifmf" style="padding: 4px 6px; font-size: 10.5px;">
</div>
<div class="d0uttwsjz2" style="margin: 0;">
<label style="font-size: 10px; font-weight: 700;"><i class="fa-solid fa-calendar-xmark"></i> <span>انتهاء الصلاحية:</span></label>
<input type="datetime-local" id="zze2ahziau" class="xy26ymifmf" style="padding: 4px 6px; font-size: 10.5px;">
</div>
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 8px;">
<div class="d0uttwsjz2" style="margin: 0;">
<label style="font-weight: 700; font-size: 11px;"><i class="fa-solid fa-key"></i> <span>الكلمات المفتاحية:</span></label>
<input type="text" id="tqyy6isz9h" class="xy26ymifmf" style="padding: 7px 8px; font-size: 11px;" placeholder="عروض، عقارات">
</div>
<div class="d0uttwsjz2" style="margin: 0;">
<label style="font-weight: 700; font-size: 11px;"><i class="fa-solid fa-tags"></i> <span>التصنيفات:</span></label>
<input type="text" id="fk1p2nd322" class="xy26ymifmf" style="padding: 7px 8px; font-size: 11px;" placeholder="عقارات_الصيف">
</div>
</div>
<!-- صندوق رسالة المتابعة التلقائية لواتساب -->
<div style="border: 1px solid var(--border); border-radius: var(--radius-md); padding: 10px; display: flex; flex-direction: column; gap: 6px; margin-top: auto; background: var(--bg-subtle);">
<div class="mkxtd1c1kq" style="padding: 6px 10px; margin: 0; min-height: 32px;">
<input type="checkbox" id="zjibwdxt0e" style="width:16px; height:16px; cursor: pointer; accent-color: var(--wa-brand);">
<label for="zjibwdxt0e" style="font-weight: 700; cursor: pointer; font-size: 11px; margin: 0; display: flex; align-items: center; gap: 5px;">
<i class="fa-brands fa-whatsapp" style="color: var(--wa-brand);"></i> <span>ربط رسالة متابعة تلقائية للعملاء على واتساب</span>
</label>
</div>
<div id="p1fp7t08yw" style="display: flex; flex-direction: column; gap: 6px;">
<div class="d0uttwsjz2" style="margin: 0;">
<label style="font-size: 10px;"><i class="fa-solid fa-phone"></i> <span>أرقام الموبايل (افصل بفاصلة):</span></label>
<input type="text" id="n49dyh07qe" class="xy26ymifmf" style="padding: 5px 8px; font-size: 10.5px;" placeholder="+201069794840, +201096896689">
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 6px;">
<div class="d0uttwsjz2" style="margin: 0;">
<label style="font-size: 10px;"><i class="fa-solid fa-user"></i> <span>اسم العميل:</span></label>
<input type="text" id="shwl4dswr3" class="xy26ymifmf" style="padding: 5px 8px; font-size: 10.5px;" placeholder="أحمد">
</div>
<div class="d0uttwsjz2" style="margin: 0;">
<label style="font-size: 10px;"><i class="fa-solid fa-clock"></i> <span>تاريخ ووقت المتابعة:</span></label>
<input type="datetime-local" id="zzb32zuqfq" class="xy26ymifmf" style="padding: 4px 6px; font-size: 10.5px;">
</div>
</div>
</div>
<div class="d0uttwsjz2" style="margin: 0;">
<label style="font-size: 10px;"><i class="fa-solid fa-message"></i> <span>نص رسالة المتابعة:</span></label>
<textarea id="smpimntnov" class="f0ngq4vbzj" style="height: 50px; min-height: 40px; font-size: 11px; padding: 6px 8px;" placeholder="أهلاً {name}، نتابع مع حضرتك بخصوص طلبك..."></textarea>
</div>
<div style="display: flex; gap: 4px; flex-wrap: wrap;">
<button type="button" class="ipxi2jz4g0 nura0m8mnt" data-tag="{name}" style="padding: 2px 6px; font-size: 9.5px; height: auto; min-height: 24px; font-weight: 700;">
<i class="fa-solid fa-user"></i> <span>اسم العميل</span>
</button>
<button type="button" class="ipxi2jz4g0 nura0m8mnt" data-tag="{post_links}" style="padding: 2px 6px; font-size: 9.5px; height: auto; min-height: 24px; font-weight: 700;">
<i class="fa-solid fa-link"></i> <span>روابط المنشورات</span>
</button>
</div>
<div id="w8qjr35f9v" style="background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px; display: flex; flex-direction: column; gap: 4px;">
<span style="font-size: 9.5px; font-weight: 700;"><i class="fa-solid fa-gears"></i> <span>إعدادات الروابط المضمنة:</span></span>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 4px; align-items: center;">
<div class="d0uttwsjz2" style="margin: 0;">
<select id="p4ill70byo" class="x7fmsajit7" style="padding: 3px 6px; font-size: 9.5px; width: 100%;">
<option value="all" selected>إرسال كافة الروابط</option>
<option value="limit">إرسال عدد محدد</option>
</select>
</div>
<div class="d0uttwsjz2" style="margin: 0; display: none;" id="fa3hnmyxvu">
<input type="number" id="qibeji3kih" class="xy26ymifmf" style="padding: 3px 6px; font-size: 9.5px; text-align: center;" min="1" value="5">
</div>
</div>
<div class="d0uttwsjz2" style="margin: 0;">
<select id="hgi4sk486r" class="x7fmsajit7" style="padding: 3px 6px; font-size: 9.5px; width: 100%;">
<option value="ordered" selected>بالترتيب الزمني</option>
<option value="random">توزيع عشوائي</option>
</select>
</div>
</div>
<div id="tbgxlx0ini" style="background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px; display: flex; flex-direction: column; gap: 4px;">
<span style="font-size: 9.5px; font-weight: 700;"><i class="fa-solid fa-arrows-spin"></i> <span>جدولة التكرار التلقائي:</span></span>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 4px; align-items: center;">
<div class="d0uttwsjz2" style="margin: 0;">
<select id="x0tn0hlktk" class="x7fmsajit7" style="padding: 3px 6px; font-size: 9.5px; width: 100%;">
<option value="none" selected>مرة واحدة فقط</option>
<option value="1-day">تكرار بعد يوم (24 ساعة)</option>
<option value="7-days">تكرار بعد أسبوع (7 أيام)</option>
<option value="30-days">تكرار بعد شهر (30 يوماً)</option>
<option value="custom-days">تكرار بعد أيام مخصصة</option>
</select>
</div>
<div class="d0uttwsjz2" style="margin: 0; display: none;" id="oagpt02897">
<input type="number" id="x4me28ma8a" class="xy26ymifmf" style="padding: 3px 6px; font-size: 9.5px; text-align: center;" min="1" value="3">
</div>
</div>
</div>
</div>
</div>
</div>
<!-- منطقة إرفاق الصور والوسائط -->
<div class="d5tp7way8h" style="margin-bottom: 0; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--bg-subtle);">
<div class="cm41ch7urz" style="margin-bottom: 6px; font-size: 12px;">
<span><i class="fa-solid fa-photo-film" style="color: var(--primary);"></i> <span>إرفاق صور أو فيديوهات للمنشور:</span></span>
</div>
<div class="jbhynmzpf2" id="tr3maazuat" style="padding: 16px;">
<span><i class="fa-solid fa-cloud-arrow-up fa-2x" style="color: var(--primary); margin-bottom: 4px;"></i></span>
<span style="font-size: 11px;">اسحب وأفلت الصور والفيديوهات هنا أو اضغط للاختيار من جهازك...</span>
<input type="file" id="hrl56oubz6" multiple accept="image/*" style="display: none;">
</div>
<div class="dlk0zpo39e" id="utw9am60j7" style="margin-top: 8px;"></div>
</div>
<div style="display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px;">
<button id="fpvai7vrns" class="itdnt14mss" style="padding: 10px 24px; font-size: 12.5px; font-weight: 800; background: #0d9488; border-color: #0d9488;">
<i class="fa-solid fa-floppy-disk"></i> <span>حفظ وتخزين المنشور في المكتبة</span>
</button>
</div>
</div>
</div>
`;
document.body.appendChild(modal);
document.getElementById('anctu5etze').onclick = () => {
modal.style.display = 'none';
};
const submitBtn = document.getElementById('fpvai7vrns');
if (submitBtn) submitBtn.onclick = handleAddNewRotationPost;
};
/**
* بناء نافذة تعديل منشور محفوظ بالـ DOM
*/
const appendEditModalLayout = () => {
let modal = document.getElementById('a8jzwb130u');
if (modal) return;
modal = document.createElement('div');
modal.className = 'cpzxome5dd';
modal.id = 'a8jzwb130u';
modal.style.cssText = 'position: fixed; top: 0; left: 0; width: 100%; height: 100%; backdrop-filter: blur(8px); display: none; align-items: center; justify-content: center; z-index: var(--z-modal-backdrop); background-color: rgba(15, 23, 42, 0.65); direction: rtl; text-align: right; box-sizing: border-box;';
modal.innerHTML = `
<div class="s4yvtq9394" style="max-width: min(960px, 95vw); max-height: min(92vh, 900px); border-radius: var(--radius-xl); border: 1px solid var(--border); box-shadow: var(--shadow-modal); background: var(--bg-card);">
<div class="x8pdlyq70a" style="border-bottom: 1px solid var(--border); padding: 14px 20px; display: flex; justify-content: space-between; align-items: center; background: var(--bg-subtle);">
<div class="tooau3ykdi" style="font-weight: 800; font-size: 14px; display: flex; align-items: center; gap: 8px;">
<i class="fa-solid fa-pen-to-square" style="color: #0d9488;"></i>
<span>تعديل المنشور وإعدادات التدوير</span>
</div>
<button class="bcuz086hu4" id="hvsir9fpzq">&times;</button>
</div>
<div class="zn6t0dl6ke" style="max-height: 80vh; overflow-y: auto; padding: clamp(14px, 1.6vw, 22px); gap: var(--space-md);">
<input type="hidden" id="f0e140ihx2">
<div class="xd506q5mar" style="display: grid; grid-template-columns: repeat(auto-fit, minmax(clamp(280px, 30vw, 1fr), 1fr)); gap: 12px; margin-bottom: 0;">
<!-- العمود الأول: نص المنشور -->
<div class="d5tp7way8h" style="height: 100%; display: flex; flex-direction: column; gap: 10px; margin: 0; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--bg-card); box-sizing: border-box;">
<div class="cm41ch7urz" style="margin-bottom: 2px; font-size: 13px;">
<span><i class="fa-solid fa-file-pen" style="color: var(--primary);"></i> <span>محتوى ونص المنشور</span></span>
</div>
<div class="d0uttwsjz2" style="margin: 0;">
<label style="font-weight: 700; font-size: 11.5px;"><i class="fa-solid fa-heading"></i> <span>اسم أو عنوان المنشور للتوضيح:</span></label>
<input type="text" id="sf07blbqj5" class="xy26ymifmf">
</div>
<div class="suxidgikgm" style="margin-bottom: 0;">
<div class="dcaynff6el" style="margin-bottom: 4px;">
<span class="ipbz1xlmff" style="font-size: 11px; font-weight: 700;"><i class="fa-solid fa-wand-magic-sparkles" style="color: #8b5cf6;"></i> <span>محرك فحص الـ Spintax</span></span>
<div style="display: flex; gap: 4px;">
<button type="button" id="pcam8x7wdq" class="ipxi2jz4g0" style="padding: 3px 8px; font-size: 10px; height: auto;"><i class="fa-solid fa-mask"></i> <span>معاينة التمويه</span></button>
</div>
</div>
<div id="c2motxakmm" style="display:none; margin-top: 8px; padding: 10px; border: 1px dashed var(--border-strong); border-radius: var(--radius-md); font-size: 11px; direction: rtl; text-align: right; background: var(--bg-subtle);">
<strong style="display: block; margin-bottom: 4px; color: var(--text-main);"><i class="fa-solid fa-eye"></i> <span>النص بعد التمويه وحقن البيانات الحقيقية:</span></strong>
<div id="nmt96brzmq" style="white-space: pre-wrap; color: var(--text-secondary); background: var(--bg-card); padding: 8px 10px; border-radius: var(--radius-sm); border: 1px solid var(--border); max-height: 100px; overflow-y: auto; font-size: 11.5px; line-height: 1.5;"></div>
</div>
</div>
<div class="d0uttwsjz2" style="flex: 1; margin: 0; display: flex; flex-direction: column;">
<label style="font-weight: 700; margin-bottom: 4px; font-size: 11.5px;"><i class="fa-solid fa-message"></i> <span>محتوى المنشور الأصلي:</span></label>
<textarea id="y6sf67114z" class="f0ngq4vbzj" style="flex: 1; height: 130px; min-height: 100px;"></textarea>
</div>
<!-- أشرطة إدراج المتغيرات السريعة -->
<div style="display: flex; gap: 4px; flex-wrap: wrap; align-items: center; border: 1px solid var(--border); padding: 6px 8px; border-radius: var(--radius-md); background: var(--bg-subtle);">
<span style="font-size: 10px; font-weight: 700; color: var(--text-muted);"><i class="fa-solid fa-plus-circle"></i> <span>المتغيرات:</span></span>
<button type="button" class="ipxi2jz4g0 ynnugi2j1w" data-var="{{USER_NAME}}" style="padding: 2px 6px; font-size: 9.5px; height: auto; font-weight: 700;"><i class="fa-solid fa-user"></i> <span>الاسم</span></button>
<button type="button" class="ipxi2jz4g0 ynnugi2j1w" data-var="{{USER_PHONE}}" style="padding: 2px 6px; font-size: 9.5px; height: auto; font-weight: 700;"><i class="fa-solid fa-phone"></i> <span>الموبايل</span></button>
<button type="button" class="ipxi2jz4g0 ynnugi2j1w" data-var="{{WA_LINK}}" style="padding: 2px 6px; font-size: 9.5px; height: auto; font-weight: 700;"><i class="fa-brands fa-whatsapp"></i> <span>رابط الواتساب</span></button>
<button type="button" class="ipxi2jz4g0 ynnugi2j1w" data-var="{{RAN_T(5)}}" style="padding: 2px 6px; font-size: 9.5px; height: auto;"><i class="fa-solid fa-font"></i> <span>نص عشوائي</span></button>
<button type="button" class="ipxi2jz4g0 ynnugi2j1w" data-var="{{RAN_D(6)}}" style="padding: 2px 6px; font-size: 9.5px; height: auto;"><i class="fa-solid fa-hashtag"></i> <span>أرقام</span></button>
<button type="button" class="ipxi2jz4g0 ynnugi2j1w" data-var="{{GROUP_NAME}}" style="padding: 2px 6px; font-size: 9.5px; height: auto;"><i class="fa-solid fa-users"></i> <span>اسم الجروب</span></button>
</div>
<div style="display: grid; grid-template-columns: 2fr 1fr; gap: 8px; align-items: center;">
<div class="d0uttwsjz2" style="margin: 0;">
<label style="font-weight: 700; font-size: 11px;"><i class="fa-solid fa-font"></i> <span>النص البديل (احتياطي):</span></label>
<input type="text" id="nj5384jl5c" class="xy26ymifmf" style="padding: 6px 10px;">
</div>
<div class="d0uttwsjz2" style="margin: 0;">
<label style="font-weight: 700; font-size: 11px;"><i class="fa-solid fa-arrow-up-9-1"></i> <span>الأولوية (1-100):</span></label>
<input type="number" id="d1w0s2kv3v" class="xy26ymifmf" min="1" max="100" style="padding: 6px 8px; text-align: center; font-weight: 700;">
</div>
</div>
</div>
<!-- العمود الثاني: الإعدادات والمتابعة المجدولة -->
<div class="d5tp7way8h" style="height: 100%; display: flex; flex-direction: column; gap: 10px; margin: 0; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--bg-card); box-sizing: border-box;">
<div class="cm41ch7urz" style="margin-bottom: 2px; font-size: 13px;">
<span><i class="fa-solid fa-gears" style="color: var(--primary);"></i> <span>إعدادات الفلاتر ومواعيد النشر</span></span>
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 8px;">
<div class="d0uttwsjz2" style="margin: 0;">
<label style="font-weight: 700; font-size: 11px;"><i class="fa-solid fa-circle-info"></i> <span>حالة المنشور:</span></label>
<select id="texys3w2lv" class="x7fmsajit7" style="padding: 7px 8px; font-size: 11px;">
<option value="active">نشط ومتاح في التدوير</option>
<option value="inactive">معطل مؤقتاً ومستبعد</option>
<option value="frozen">مجمد أو منتهي الصلاحية</option>
<option value="draft">مسودة غير منشورة</option>
</select>
</div>
<div class="d0uttwsjz2" style="margin: 0;">
<label style="font-weight: 700; font-size: 11px;"><i class="fa-solid fa-sticky-note"></i> <span>ملاحظات داخلية:</span></label>
<input type="text" id="fkrgoi078q" class="xy26ymifmf" style="padding: 7px 8px; font-size: 11px;">
</div>
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 8px 10px; border-radius: var(--radius-md); border: 1px solid var(--border); background: var(--bg-subtle);">
<div class="d0uttwsjz2" style="margin: 0;">
<label style="font-size: 10px; font-weight: 700;"><i class="fa-solid fa-calendar-check"></i> <span>بدء التفعيل:</span></label>
<input type="datetime-local" id="hnits5ebb5" class="xy26ymifmf" style="padding: 4px 6px; font-size: 10.5px;">
</div>
<div class="d0uttwsjz2" style="margin: 0;">
<label style="font-size: 10px; font-weight: 700;"><i class="fa-solid fa-calendar-xmark"></i> <span>انتهاء الصلاحية:</span></label>
<input type="datetime-local" id="grp82kp5ee" class="xy26ymifmf" style="padding: 4px 6px; font-size: 10.5px;">
</div>
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 8px;">
<div class="d0uttwsjz2" style="margin: 0;">
<label style="font-weight: 700; font-size: 11px;"><i class="fa-solid fa-key"></i> <span>الكلمات المفتاحية:</span></label>
<input type="text" id="n2qgtkpju3" class="xy26ymifmf" style="padding: 7px 8px; font-size: 11px;">
</div>
<div class="d0uttwsjz2" style="margin: 0;">
<label style="font-weight: 700; font-size: 11px;"><i class="fa-solid fa-tags"></i> <span>التصنيفات:</span></label>
<input type="text" id="xbks261mca" class="xy26ymifmf" style="padding: 7px 8px; font-size: 11px;">
</div>
</div>
<!-- صندوق المتابعة المجدولة في نافذة التعديل -->
<div style="border: 1px solid var(--border); border-radius: var(--radius-md); padding: 10px; display: flex; flex-direction: column; gap: 6px; margin-top: auto; background: var(--bg-subtle);">
<div class="mkxtd1c1kq" style="padding: 6px 10px; margin: 0; min-height: 32px;">
<input type="checkbox" id="jgtj1u98h0" style="width:16px; height:16px; cursor: pointer; accent-color: var(--wa-brand);">
<label for="jgtj1u98h0" style="font-weight: 700; cursor: pointer; font-size: 11px; margin: 0; display: flex; align-items: center; gap: 5px;">
<i class="fa-brands fa-whatsapp" style="color: var(--wa-brand);"></i> <span>ربط رسالة متابعة تلقائية للعملاء على واتساب</span>
</label>
</div>
<div style="display: flex; flex-direction: column; gap: 6px;">
<div class="d0uttwsjz2" style="margin: 0;">
<label style="font-size: 10px;"><i class="fa-solid fa-phone"></i> <span>أرقام الموبايل (افصل بفاصلة):</span></label>
<input type="text" id="qu2fksgv9h" class="xy26ymifmf" style="padding: 5px 8px; font-size: 10.5px;">
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 6px;">
<div class="d0uttwsjz2" style="margin: 0;">
<label style="font-size: 10px;"><i class="fa-solid fa-user"></i> <span>اسم العميل:</span></label>
<input type="text" id="swzbu11pzw" class="xy26ymifmf" style="padding: 5px 8px; font-size: 10.5px;">
</div>
<div class="d0uttwsjz2" style="margin: 0;">
<label style="font-size: 10px;"><i class="fa-solid fa-clock"></i> <span>تاريخ ووقت المتابعة:</span></label>
<input type="datetime-local" id="tbruewdovo" class="xy26ymifmf" style="padding: 4px 6px; font-size: 10.5px;">
</div>
</div>
</div>
<div class="d0uttwsjz2" style="margin: 0;">
<label style="font-size: 10px;"><i class="fa-solid fa-message"></i> <span>نص رسالة المتابعة:</span></label>
<textarea id="q9xi99sflx" class="xy26ymifmf" style="height: 50px; min-height: 40px; font-size: 11px; padding: 6px 8px;"></textarea>
</div>
<div style="display: flex; gap: 4px; flex-wrap: wrap;">
<button type="button" class="ipxi2jz4g0 x8g5p7tdh7" data-tag="{name}" style="padding: 2px 6px; font-size: 9.5px; height: auto; min-height: 24px; font-weight: 700;">
<i class="fa-solid fa-user"></i> <span>اسم العميل</span>
</button>
<button type="button" class="ipxi2jz4g0 x8g5p7tdh7" data-tag="{post_links}" style="padding: 2px 6px; font-size: 9.5px; height: auto; min-height: 24px; font-weight: 700;">
<i class="fa-solid fa-link"></i> <span>روابط المنشورات</span>
</button>
</div>
<div id="o96s3y72ab" style="background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px; display: flex; flex-direction: column; gap: 4px;">
<span style="font-size: 9.5px; font-weight: 700;"><i class="fa-solid fa-gears"></i> <span>إعدادات الروابط المضمنة:</span></span>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 4px; align-items: center;">
<div class="d0uttwsjz2" style="margin: 0;">
<select id="lsia7sxo1z" class="x7fmsajit7" style="padding: 3px 6px; font-size: 9.5px; width: 100%;">
<option value="all" selected>إرسال كافة الروابط</option>
<option value="limit">إرسال عدد محدد</option>
</select>
</div>
<div class="d0uttwsjz2" style="margin: 0; display: none;" id="cje296b5w0">
<input type="number" id="q4ft603tog" class="xy26ymifmf" style="padding: 3px 6px; font-size: 9.5px; text-align: center;" min="1" value="5">
</div>
</div>
<div class="d0uttwsjz2" style="margin: 0;">
<select id="jmue92xc4j" class="x7fmsajit7" style="padding: 3px 6px; font-size: 9.5px; width: 100%;">
<option value="ordered" selected>بالترتيب الزمني</option>
<option value="random">توزيع عشوائي</option>
</select>
</div>
</div>
<div id="nnwvpb9xvi" style="background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px; display: flex; flex-direction: column; gap: 4px;">
<span style="font-size: 9.5px; font-weight: 700;"><i class="fa-solid fa-arrows-spin"></i> <span>جدولة التكرار التلقائي:</span></span>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 4px; align-items: center;">
<div class="d0uttwsjz2" style="margin: 0;">
<select id="twsjw36541" class="x7fmsajit7" style="padding: 3px 6px; font-size: 9.5px; width: 100%;">
<option value="none" selected>مرة واحدة فقط</option>
<option value="1-day">تكرار بعد يوم (24 ساعة)</option>
<option value="7-days">تكرار بعد أسبوع (7 أيام)</option>
<option value="30-days">تكرار بعد شهر (30 يوماً)</option>
<option value="custom-days">تكرار بعد أيام مخصصة</option>
</select>
</div>
<div class="d0uttwsjz2" style="margin: 0; display: none;" id="tcc6p8xt6o">
<input type="number" id="s1f8knupy0" class="xy26ymifmf" style="padding: 3px 6px; font-size: 9.5px; text-align: center;" min="1" value="3">
</div>
</div>
</div>
</div>
</div>
</div>
<!-- منطقة إرفاق الصور والوسائط في نافذة التعديل -->
<div class="d0uttwsjz2" style="margin-top: 4px; border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 12px; background: var(--bg-subtle);">
<label style="font-weight: 700; font-size: 11.5px;"><i class="fa-solid fa-images" style="color: var(--primary);"></i> <span>إرفاق صور أو فيديوهات للمنشور:</span></label>
<div class="jbhynmzpf2" id="jzc6fmhhs8" style="padding: 16px;">
<span><i class="fa-solid fa-cloud-arrow-up fa-2x" style="color: var(--primary); margin-bottom: 4px;"></i></span>
<span style="font-size: 11px;">اسحب وأفلت الصور والفيديوهات هنا أو اضغط للاختيار من جهازك...</span>
<input type="file" id="s0jxf1x6ev" multiple accept="image/*" style="display: none;">
</div>
<div class="dlk0zpo39e" id="rd6kwbqsvk" style="margin-top: 8px;"></div>
</div>
<button id="hlec9j3gwy" class="itdnt14mss" style="width: 100%; padding: 11px; margin-top: 8px; font-size: 12.5px; font-weight: 800; background: #0d9488; border-color: #0d9488;">
<i class="fa-solid fa-circle-check"></i> <span>حفظ وتوثيق التعديلات في المكتبة</span>
</button>
</div>
</div>
`;
document.body.appendChild(modal);
document.getElementById('hvsir9fpzq').onclick = () => {
modal.style.display = 'none';
};
const saveEditedBtn = document.getElementById('hlec9j3gwy');
if (saveEditedBtn) saveEditedBtn.onclick = saveEditedPreviousPost;
};
/**
* معالجة رفع وحفظ صور المنشور الجديد
*/
const handleAddPrevPostFiles = (files) => {
for (let i = 0; i < files.length; i++) {
const file = files[i];
if (file.size > 25 * 1024 * 1024) continue;
if (!file.type.startsWith('image/')) continue;
const reader = new FileReader();
reader.onload = async () => {
let compressedBlob = file;
let thumbBlob = file;
if (global.FritreeImageCompressor) {
compressedBlob = await global.FritreeImageCompressor.compressImage(file);
thumbBlob = await global.FritreeImageCompressor.generateThumbnail(compressedBlob);
}
const binaryHash = 'rot_media_add_' + Date.now() + "_" + Math.random().toString(36).substr(2,4);
if (global.FritreeStorage) {
await global.FritreeStorage.set(`media_blob_${binaryHash}`, compressedBlob);
await global.FritreeStorage.set(`media_thumb_${binaryHash}`, thumbBlob);
}
state.addPrevPostMedia.push({
id: binaryHash,
type: "image/jpeg",
blob: compressedBlob,
thumbBlob: thumbBlob,
filename: file.name
});
renderAddPrevPostPreviews();
};
reader.readAsDataURL(file);
}
};
const renderAddPrevPostPreviews = () => {
const container = document.getElementById('utw9am60j7');
if (!container) return;
container.innerHTML = '';
for (let i = 0; i < state.addPrevPostMedia.length; i++) {
const media = state.addPrevPostMedia[i];
const box = document.createElement('div');
box.className = 'evr435qzb2';
box.style.cssText = 'width: 76px; height: 76px; border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; position: relative; display: inline-block;';
const el = document.createElement('img');
const previewUrl = URL.createObjectURL(media.thumbBlob || media.blob);
el.src = previewUrl;
box.dataset.objurl = previewUrl;
el.style.cssText = 'width: 100%; height: 100%; object-fit: cover;';
const closeBtn = document.createElement('button');
closeBtn.setAttribute('type', 'button');
closeBtn.style.cssText = 'position: absolute; top: 4px; left: 4px; background: rgba(239, 68, 68, 0.85); color: #fff; border: none; border-radius: 50%; width: 22px; height: 22px; font-size: 10px; cursor: pointer; display: flex; align-items: center; justify-content: center;';
closeBtn.innerHTML = '<i class="fa-solid fa-xmark"></i> ';
closeBtn.onclick = () => {
if (box.dataset.objurl) URL.revokeObjectURL(box.dataset.objurl);
if (global.FritreeStorage) {
global.FritreeStorage.remove(`media_blob_${media.id}`);
global.FritreeStorage.remove(`media_thumb_${media.id}`);
}
state.addPrevPostMedia.splice(i, 1);
renderAddPrevPostPreviews();
};
box.appendChild(el);
box.appendChild(closeBtn);
container.appendChild(box);
}
};
/**
* حفظ المنشور الجديد في مكتبة التدوير والتخزين المشفر
*/
const handleAddNewRotationPost = async () => {
const titleVal = (document.getElementById('wlunjizubf')?.value || '').trim();
const textVal = document.getElementById('tfurtfdsqf')?.value || '';
const statusVal = document.getElementById('gc2figac9w')?.value || 'active';
const keywordsVal = document.getElementById('tqyy6isz9h')?.value || '';
const phonesVal = document.getElementById('n49dyh07qe')?.value || '';
const noteVal = (document.getElementById('sdpu7v53bc')?.value || '').trim();
const categoryVal = document.getElementById('fk1p2nd322')?.value || '';
const altTextVal = document.getElementById('ttzd830v71')?.value || '';
const priorityVal = parseInt(document.getElementById('dpfsbbscb8')?.value, 10) || 50;
const entryDateVal = document.getElementById('nxkipeaxy3')?.value || '';
const expireDateVal = document.getElementById('zze2ahziau')?.value || '';
const clientNameVal = (document.getElementById('shwl4dswr3')?.value || '').trim();
const enableWaFollowUp = document.getElementById('zjibwdxt0e')?.checked || false;
const followUpMessage = document.getElementById('smpimntnov')?.value || '';
const followUpDate = document.getElementById('zzb32zuqfq')?.value || '';
const followupLinksMode = document.getElementById('p4ill70byo')?.value || 'all';
const followupLinksCount = parseInt(document.getElementById('qibeji3kih')?.value, 10) || 5;
const followupLinksOrder = document.getElementById('hgi4sk486r')?.value || 'ordered';
const followupRecurrenceMode = document.getElementById('x0tn0hlktk')?.value || 'none';
const followupRecurrenceDays = parseInt(document.getElementById('x4me28ma8a')?.value, 10) || 3;
if (!textVal && state.addPrevPostMedia.length === 0) {
alert('لا يمكن حفظ منشور فارغ تماماً!');
return;
}
let keywordsArray = keywordsVal.split(',').map(s => s.trim().toLowerCase()).filter(s => s);
let categoryArray = categoryVal.split(',').map(s => s.trim()).filter(s => s);
if (categoryArray.length === 0 && keywordsArray.length === 0 && textVal) {
if (global.FritreeSimilarityService && typeof global.FritreeSimilarityService.autoClassify === 'function') {
const classified = global.FritreeSimilarityService.autoClassify(textVal);
categoryArray = classified.categories;
keywordsArray = classified.keywords;
}
}
const phonesArray = phonesVal.split(',').map(s => s.trim().replace(/[^0-9+]/g, '')).filter(s => s);
const newPost = {
id: 'rot_' + Date.now() + '_' + Math.random().toString(36).substr(2, 4),
title: titleVal || (textVal ? textVal.substring(0, 30) + '...' : 'أرشيف تدوير محفوظ'),
text: textVal,
altText: altTextVal,
priority: priorityVal,
mediaReferences: state.addPrevPostMedia.map(m => ({ id: m.id, type: m.type, filename: m.filename })),
status: statusVal,
keywords: keywordsArray,
categories: categoryArray,
notes: noteVal,
enableWaFollowUp: enableWaFollowUp,
clientName: clientNameVal,
phoneNumbers: phonesArray,
followUpDate: followUpDate,
followUpMessage: followUpMessage,
followupLinksMode: followupLinksMode,
followupLinksCount: followupLinksCount,
followupLinksOrder: followupLinksOrder,
followupRecurrenceMode: followupRecurrenceMode,
followupRecurrenceDays: followupRecurrenceDays,
entryDate: entryDateVal || new Date().toISOString(),
expireDate: expireDateVal,
followUpSent: false,
date: new Date().toISOString()
};
if (!Array.isArray(state.previousPostsData)) {
state.previousPostsData = [];
}
state.previousPostsData.unshift(newPost);
if (global.FritreeRotationStore && typeof global.FritreeRotationStore.save === 'function') {
global.FritreeRotationStore.recalculateScores();
await global.FritreeRotationStore.save();
}
if (global.FritreeRotation && typeof global.FritreeRotation.renderPreviousPostsGrid === 'function') {
global.FritreeRotation.renderPreviousPostsGrid();
}
// تفريغ حقول الإدخال
document.getElementById('wlunjizubf').value = '';
document.getElementById('tfurtfdsqf').value = '';
document.getElementById('tqyy6isz9h').value = '';
document.getElementById('n49dyh07qe').value = '';
document.getElementById('sdpu7v53bc').value = '';
document.getElementById('fk1p2nd322').value = '';
document.getElementById('nxkipeaxy3').value = '';
document.getElementById('zze2ahziau').value = '';
document.getElementById('shwl4dswr3').value = '';
document.getElementById('zjibwdxt0e').checked = false;
document.getElementById('smpimntnov').value = '';
document.getElementById('zzb32zuqfq').value = '';
document.getElementById('ttzd830v71').value = '';
document.getElementById('dpfsbbscb8').value = '50';
state.addPrevPostMedia = [];
const previewsContainer = document.getElementById('utw9am60j7');
if (previewsContainer) previewsContainer.innerHTML = '';
const addModal = document.getElementById('s74nhbmzs5');
if (addModal) addModal.style.display = 'none';
if (typeof window.addLog === 'function') {
window.addLog(`تم حفظ وتخزين المنشور بنجاح: "${newPost.title}".`, 'success');
}
};
/**
* فتح نافذة إنشاء المنشور الجديد
* @param {string} presetText
*/
const openAddPrevPostModal = (presetText = '') => {
appendAddModalLayout();
if (presetText) {
const txtArea = document.getElementById('tfurtfdsqf');
if (txtArea) txtArea.value = presetText;
}
const modal = document.getElementById('s74nhbmzs5');
if (modal) modal.style.display = 'flex';
};
/**
* فتح نافذة تعديل المنشور
* @param {string} id
*/
const openEditPrevPostModal = async (id) => {
const post = state.previousPostsData.find(p => p.id === id);
if (!post) return;
appendEditModalLayout();
document.getElementById('f0e140ihx2').value = post.id;
document.getElementById('sf07blbqj5').value = post.title || '';
document.getElementById('y6sf67114z').value = post.text || '';
document.getElementById('texys3w2lv').value = post.status || 'active';
document.getElementById('n2qgtkpju3').value = post.keywords ? post.keywords.join(', ') : '';
document.getElementById('qu2fksgv9h').value = post.phoneNumbers ? post.phoneNumbers.join(', ') : '';
document.getElementById('fkrgoi078q').value = post.notes || '';
document.getElementById('xbks261mca').value = post.categories ? post.categories.join(', ') : '';
document.getElementById('nj5384jl5c').value = post.altText || '';
document.getElementById('d1w0s2kv3v').value = post.priority !== undefined ? post.priority : 50;
document.getElementById('hnits5ebb5').value = post.entryDate ? post.entryDate.slice(0, 16) : '';
document.getElementById('grp82kp5ee').value = post.expireDate ? post.expireDate.slice(0, 16) : '';
document.getElementById('swzbu11pzw').value = post.clientName || '';
document.getElementById('jgtj1u98h0').checked = !!post.enableWaFollowUp;
document.getElementById('q9xi99sflx').value = post.followUpMessage || '';
document.getElementById('tbruewdovo').value = post.followUpDate ? post.followUpDate.slice(0, 16) : '';
const editLinksMode = post.followupLinksMode || 'all';
document.getElementById('lsia7sxo1z').value = editLinksMode;
document.getElementById('q4ft603tog').value = post.followupLinksCount || 5;
document.getElementById('jmue92xc4j').value = post.followupLinksOrder || 'ordered';
const editLinksWrapper = document.getElementById('cje296b5w0');
if (editLinksWrapper) editLinksWrapper.style.display = (editLinksMode === 'limit') ? 'block' : 'none';
const editRecMode = post.followupRecurrenceMode || 'none';
document.getElementById('twsjw36541').value = editRecMode;
document.getElementById('s1f8knupy0').value = post.followupRecurrenceDays || 3;
const editRecWrapper = document.getElementById('tcc6p8xt6o');
if (editRecWrapper) editRecWrapper.style.display = (editRecMode === 'custom-days') ? 'block' : 'none';
state.editPrevPostMedia = [];
if (post.mediaReferences && global.FritreeStorage) {
for (let i = 0; i < post.mediaReferences.length; i++) {
const ref = post.mediaReferences[i];
const rawBlob = await global.FritreeStorage.get(`media_blob_${ref.id}`);
const thumbBlob = await global.FritreeStorage.get(`media_thumb_${ref.id}`);
state.editPrevPostMedia.push({
id: ref.id,
type: ref.type,
blob: rawBlob,
thumbBlob: thumbBlob,
filename: ref.filename
});
}
}
renderEditPrevPostPreviews();
const modal = document.getElementById('a8jzwb130u');
if (modal) modal.style.display = 'flex';
};
/**
* معالجة رفع صور المنشور قيد التعديل
*/
const handleEditPrevPostFiles = (files) => {
for (let i = 0; i < files.length; i++) {
const file = files[i];
if (file.size > 25 * 1024 * 1024) continue;
if (!file.type.startsWith('image/')) continue;
const reader = new FileReader();
reader.onload = async () => {
let compressedBlob = file;
let thumbBlob = file;
if (global.FritreeImageCompressor) {
compressedBlob = await global.FritreeImageCompressor.compressImage(file);
thumbBlob = await global.FritreeImageCompressor.generateThumbnail(compressedBlob);
}
const binaryHash = 'rot_media_edit_' + Date.now() + "_" + Math.random().toString(36).substr(2,4);
if (global.FritreeStorage) {
await global.FritreeStorage.set(`media_blob_${binaryHash}`, compressedBlob);
await global.FritreeStorage.set(`media_thumb_${binaryHash}`, thumbBlob);
}
state.editPrevPostMedia.push({
id: binaryHash,
type: "image/jpeg",
blob: compressedBlob,
thumbBlob: thumbBlob,
filename: file.name
});
renderEditPrevPostPreviews();
};
reader.readAsDataURL(file);
}
};
const renderEditPrevPostPreviews = () => {
const container = document.getElementById('rd6kwbqsvk');
if (!container) return;
container.innerHTML = '';
for (let i = 0; i < state.editPrevPostMedia.length; i++) {
const media = state.editPrevPostMedia[i];
const box = document.createElement('div');
box.className = 'evr435qzb2';
box.style.cssText = 'width: 76px; height: 76px; border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; position: relative; display: inline-block;';
const el = document.createElement('img');
if (media.thumbBlob || media.blob) {
const previewUrl = URL.createObjectURL(media.thumbBlob || media.blob);
el.src = previewUrl;
box.dataset.objurl = previewUrl;
} else {
el.src = 'icon.png';
}
el.style.cssText = 'width: 100%; height: 100%; object-fit: cover;';
const closeBtn = document.createElement('button');
closeBtn.setAttribute('type', 'button');
closeBtn.style.cssText = 'position: absolute; top: 4px; left: 4px; background: rgba(239, 68, 68, 0.85); color: #fff; border: none; border-radius: 50%; width: 22px; height: 22px; font-size: 10px; cursor: pointer; display: flex; align-items: center; justify-content: center;';
closeBtn.innerHTML = '<i class="fa-solid fa-xmark"></i> ';
closeBtn.onclick = () => {
if (box.dataset.objurl) URL.revokeObjectURL(box.dataset.objurl);
if (global.FritreeStorage) {
global.FritreeStorage.remove(`media_blob_${media.id}`);
global.FritreeStorage.remove(`media_thumb_${media.id}`);
}
state.editPrevPostMedia.splice(i, 1);
renderEditPrevPostPreviews();
};
box.appendChild(el);
box.appendChild(closeBtn);
container.appendChild(box);
}
};
/**
* حفظ المنشور بعد التعديل
*/
const saveEditedPreviousPost = async () => {
const id = document.getElementById('f0e140ihx2')?.value;
const post = state.previousPostsData.find(p => p.id === id);
if (!post) return;
const titleVal = (document.getElementById('sf07blbqj5')?.value || '').trim();
const textVal = document.getElementById('y6sf67114z')?.value || '';
const statusVal = document.getElementById('texys3w2lv')?.value || 'active';
const keywordsVal = document.getElementById('n2qgtkpju3')?.value || '';
const phonesVal = document.getElementById('qu2fksgv9h')?.value || '';
const noteVal = (document.getElementById('fkrgoi078q')?.value || '').trim();
const categoryVal = document.getElementById('xbks261mca')?.value || '';
const entryDateVal = document.getElementById('hnits5ebb5')?.value || '';
const expireDateVal = document.getElementById('grp82kp5ee')?.value || '';
const clientNameVal = (document.getElementById('swzbu11pzw')?.value || '').trim();
const enableWaFollowUp = document.getElementById('jgtj1u98h0')?.checked || false;
const followUpMessage = document.getElementById('q9xi99sflx')?.value || '';
const followUpDate = document.getElementById('tbruewdovo')?.value || '';
const followupLinksMode = document.getElementById('lsia7sxo1z')?.value || 'all';
const followupLinksCount = parseInt(document.getElementById('q4ft603tog')?.value, 10) || 5;
const followupLinksOrder = document.getElementById('jmue92xc4j')?.value || 'ordered';
const followupRecurrenceMode = document.getElementById('twsjw36541')?.value || 'none';
const followupRecurrenceDays = parseInt(document.getElementById('s1f8knupy0')?.value, 10) || 3;
const altTextVal = document.getElementById('nj5384jl5c')?.value || '';
const priorityVal = parseInt(document.getElementById('d1w0s2kv3v')?.value, 10) || 50;
if (!textVal && state.editPrevPostMedia.length === 0) {
alert('لا يمكن حفظ منشور فارغ تماماً!');
return;
}
post.title = titleVal || (textVal ? textVal.substring(0, 30) + '...' : 'أرشيف تدوير محفوظ');
post.text = textVal;
post.altText = altTextVal;
post.priority = priorityVal;
post.mediaReferences = state.editPrevPostMedia.map(m => ({ id: m.id, type: m.type, filename: m.filename }));
post.status = statusVal;
post.keywords = keywordsVal.split(',').map(s => s.trim().toLowerCase()).filter(s => s);
post.categories = categoryVal.split(',').map(s => s.trim()).filter(s => s);
post.notes = noteVal;
post.enableWaFollowUp = enableWaFollowUp;
post.clientName = clientNameVal;
post.phoneNumbers = phonesVal.split(',').map(s => s.trim().replace(/[^0-9+]/g, '')).filter(s => s);
post.followUpDate = followUpDate;
post.followUpMessage = followUpMessage;
post.followupLinksMode = followupLinksMode;
post.followupLinksCount = followupLinksCount;
post.followupLinksOrder = followupLinksOrder;
post.followupRecurrenceMode = followupRecurrenceMode;
post.followupRecurrenceDays = followupRecurrenceDays;
post.entryDate = entryDateVal || post.entryDate || new Date().toISOString();
post.expireDate = expireDateVal;
if (global.FritreeRotationStore && typeof global.FritreeRotationStore.save === 'function') {
global.FritreeRotationStore.recalculateScores();
await global.FritreeRotationStore.save();
}
if (global.FritreeRotation && typeof global.FritreeRotation.renderPreviousPostsGrid === 'function') {
global.FritreeRotation.renderPreviousPostsGrid();
}
const modal = document.getElementById('a8jzwb130u');
if (modal) modal.style.display = 'none';
if (typeof window.addLog === 'function') {
window.addLog(`تم تحديث وحفظ المنشور بنجاح: "${post.title}".`, 'success');
}
};
/**
* ربط أحداث المحرر والنوافذ
*/
const bindCreatorEventListeners = () => {
appendAddModalLayout();
appendEditModalLayout();
// 1. أزرار فحص جودة الـ Spintax ومعاينة التمويه في نافذة الإضافة
const btnCheckQualityAdd = document.getElementById('ukgv00a6ew');
const qualityResultAdd = document.getElementById('pvd3acinzt');
const btnPreviewStealthAdd = document.getElementById('q1oy8rpm26');
const previewBoxWrapperAdd = document.getElementById('w2d0q5j0yl');
const previewTextBoxAdd = document.getElementById('p1yahnikb8');
if (btnCheckQualityAdd && qualityResultAdd) {
btnCheckQualityAdd.onclick = () => {
const text = document.getElementById('tfurtfdsqf')?.value || '';
if (global.FritreeSimilarityService && typeof global.FritreeSimilarityService.analyzeSpintax === 'function') {
const res = global.FritreeSimilarityService.analyzeSpintax(text);
if (res.valid) {
qualityResultAdd.innerHTML = `<span style="color:var(--success-hover);"><i class="fa-solid fa-circle-check"></i> صياغة الأقواس سليمة! المتغيرات المحسوبة: <strong>${res.variations.toLocaleString('en-US')}</strong> | الأمان: <strong>${res.safetyPct}%</strong></span>`;
} else {
qualityResultAdd.innerHTML = `<span style="color:var(--danger);"><i class="fa-solid fa-triangle-exclamation"></i> ${res.errors || 'خطأ في صياغة الأقواس'}</span>`;
}
}
};
}
if (btnPreviewStealthAdd && previewBoxWrapperAdd && previewTextBoxAdd) {
btnPreviewStealthAdd.onclick = async () => {
const text = document.getElementById('tfurtfdsqf')?.value || '';
if (!text) {
alert('اكتب نص المنشور أولاً لمعاينة التمويه!');
return;
}
if (previewBoxWrapperAdd.style.display === 'none') {
if (global.FritreeTextCompiler && typeof global.FritreeTextCompiler.compileAndObfuscate === 'function') {
const obfuscated = await global.FritreeTextCompiler.compileAndObfuscate(text, "جروب_التجربة");
previewTextBoxAdd.textContent = obfuscated;
previewBoxWrapperAdd.style.display = 'block';
}
} else {
previewBoxWrapperAdd.style.display = 'none';
}
};
}
// 2. زر معاينة التمويه في نافذة التعديل
const btnPreviewStealthEdit = document.getElementById('pcam8x7wdq');
const previewBoxWrapperEdit = document.getElementById('c2motxakmm');
const previewTextBoxEdit = document.getElementById('nmt96brzmq');
if (btnPreviewStealthEdit && previewBoxWrapperEdit && previewTextBoxEdit) {
btnPreviewStealthEdit.onclick = async () => {
const text = document.getElementById('y6sf67114z')?.value || '';
if (!text) {
alert('اكتب نص المنشور أولاً لمعاينة التمويه!');
return;
}
if (previewBoxWrapperEdit.style.display === 'none') {
if (global.FritreeTextCompiler && typeof global.FritreeTextCompiler.compileAndObfuscate === 'function') {
const obfuscated = await global.FritreeTextCompiler.compileAndObfuscate(text, "جروب_التجربة");
previewTextBoxEdit.textContent = obfuscated;
previewBoxWrapperEdit.style.display = 'block';
}
} else {
previewBoxWrapperEdit.style.display = 'none';
}
};
}
// 3. ربط أزرار إضافة المتغيرات
document.querySelectorAll('.ynnugi2j1w').forEach(btn => {
btn.onclick = (e) => {
const tag = e.currentTarget.getAttribute('data-var');
let targetTextarea = document.getElementById('tfurtfdsqf');
const editModal = document.getElementById('a8jzwb130u');
if (editModal && editModal.style.display === 'flex') {
targetTextarea = document.getElementById('y6sf67114z');
}
if (targetTextarea) {
const start = targetTextarea.selectionStart;
const end = targetTextarea.selectionEnd;
targetTextarea.value = targetTextarea.value.substring(0, start) + tag + targetTextarea.value.substring(end);
targetTextarea.focus();
targetTextarea.selectionEnd = start + tag.length;
}
};
});
// 4. ربط أزرار وسوم رسائل المتابعة
document.querySelectorAll('.nura0m8mnt, .x8g5p7tdh7').forEach(btn => {
btn.onclick = (e) => {
const tag = e.currentTarget.getAttribute('data-tag');
let targetTextarea = document.getElementById('smpimntnov');
const editModal = document.getElementById('a8jzwb130u');
if (editModal && editModal.style.display === 'flex') {
targetTextarea = document.getElementById('q9xi99sflx');
}
if (targetTextarea) {
const start = targetTextarea.selectionStart;
const end = targetTextarea.selectionEnd;
targetTextarea.value = targetTextarea.value.substring(0, start) + tag + targetTextarea.value.substring(end);
targetTextarea.focus();
targetTextarea.selectionEnd = start + tag.length;
}
};
});
// 5. ربط مناطق رفع الصور
const addDropzone = document.getElementById('tr3maazuat');
const addFileInput = document.getElementById('hrl56oubz6');
if (addDropzone && addFileInput) {
addDropzone.onclick = () => addFileInput.click();
addFileInput.onchange = (e) => { if (e.target.files.length > 0) handleAddPrevPostFiles(e.target.files); };
}
const editDropzone = document.getElementById('jzc6fmhhs8');
const editFileInput = document.getElementById('s0jxf1x6ev');
if (editDropzone && editFileInput) {
editDropzone.onclick = () => editFileInput.click();
editFileInput.onchange = (e) => { if (e.target.files.length > 0) handleEditPrevPostFiles(e.target.files); };
}
};
/**
* تهيئة وحدة تحكم إنشاء وتعديل المنشورات
*/
const initCreator = () => {
bindCreatorEventListeners();
return true;
};
global.FritreeRotationCreator = {
init: initCreator,
openAddModal: openAddPrevPostModal,
openEditModal: openEditPrevPostModal,
openEditGroupModal: (groupId = null, preselectedPostIds = []) => {
if (global.FritreeRotationGroups && typeof global.FritreeRotationGroups.openModal === 'function') {
global.FritreeRotationGroups.openModal(groupId, preselectedPostIds);
}
},
saveEditedPost: saveEditedPreviousPost
};
if (typeof document !== 'undefined') {
if (document.readyState === 'complete' || document.readyState === 'interactive') {
global.FritreeRotationCreator.init();
} else {
document.addEventListener('DOMContentLoaded', () => global.FritreeRotationCreator.init());
}
}
})(typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : this);