File size: 77,198 Bytes
cca0cf3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
/**

 * @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);