File size: 64,542 Bytes
fbfa6a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Advanced Component Builder</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&family=Open+Sans:wght@400;700&family=Lato:wght@400;700&family=Montserrat:wght@400;700&family=Poppins:wght@400;500;600;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
    <link rel="stylesheet" href="https://unpkg.com/swiper/swiper-bundle.min.css" />

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.0/FileSaver.min.js"></script>
    <style>
        :root {
            --primary-color: #3b82f6;
            --primary-hover-color: #2563eb;
            --secondary-color: #10b981;
            --secondary-hover-color: #059669;
            --text-color: #374151;
            --heading-color: #111827;
            --font-family: 'Inter', sans-serif;
        }

        body {
            font-family: var(--font-family);
            color: var(--text-color);
            background-color: var(--background-color);
        }
        h1, h2, h3, h4, h5, h6 {
            color: var(--heading-color);
        }
        /* Custom scrollbar for webkit browsers */
        ::-webkit-scrollbar {
            width: 8px;
            height: 8px;
        }
        ::-webkit-scrollbar-track {
            background: #f1f1f1;
        }
        ::-webkit-scrollbar-thumb {
            background: #888;
            border-radius: 10px;
        }
        ::-webkit-scrollbar-thumb:hover {
            background: #555;
        }
        .preview-iframe {
            width: 100%;
            height: 100%;
            border: 0;
            transition: all 0.3s ease-in-out;
        }
        #preview-container.preview-desktop .preview-iframe { width: 100%; }
        #preview-container.preview-tablet .preview-iframe { width: 768px; margin: 0 auto; }
        #preview-container.preview-mobile .preview-iframe { width: 375px; margin: 0 auto; }

        .toast {
            visibility: hidden;
            min-width: 250px;
            background-color: #333;
            color: #fff;
            text-align: center;
            border-radius: 8px;
            padding: 16px;
            position: fixed;
            z-index: 100;
            left: 50%;
            bottom: 30px;
            transform: translateX(-50%);
            opacity: 0;
            transition: opacity 0.3s, visibility 0.3s;
        }
        .toast.show {
            visibility: visible;
            opacity: 1;
        }
        
        /* Professional Controls UI Styles */
        #controls-layout {
            display: flex;
            height: 100%;
        }
        #controls-nav {
            width: 180px;
            flex-shrink: 0;
            background-color: #f8fafc;
            border-right: 1px solid #e5e7eb;
            padding: 0.5rem;
            overflow-y: auto;
        }
        .control-nav-button {
            display: flex;
            align-items: center;
            width: 100%;
            padding: 0.75rem;
            border-radius: 0.375rem;
            font-weight: 500;
            color: var(--text-color);
            transition: background-color 0.2s, color 0.2s;
            text-align: left;
        }
        .control-nav-button:hover {
            background-color: #e5e7eb;
        }
        .control-nav-button.active {
            background-color: var(--primary-color);
            color: white;
            box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
        }
        .control-nav-button i {
            margin-right: 0.75rem;
            width: 20px;
            text-align: center;
        }
        #controls-panels {
            flex-grow: 1;
            padding: 1.5rem;
            overflow-y: auto;
        }
        .control-panel {
            display: none;
        }
        .control-panel.active {
            display: block;
        }
        .control-panel h3 {
            font-size: 1.25rem;
            font-weight: 600;
            margin-bottom: 1.5rem;
            border-bottom: 1px solid #e5e7eb;
            padding-bottom: 0.75rem;
        }
        .control-panel h4 {
            font-size: 1rem;
            font-weight: 600;
            margin-top: 1.5rem;
            margin-bottom: 1rem;
            color: var(--heading-color);
        }
        .nested-builder {
             margin-left: 1rem;
            padding-left: 1rem;
            border-left: 2px solid #e5e7eb;
            margin-top: 1rem;
            padding-top: 1rem;
        }
        .item-toolbar {
            display: flex;
            justify-content: flex-end;
            gap: 0.25rem;
            margin-bottom: 0.5rem;
        }
        .item-toolbar button {
            line-height: 1;
        }
        .layout-item {
            cursor: move;
        }
        .code-modal-pre {
            background-color: #2d3748;
            color: #e2e8f0;
            padding: 1rem;
            border-radius: 0.375rem;
            max-height: 200px;
            overflow-y: auto;
            position: relative;
        }
        /* Feature: Hide/Show Sidebar */
        #controls-sidebar {
            flex-shrink: 0;
        }
        #main-container.sidebar-collapsed #controls-sidebar {
            width: 0;
            padding: 0;
            overflow: hidden;
        }
        #main-container.sidebar-collapsed #preview-main {
            width: 100%;
        }
        /* Component Control Specific Styles */
        .component-item-controls {
            background-color: #f9fafb;
            border: 1px solid #e5e7eb;
            padding: 0.75rem;
            border-radius: 0.375rem;
            margin-bottom: 0.5rem;
        }
    </style>
</head>
<body class="text-gray-800">

    <div id="app" class="flex flex-col h-screen">

        <header class="bg-white shadow-md p-4 flex justify-between items-center z-20">
             <div class="flex items-center space-x-3">
                <h1 class="text-xl font-bold text-gray-700">Component Builder</h1>
                <button id="toggle-sidebar-btn" class="p-2 rounded-md hover:bg-gray-200 text-gray-600" title="Hide Controls">
                     <i class="fas fa-chevron-left"></i>
                </button>
            </div>
            <div class="flex items-center space-x-4">
                
                <button id="import-btn" class="flex items-center space-x-2 bg-blue-600 text-white font-bold py-2 px-4 rounded-md hover:bg-blue-700 transition">
                    <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
                        <path d="M10 2a1 1 0 00-1 1v5.586l-1.293-1.293a1 1 0 00-1.414 1.414l3 3a1 1 0 001.414 0l3-3a1 1 0 00-1.414-1.414L11 8.586V3a1 1 0 00-1-1z"></path>
                        <path d="M4 14a1 1 0 011 1v1a1 1 0 001 1h8a1 1 0 001-1v-1a1 1 0 112 0v1a3 3 0 01-3 3H6a3 3 0 01-3-3v-1a1 1 0 011-1z"></path>
                    </svg>
                    <span>Import</span>
                </button>
                <input type="file" id="import-file-input" class="hidden" accept=".html">
                
                <div id="export-menu-container" class="relative">
                    <button id="export-menu-btn" class="flex items-center space-x-2 bg-green-600 text-white font-bold py-2 px-4 rounded-md hover:bg-green-700 transition">
                        <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M3 17a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM6.293 6.707a1 1 0 010-1.414l3-3a1 1 0 011.414 0l3 3a1 1 0 01-1.414 1.414L11 5.414V13a1 1 0 11-2 0V5.414L7.707 6.707a1 1 0 01-1.414 0z" clip-rule="evenodd"></path></svg>
                        <span>Export Page</span>
                    </button>
                    <div id="export-dropdown" class="hidden absolute right-0 mt-2 w-64 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5 z-30">
                        <div class="py-1" role="menu" aria-orientation="vertical" aria-labelledby="export-menu-btn">
                            <a href="#" id="copy-combined-code" class="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" role="menuitem">
                                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-3 text-gray-500" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"></path></svg>
                                <span>Copy Combined Code</span>
                            </a>
                            <a href="#" id="copy-html" class="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" role="menuitem">
                                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-3 text-gray-500" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path d="M5 5a2 2 0 012-2h10a2 2 0 012 2v1h-14V5zM3 8h18v10a2 2 0 01-2 2H5a2 2 0 01-2-2V8z"></path></svg>
                                <span>Copy Page HTML</span>
                            </a>
                             <a href="#" id="copy-css" class="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" role="menuitem">
                                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-3 text-gray-500" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 21a4 4 0 01-4-4V5a2 2 0 012-2h4a2 2 0 012 2v12a4 4 0 01-4 4zm0 0h12a2 2 0 002-2v-4a2 2 0 00-2-2h-2.343M11 7.343l1.657-1.657a2 2 0 012.828 0l2.829 2.829a2 2 0 010 2.828l-8.486 8.485M7 17h.01"></path></svg>
                                <span>Copy Page CSS</span>
                            </a>
                            <a href="#" id="copy-js" class="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" role="menuitem">
                                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-3 text-gray-500" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M10 2a1 1 0 011 1v1h1a1 1 0 010 2h-1v1a1 1 0 01-2 0V6H8a1 1 0 010-2h1V3a1 1 0 011-1zM5 5a3 3 0 013-3h4a3 3 0 013 3v1h-1V5a2 2 0 00-2-2H8a2 2 0 00-2 2v1H5V5zm2 5a1 1 0 011-1h4a1 1 0 110 2H8a1 1 0 01-1-1zm-1 4a1 1 0 100 2h8a1 1 0 100-2H6z" clip-rule="evenodd" /></svg>
                                <span>Copy Page JS</span>
                            </a>
                            <div class="border-t border-gray-100"></div>
                            <a href="#" id="download-zip-btn" class="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" role="menuitem">
                                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-3 text-gray-500" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M4 2a2 2 0 00-2 2v12a2 2 0 002 2h12a2 2 0 002-2V4a2 2 0 00-2-2H4zm1 3a1 1 0 000 2h10a1 1 0 100-2H5zM5 13a1 1 0 100 2h10a1 1 0 100-2H5z" clip-rule="evenodd"></path></svg>
                                <span>Download Page .zip</span>
                            </a>
                        </div>
                    </div>
                </div>

                <div class="flex items-center space-x-2">
                    <span class="text-sm font-medium text-gray-500">Preview:</span>
                    <button id="desktop-btn" class="p-2 rounded-md bg-blue-500 text-white shadow" title="Desktop View">
                        <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M10 2a2 2 0 00-2 2v1H6a2 2 0 00-2 2v7a2 2 0 002 2h8a2 2 0 002-2V7a2 2 0 00-2-2h-2V4a2 2 0 00-2-2zm-1 3V4a1 1 0 112 0v1h-2zM6 7v7h8V7H6z" clip-rule="evenodd"></path></svg>
                    </button>
                    <button id="tablet-btn" class="p-2 rounded-md bg-gray-200 text-gray-700" title="Tablet View">
                        <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M4 2a2 2 0 00-2 2v12a2 2 0 002 2h12a2 2 0 002-2V4a2 2 0 00-2-2H4zm1 2a1 1 0 00-1 1v10a1 1 0 001 1h10a1 1 0 001-1V5a1 1 0 00-1-1H5z" clip-rule="evenodd"></path></svg>
                    </button>
                    <button id="mobile-btn" class="p-2 rounded-md bg-gray-200 text-gray-700" title="Mobile View">
                        <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor"><path d="M5 2a2 2 0 00-2 2v12a2 2 0 002 2h6a2 2 0 002-2V4a2 2 0 00-2-2H5z"></path></svg>
                    </button>
                </div>
            </div>
        </header>

        <div class="flex flex-1 overflow-hidden" id="main-container">
             <aside id="controls-sidebar" class="w-1/3 bg-white shadow-lg overflow-hidden transition-all duration-300 ease-in-out">
                <div id="controls-layout">
                    <nav id="controls-nav" class="space-y-2">
                        <button class="control-nav-button" data-target="#panel-global-settings"><i class="fas fa-cog"></i>Global</button>
                        <button class="control-nav-button" data-target="#panel-layout"><i class="fas fa-layer-group"></i>Layout</button>
                        <button class="control-nav-button" data-target="#panel-image-slider"><i class="fas fa-images"></i>Image Slider</button>
                        <button class="control-nav-button" data-target="#panel-accordion"><i class="fas fa-align-justify"></i>Accordion/FAQ</button>
                        <button class="control-nav-button" data-target="#panel-custom-html"><i class="fas fa-code"></i>Custom HTML</button>
                    </nav>

                    <div id="controls-panels">
                        <div id="panel-global-settings" class="control-panel">
                            <h3>⚙️ Global Settings</h3>
                            <div class="space-y-4">
                                <div class="space-y-2 border-b pb-4">
                                     <label class="font-medium text-sm">Color Palette</label>
                                     <div class="grid grid-cols-2 gap-2 text-xs">
                                        <div>
                                            <label for="global-color-primary">Primary</label>
                                            <input type="color" id="global-color-primary" class="w-full p-0 h-8 border-none rounded-md">
                                        </div>
                                        <div>
                                            <label for="global-color-secondary">Secondary</label>
                                            <input type="color" id="global-color-secondary" class="w-full p-0 h-8 border-none rounded-md">
                                        </div>
                                        <div>
                                            <label for="global-color-text">Text</label>
                                            <input type="color" id="global-color-text" class="w-full p-0 h-8 border-none rounded-md">
                                        </div>
                                        <div>
                                            <label for="global-color-heading">Heading</label>
                                            <input type="color" id="global-color-heading" class="w-full p-0 h-8 border-none rounded-md">
                                        </div>
                                     </div>
                                </div>
                                <div class="space-y-2 border-b pb-4">
                                     <label class="font-medium text-sm">Typography</label>
                                     <div>
                                        <label for="global-font-family" class="text-xs">Font Family</label>
                                        <select id="global-font-family" class="w-full p-1 border rounded-md text-sm">
                                            <option value="'Inter', sans-serif">Inter</option>
                                            <option value="'Roboto', sans-serif">Roboto</option>
                                            <option value="'Open Sans', sans-serif">Open Sans</option>
                                            <option value="'Lato', sans-serif">Lato</option>
                                            <option value="'Montserrat', sans-serif">Montserrat</option>
                                            <option value="'Poppins', sans-serif">Poppins</option>
                                        </select>
                                    </div>
                                </div>
                                <button id="apply-global-settings" class="w-full bg-blue-600 text-white font-bold py-2 px-4 rounded-md hover:bg-blue-700 transition">Apply Global Styles</button>
                            </div>
                        </div>

                        <div id="panel-layout" class="control-panel">
                            <h3>↕️ Component Layout</h3>
                            <p class="text-xs text-gray-500 mb-4">Drag and drop to change the vertical order of the components on your page.</p>
                            <div id="layout-builder-container" class="space-y-2"></div>
                        </div>
                        
                        <div id="panel-image-slider" class="control-panel">
                            <div class="flex justify-between items-center mb-6">
                                <h3 class="mb-0 pb-0 border-b-0">🖼️ Image Slider</h3>
                                <button class="get-component-code-btn text-sm bg-indigo-500 text-white py-1 px-3 rounded-md hover:bg-indigo-600" data-component-key="imageSlider">
                                    <i class="fas fa-code mr-1"></i> Get Code
                                </button>
                            </div>

                             <div class="space-y-4">
                                <div class="flex items-center space-x-2 border-b pb-4">
                                    <input type="checkbox" id="image-slider-toggle" class="h-4 w-4 rounded">
                                    <label for="image-slider-toggle" class="font-medium">Enable Image Slider</label>
                                </div>

                                <div id="image-slider-builder" class="space-y-4">
                                    <h4>Slides</h4>
                                    <div id="slider-slides-container" class="space-y-2"></div>
                                    <button id="add-slider-slide-btn" class="text-sm bg-blue-500 text-white py-2 px-4 rounded-md hover:bg-blue-600 w-full"><i class="fas fa-plus mr-2"></i>Add Slide</button>

                                    <h4>Behavior &amp; Timing</h4>
                                    <div class="grid grid-cols-2 gap-4 text-sm">
                                        <div class="flex items-center space-x-2"><input type="checkbox" id="slider-autoplay-toggle" class="h-4 w-4 rounded"><label for="slider-autoplay-toggle">Autoplay</label></div>
                                        <div class="flex items-center space-x-2"><input type="checkbox" id="slider-loop-toggle" class="h-4 w-4 rounded"><label for="slider-loop-toggle">Loop</label></div>
                                        <div class="flex items-center space-x-2"><input type="checkbox" id="slider-pause-on-hover-toggle" class="h-4 w-4 rounded"><label for="slider-pause-on-hover-toggle">Pause on Hover</label></div>
                                    </div>
                                    <div class="grid grid-cols-2 gap-4 text-sm">
                                        <div><label for="slider-speed" class="block text-xs">Transition Speed (ms)</label><input type="number" id="slider-speed" class="w-full p-1 border rounded-md" step="100"></div>
                                        <div><label for="slider-autoplay-delay" class="block text-xs">Autoplay Delay (ms)</label><input type="number" id="slider-autoplay-delay" class="w-full p-1 border rounded-md" step="500"></div>
                                    </div>
                                    
                                    <h4>Navigation & Interaction</h4>
                                     <div class="grid grid-cols-2 gap-4 text-sm">
                                        <div class="flex items-center space-x-2"><input type="checkbox" id="slider-arrows-toggle" class="h-4 w-4 rounded"><label for="slider-arrows-toggle">Arrows</label></div>
                                        <div class="flex items-center space-x-2"><input type="checkbox" id="slider-pagination-toggle" class="h-4 w-4 rounded"><label for="slider-pagination-toggle">Dots</label></div>
                                        <div class="flex items-center space-x-2"><input type="checkbox" id="slider-progressbar-toggle" class="h-4 w-4 rounded"><label for="slider-progressbar-toggle">Progress Bar</label></div>
                                        <div class="flex items-center space-x-2"><input type="checkbox" id="slider-scrollbar-toggle" class="h-4 w-4 rounded"><label for="slider-scrollbar-toggle">Scrollbar</label></div>
                                        <div class="flex items-center space-x-2"><input type="checkbox" id="slider-thumbnails-toggle" class="h-4 w-4 rounded"><label for="slider-thumbnails-toggle">Thumbnails</label></div>
                                        <div class="flex items-center space-x-2"><input type="checkbox" id="slider-keyboard-toggle" class="h-4 w-4 rounded"><label for="slider-keyboard-toggle">Keyboard</label></div>
                                    </div>

                                    <h4>Effects & Layout</h4>
                                    <div class="grid grid-cols-2 gap-4 text-sm">
                                        <div>
                                            <label for="slider-effect" class="block text-xs">Transition Effect</label>
                                            <select id="slider-effect" class="w-full p-1 border rounded-md text-sm">
                                                <option value="slide">Slide</option><option value="fade">Fade</option><option value="cube">Cube</option><option value="coverflow">Coverflow</option><option value="flip">Flip</option>
                                            </select>
                                        </div>
                                        <div>
                                            <label for="slider-slides-per-view" class="block text-xs">Slides Per View</label>
                                            <input type="number" id="slider-slides-per-view" class="w-full p-1 border rounded-md" min="1" max="10" step="1">
                                        </div>
                                    </div>
                                    <div class="grid grid-cols-2 gap-4 text-sm">
                                        <div class="flex items-center space-x-2"><input type="checkbox" id="slider-centered-slides-toggle" class="h-4 w-4 rounded"><label for="slider-centered-slides-toggle">Center Slides</label></div>
                                        <div class="flex items-center space-x-2"><input type="checkbox" id="slider-full-width-toggle" class="h-4 w-4 rounded"><label for="slider-full-width-toggle">Full Width</label></div>
                                    </div>
                                    
                                    <h4>Performance & Accessibility</h4>
                                     <div class="grid grid-cols-2 gap-4 text-sm">
                                        <div class="flex items-center space-x-2"><input type="checkbox" id="slider-lazyload-toggle" class="h-4 w-4 rounded"><label for="slider-lazyload-toggle">Lazy Loading</label></div>
                                        <div class="flex items-center space-x-2"><input type="checkbox" id="slider-a11y-toggle" class="h-4 w-4 rounded"><label for="slider-a11y-toggle">Accessibility</label></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <div id="panel-accordion" class="control-panel">
                            <div class="flex justify-between items-center mb-6">
                                <h3 class="mb-0 pb-0 border-b-0"><i class="fas fa-align-justify mr-2"></i>Accordion/FAQ</h3>
                                <button class="get-component-code-btn text-sm bg-indigo-500 text-white py-1 px-3 rounded-md hover:bg-indigo-600" data-component-key="accordion">
                                    <i class="fas fa-code mr-1"></i> Get Code
                                </button>
                            </div>
                            <div class="space-y-4">
                                <div class="flex items-center space-x-2 border-b pb-4">
                                    <input type="checkbox" id="accordion-toggle" class="h-4 w-4 rounded">
                                    <label for="accordion-toggle" class="font-medium">Enable Accordion/FAQ Section</label>
                                </div>
                                <div id="accordion-builder" class="space-y-4">
                                    <h4>Items</h4>
                                    <div id="accordion-items-container" class="space-y-2"></div>
                                    <button id="add-accordion-item-btn" class="text-sm bg-blue-500 text-white py-2 px-4 rounded-md hover:bg-blue-600 w-full"><i class="fas fa-plus mr-2"></i>Add Item</button>

                                    <h4>Settings</h4>
                                    <div class="flex items-center space-x-2 text-sm">
                                        <input type="checkbox" id="accordion-multiple-open-toggle" class="h-4 w-4 rounded">
                                        <label for="accordion-multiple-open-toggle">Allow multiple items to be open</label>
                                    </div>
                                    <div class="text-sm">
                                        <label for="accordion-icon-style" class="block text-xs">Icon Style</label>
                                        <select id="accordion-icon-style" class="w-full p-1 border rounded-md text-sm">
                                            <option value="plus-minus">Plus / Minus</option>
                                            <option value="chevron">Chevron</option>
                                            <option value="caret">Caret</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div id="panel-custom-html" class="control-panel">
                             <div class="flex justify-between items-center mb-6">
                                <h3 class="mb-0 pb-0 border-b-0"> </> Custom HTML</h3>
                                <button class="get-component-code-btn text-sm bg-indigo-500 text-white py-1 px-3 rounded-md hover:bg-indigo-600" data-component-key="customHtml">
                                    <i class="fas fa-code mr-1"></i> Get Code
                                </button>
                            </div>
                             <div class="space-y-4">
                                <div class="flex items-center space-x-2 border-b pb-4">
                                    <input type="checkbox" id="custom-html-toggle" class="h-4 w-4 rounded">
                                    <label for="custom-html-toggle" class="font-medium">Enable Custom HTML Section</label>
                                </div>
                                <div id="custom-html-builder">
                                    <label for="custom-html-content" class="text-sm font-medium">HTML Content</label>
                                    <p class="text-xs text-gray-500 mb-2">Paste any valid HTML. Be cautious, as invalid code can break the page layout.</p>
                                    <textarea id="custom-html-content" rows="10" class="w-full p-2 border rounded-md font-mono text-sm"></textarea>
                                </div>
                            </div>
                        </div>

                    </div>
                </div>
            </aside>


            <main id="preview-main" class="w-2/3 bg-gray-200 p-4 flex flex-col items-center justify-center overflow-hidden transition-all duration-300 ease-in-out">
                <div id="preview-container" class="bg-white shadow-lg rounded-lg w-full h-full overflow-hidden">
                    <iframe id="preview-iframe" class="preview-iframe"></iframe>
                </div>
            </main>

        </div>
    </div>
    <div id="toast-notification" class="toast"></div>

    <div id="code-modal" class="hidden fixed inset-0 bg-gray-600 bg-opacity-75 overflow-y-auto h-full w-full z-50">
        <div class="relative top-10 mx-auto p-5 border w-11/12 md:w-2/3 shadow-lg rounded-md bg-white">
            <div class="flex justify-between items-center border-b pb-3">
                 <h3 id="code-modal-title" class="text-lg leading-6 font-medium text-gray-900">Component Code</h3>
                 <button id="close-code-modal-btn" class="text-gray-400 hover:text-gray-600">&times;</button>
            </div>
            <div class="mt-4 space-y-4">
                <div>
                    <label class="font-semibold text-gray-700">HTML</label>
                    <pre id="code-modal-html" class="code-modal-pre"><code></code></pre>
                </div>
                 <div>
                    <label class="font-semibold text-gray-700">CSS</label>
                    <pre id="code-modal-css" class="code-modal-pre"><code></code></pre>
                </div>
                 <div>
                    <label class="font-semibold text-gray-700">JavaScript</label>
                    <pre id="code-modal-js" class="code-modal-pre"><code></code></pre>
                </div>
            </div>
            <div class="items-center px-4 py-3 mt-4 text-right bg-gray-50 -mx-5 -mb-5 rounded-b-md">
                <button id="download-component-zip-btn" class="px-4 py-2 bg-green-600 text-white text-base font-medium rounded-md shadow-sm hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-green-300">
                    Download .zip
                </button>
                <button id="close-code-modal-btn-2" class="px-4 py-2 bg-gray-200 text-gray-800 text-base font-medium rounded-md shadow-sm hover:bg-gray-300 focus:outline-none focus:ring-2 focus:ring-gray-300 ml-2">
                    Close
                </button>
            </div>
        </div>
    </div>

    <script src="https://unpkg.com/swiper/swiper-bundle.min.js"></script>
    <script>
    document.addEventListener('DOMContentLoaded', () => {
        // State object to hold all configurations
        const config = {
            globalSettings: {
                colors: {
                    primary: '#3b82f6',
                    secondary: '#10b981',
                    text: '#374151',
                    heading: '#111827',
                },
                typography: {
                    fontFamily: "'Inter', sans-serif",
                }
            },
            componentOrder: [
                'imageSlider',
                'accordion',
                'customHtml'
            ],
            imageSlider: {
                enabled: true,
                slides: [
                    { id: Date.now(), type: 'image', imageUrl: 'https://images.unsplash.com/photo-1549880338-65ddcdfd017b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80', videoUrl: '', posterUrl: '', title: 'Explore the Mountains', caption: 'Breathtaking views and serene landscapes await.', link: '#' },
                    { id: Date.now() + 1, type: 'video', imageUrl: '', videoUrl: 'https://cdn.coverr.co/videos/coverr-a-man-running-on-a-road-in-the-countryside-7546/1080p.mp4', posterUrl: 'https://images.unsplash.com/photo-1551632811-561732d1e306?ixlib=rb-1.2.1&auto=format&fit=crop&w=1350&q=80', title: 'Active Lifestyle', caption: 'Push your limits every day.', link: '#' },
                    { id: Date.now() + 5, type: 'image', imageUrl: 'https://images.unsplash.com/photo-1554425396-5b404e7a4e?ixlib=rb-1.2.1&auto=format&fit=crop&w=1350&q=80', videoUrl: '', posterUrl: '', title: 'City Skylines', caption: 'Experience the vibrant life of the city.', link: '#' }
                ],
                settings: {
                    autoplay: true, loop: true, pauseOnHover: true, speed: 800, delay: 4000,
                    showArrows: true, showPagination: true, showProgressBar: false, showScrollbar: false,
                    showThumbnails: true, keyboardControl: true, lazyLoad: true, accessibility: true,
                    effect: 'slide', slidesPerView: 1, centeredSlides: true, fullWidth: true,
                }
            },
            accordion: {
                enabled: true,
                allowMultipleOpen: false,
                iconStyle: 'plus-minus', // 'plus-minus', 'chevron', 'caret'
                items: [
                    { id: Date.now() + 2, title: 'What is this component builder?', content: 'This is an interactive tool that allows you to visually construct and customize web page components, then export the ready-to-use HTML, CSS, and JavaScript code.'},
                    { id: Date.now() + 3, title: 'How do I add a new item?', content: 'Simply click the "Add Item" button in the control panel. A new accordion item will appear here, and you can edit its title and content in the controls on the left.'},
                    { id: Date.now() + 4, title: 'Can I have multiple items open at once?', content: 'Yes, you can! Just check the "Allow multiple items to be open" box in the settings within the control panel. Try it now!'}
                ]
            },
            customHtml: {
                enabled: false,
                content: ''
            }
        };

        const componentNames = {
            customHtml: 'Custom HTML',
            imageSlider: 'Image Slider',
            accordion: 'Accordion/FAQ'
        };

        // UI Element References
        const ui = {
            previewIframe: document.getElementById('preview-iframe'),
            mainContainer: document.getElementById('main-container'),
            toggleSidebarBtn: document.getElementById('toggle-sidebar-btn'),
            controls: {
                nav: document.getElementById('controls-nav'),
                panels: document.getElementById('controls-panels'),
            },
            globalSettings: {
                primaryColor: document.getElementById('global-color-primary'),
                secondaryColor: document.getElementById('global-color-secondary'),
                textColor: document.getElementById('global-color-text'),
                headingColor: document.getElementById('global-color-heading'),
                fontFamily: document.getElementById('global-font-family'),
                applyBtn: document.getElementById('apply-global-settings'),
            },
            layout: {
                container: document.getElementById('layout-builder-container'),
                panel: document.getElementById('panel-layout')
            },
            imageSlider: {
                toggle: document.getElementById('image-slider-toggle'),
                builder: document.getElementById('image-slider-builder'),
                slidesContainer: document.getElementById('slider-slides-container'),
                addSlideBtn: document.getElementById('add-slider-slide-btn'),
                autoplay: document.getElementById('slider-autoplay-toggle'),
                loop: document.getElementById('slider-loop-toggle'),
                pauseOnHover: document.getElementById('slider-pause-on-hover-toggle'),
                speed: document.getElementById('slider-speed'),
                delay: document.getElementById('slider-autoplay-delay'),
                arrows: document.getElementById('slider-arrows-toggle'),
                pagination: document.getElementById('slider-pagination-toggle'),
                progressbar: document.getElementById('slider-progressbar-toggle'),
                scrollbar: document.getElementById('slider-scrollbar-toggle'),
                thumbnails: document.getElementById('slider-thumbnails-toggle'),
                keyboard: document.getElementById('slider-keyboard-toggle'),
                lazyload: document.getElementById('slider-lazyload-toggle'),
                a11y: document.getElementById('slider-a11y-toggle'),
                effect: document.getElementById('slider-effect'),
                slidesPerView: document.getElementById('slider-slides-per-view'),
                centeredSlides: document.getElementById('slider-centered-slides-toggle'),
                fullWidth: document.getElementById('slider-full-width-toggle'),
            },
            accordion: {
                toggle: document.getElementById('accordion-toggle'),
                builder: document.getElementById('accordion-builder'),
                itemsContainer: document.getElementById('accordion-items-container'),
                addItemBtn: document.getElementById('add-accordion-item-btn'),
                multipleOpen: document.getElementById('accordion-multiple-open-toggle'),
                iconStyle: document.getElementById('accordion-icon-style'),
            },
            customHtml: {
                toggle: document.getElementById('custom-html-toggle'),
                content: document.getElementById('custom-html-content'),
            },
            buttons: {
                desktop: document.getElementById('desktop-btn'),
                tablet: document.getElementById('tablet-btn'),
                mobile: document.getElementById('mobile-btn'),
                import: document.getElementById('import-btn'),
                importFile: document.getElementById('import-file-input'),
            },
            exportMenu: {
                container: document.getElementById('export-menu-container'),
                button: document.getElementById('export-menu-btn'),
                dropdown: document.getElementById('export-dropdown'),
                copyCombined: document.getElementById('copy-combined-code'),
                copyHtml: document.getElementById('copy-html'),
                copyCss: document.getElementById('copy-css'),
                copyJs: document.getElementById('copy-js'),
                downloadZip: document.getElementById('download-zip-btn'),
            },
            codeModal: {
                modal: document.getElementById('code-modal'),
                title: document.getElementById('code-modal-title'),
                htmlContainer: document.getElementById('code-modal-html'),
                cssContainer: document.getElementById('code-modal-css'),
                jsContainer: document.getElementById('code-modal-js'),
                htmlCode: document.querySelector('#code-modal-html code'),
                cssCode: document.querySelector('#code-modal-css code'),
                jsCode: document.querySelector('#code-modal-js code'),
                downloadBtn: document.getElementById('download-component-zip-btn'),
                closeBtns: [document.getElementById('close-code-modal-btn'), document.getElementById('close-code-modal-btn-2')],
            },
            previewContainer: document.getElementById('preview-container'),
        };

        // --- Event Listeners ---
        function setupEventListeners() {
            ui.controls.nav.addEventListener('click', (e) => {
                const button = e.target.closest('.control-nav-button');
                if (!button) return;
                const targetPanelId = button.dataset.target;
                ui.controls.nav.querySelectorAll('.control-nav-button').forEach(btn => btn.classList.remove('active'));
                button.classList.add('active');
                ui.controls.panels.querySelectorAll('.control-panel').forEach(panel => {
                    panel.classList.toggle('active', `#${panel.id}` === targetPanelId);
                });
            });
            
            ui.globalSettings.applyBtn.addEventListener('click', () => { renderAll(); showToast('Global styles applied!'); });

            // Layout Controls
            ui.layout.panel.addEventListener('click', handleLayoutControlsClick);
            setupDragAndDrop();

            // Component Listeners
            ui.imageSlider.toggle.addEventListener('change', e => { config.imageSlider.enabled = e.target.checked; renderAll(); });
            setupImageSliderEventListeners();
            
            ui.accordion.toggle.addEventListener('change', e => { config.accordion.enabled = e.target.checked; renderAll(); });
            setupAccordionEventListeners();

            ui.customHtml.toggle.addEventListener('change', e => { config.customHtml.enabled = e.target.checked; renderAll(); });
            ui.customHtml.content.addEventListener('input', e => { config.customHtml.content = e.target.value; renderAll(); });

            // Preview & Export
            ui.buttons.desktop.addEventListener('click', () => setPreviewMode('desktop'));
            ui.buttons.tablet.addEventListener('click', () => setPreviewMode('tablet'));
            ui.buttons.mobile.addEventListener('click', () => setPreviewMode('mobile'));
            ui.exportMenu.button.addEventListener('click', (e) => { e.stopPropagation(); ui.exportMenu.dropdown.classList.toggle('hidden'); });
            window.addEventListener('click', (e) => { if (!ui.exportMenu.container.contains(e.target)) { ui.exportMenu.dropdown.classList.add('hidden'); } });
            
            const copyAction = (e, dataGetter, message) => {
                e.preventDefault();
                navigator.clipboard.writeText(dataGetter()).then(() => showToast(message));
                ui.exportMenu.dropdown.classList.add('hidden');
            };
            
            ui.exportMenu.copyCombined.addEventListener('click', (e) => copyAction(e, getCombinedCode, 'Combined code copied!'));
            ui.exportMenu.copyHtml.addEventListener('click', (e) => copyAction(e, getAllHtml, 'All HTML copied!'));
            ui.exportMenu.copyCss.addEventListener('click', (e) => copyAction(e, getFullCSS, 'All CSS copied!'));
            ui.exportMenu.copyJs.addEventListener('click', (e) => copyAction(e, getFullJS, 'All JS copied!'));
            ui.exportMenu.downloadZip.addEventListener('click', (e) => { e.preventDefault(); generatePageZip(); ui.exportMenu.dropdown.classList.add('hidden'); });
            
            // Other Listeners
            ui.controls.panels.addEventListener('click', handleGetCodeClick);
            ui.codeModal.closeBtns.forEach(btn => btn.addEventListener('click', () => ui.codeModal.modal.classList.add('hidden')));
            ui.toggleSidebarBtn.addEventListener('click', () => {
                ui.mainContainer.classList.toggle('sidebar-collapsed');
                const isCollapsed = ui.mainContainer.classList.contains('sidebar-collapsed');
                const icon = ui.toggleSidebarBtn.querySelector('i');
                icon.classList.toggle('fa-chevron-left', !isCollapsed);
                icon.classList.toggle('fa-chevron-right', isCollapsed);
                ui.toggleSidebarBtn.title = isCollapsed ? 'Show Controls' : 'Hide Controls';
            });
        }
        
        // --- LAYOUT CONTROLS ---
        function renderLayoutControls() {
            ui.layout.container.innerHTML = config.componentOrder.map((key, index) => {
                const total = config.componentOrder.length;
                return `
                <div class="layout-item p-3 border rounded-md bg-white flex items-center justify-between" draggable="true" data-key="${key}">
                    <span class="font-medium text-sm"><i class="fas fa-grip-vertical mr-3 text-gray-400"></i> ${componentNames[key]}</span>
                    <div class="item-toolbar mb-0">
                        <button class="reorder-layout-up-btn text-xs bg-gray-200 text-gray-700 p-1 rounded-md hover:bg-gray-300" data-index="${index}" ${index === 0 ? 'disabled' : ''}><i class="fas fa-arrow-up fa-fw"></i></button>
                        <button class="reorder-layout-down-btn text-xs bg-gray-200 text-gray-700 p-1 rounded-md hover:bg-gray-300" data-index="${index}" ${index === total - 1 ? 'disabled' : ''}><i class="fas fa-arrow-down fa-fw"></i></button>
                    </div>
                </div>`;
            }).join('');
        }

        function handleLayoutControlsClick(e) {
            const button = e.target.closest('button');
            if (!button) return;
            const index = parseInt(button.dataset.index, 10);
            const order = config.componentOrder;
            let changed = false;
            if (button.classList.contains('reorder-layout-up-btn') && index > 0) {
                [order[index], order[index - 1]] = [order[index - 1], order[index]];
                changed = true;
            } else if (button.classList.contains('reorder-layout-down-btn') && index < order.length - 1) {
                [order[index], order[index + 1]] = [order[index + 1], order[index]];
                changed = true;
            }
            if(changed) { renderLayoutControls(); renderAll(); }
        }
        
        function setupDragAndDrop() {
            let draggedItem = null;
            ui.layout.container.addEventListener('dragstart', e => {
                draggedItem = e.target;
                setTimeout(() => e.target.style.display = 'none', 0);
            });
            ui.layout.container.addEventListener('dragend', () => setTimeout(() => { if(draggedItem) { draggedItem.style.display = 'flex'; } draggedItem = null; }, 0));
            ui.layout.container.addEventListener('dragover', e => {
                e.preventDefault();
                const afterElement = getDragAfterElement(ui.layout.container, e.clientY);
                if (afterElement == null) { ui.layout.container.appendChild(draggedItem); } 
                else { ui.layout.container.insertBefore(draggedItem, afterElement); }
            });
            ui.layout.container.addEventListener('drop', e => {
                 e.preventDefault();
                 if (!draggedItem) return;
                 config.componentOrder = [...ui.layout.container.querySelectorAll('.layout-item')].map(item => item.dataset.key);
                 renderLayoutControls();
                 renderAll();
            });
        }

        function getDragAfterElement(container, y) {
            const draggableElements = [...container.querySelectorAll('.layout-item:not([style*="display: none"])')];
            return draggableElements.reduce((closest, child) => {
                const box = child.getBoundingClientRect();
                const offset = y - box.top - box.height / 2;
                if (offset < 0 && offset > closest.offset) { return { offset: offset, element: child }; } 
                else { return closest; }
            }, { offset: Number.NEGATIVE_INFINITY }).element;
        }


        // --- HTML Generation Logic ---
        const componentGenerators = {
            imageSlider: generateImageSliderHTML,
            accordion: generateAccordionHTML,
            customHtml: generateCustomHtmlHTML
        };
        
        function getAllHtml() { return config.componentOrder.map(key => componentGenerators[key] ? componentGenerators[key]() : '').filter(Boolean).join('\n\n'); }
        
        function generateImageSliderHTML() {
            if (!config.imageSlider.enabled) return '';
            const { slides, settings } = config.imageSlider;

            const mainSlidesHtml = slides.map(slide => {
                const lazyHtml = settings.lazyLoad ? `data-src="${slide.type === 'image' ? slide.imageUrl : slide.videoUrl}" class="swiper-lazy"` : `src="${slide.type === 'image' ? slide.imageUrl : slide.videoUrl}"`;
                const mediaHtml = slide.type === 'image'
                    ? `<img ${lazyHtml} alt="${slide.title}" />`
                    : `<video ${lazyHtml} loop muted playsinline poster="${slide.posterUrl}"></video>`;
                const preloader = settings.lazyLoad ? '<div class="swiper-lazy-preloader swiper-lazy-preloader-white"></div>' : '';

                return `
                <div class="swiper-slide">
                    <a href="${slide.link || '#'}" class="slide-link">
                        ${mediaHtml}
                        <div class="slide-caption"><h3>${slide.title}</h3><p>${slide.caption}</p></div>
                        ${preloader}
                    </a>
                </div>`;
            }).join('');

            const thumbsSlidesHtml = settings.showThumbnails ? slides.map(slide => {
                const thumbSrc = slide.type === 'image' ? slide.imageUrl : slide.posterUrl;
                return `<div class="swiper-slide"><img src="${thumbSrc}" /></div>`;
            }).join('') : '';

            return `
            <div class="image-slider-section ${settings.fullWidth ? 'w-full' : 'max-w-7xl mx-auto py-8'}">
                <div class="swiper-container gallery-main">
                    <div class="swiper-wrapper">${mainSlidesHtml}</div>
                    ${settings.showArrows ? '<div class="swiper-button-next"></div><div class="swiper-button-prev"></div>' : ''}
                    ${settings.showPagination ? '<div class="swiper-pagination" id="swiper-pagination-dots"></div>' : ''}
                    ${settings.showProgressBar ? '<div class="swiper-pagination" id="swiper-pagination-progressbar"></div>' : ''}
                    ${settings.showScrollbar ? '<div class="swiper-scrollbar"></div>' : ''}
                </div>
                ${settings.showThumbnails ? `<div class="swiper-container gallery-thumbs"><div class="swiper-wrapper">${thumbsSlidesHtml}</div></div>` : ''}
            </div>`;
        }

        function generateAccordionHTML() {
            if (!config.accordion.enabled) return '';
            const { items, iconStyle } = config.accordion;
            const itemsHtml = items.map(item => `
                <div class="accordion-item">
                    <button class="accordion-header" aria-expanded="false">
                        <span class="accordion-title">${item.title}</span>
                        <span class="accordion-icon" data-icon-style="${iconStyle}"></span>
                    </button>
                    <div class="accordion-content"><div class="accordion-content-inner">${item.content}</div></div>
                </div>`).join('');
            return `
            <div class="accordion-section">
                <div class="max-w-3xl mx-auto py-8 px-4">
                    <h2 class="section-title">Frequently Asked Questions</h2>
                    <div class="accordion-container">${itemsHtml}</div>
                </div>
            </div>`;
        }
        
        function generateCustomHtmlHTML() { return config.customHtml.enabled ? `<div class="custom-html-section">${config.customHtml.content}</div>` : ''; }

        function generateComponentCSS(targetKey = null) {
            const { colors } = config.globalSettings;
            const css = {};
            css.global = `:root { --primary-color: ${colors.primary}; } /* ... */`;

            if(config.imageSlider.enabled) css.imageSlider = `
.gallery-main { height: 80%; width: 100%; }
.gallery-thumbs { height: 20%; box-sizing: border-box; padding: 10px 0; }
.gallery-thumbs .swiper-slide { width: 25%; height: 100%; opacity: 0.4; cursor: pointer; }
.gallery-thumbs .swiper-slide-thumb-active { opacity: 1; border: 2px solid var(--primary-color); }
.swiper-slide img, .swiper-slide video { display: block; width: 100%; height: 100%; object-fit: cover; }
.slide-caption { position: absolute; bottom: 0; left: 0; right: 0; padding: 40px 20px; background: linear-gradient(to top, rgba(0,0,0,0.8) 0%, rgba(0,0,0,0) 100%); color: white; }
.slide-caption h3 { color: white; }
.swiper-button-next, .swiper-button-prev { color: var(--primary-color); }
.swiper-pagination-bullet-active { background-color: var(--primary-color); }
.swiper-pagination-progressbar .swiper-pagination-progressbar-fill { background: var(--primary-color); }`;
            
            if(config.accordion.enabled) css.accordion = `
.accordion-header { width: 100%; text-align: left; padding: 1rem 1.5rem; background-color: #fff; border: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
.accordion-header:hover { background-color: #f9fafb; }
.accordion-content { max-height: 0; overflow: hidden; transition: max-height 0.3s ease-in-out; }
.accordion-content-inner { padding: 1.5rem; }
.accordion-header[aria-expanded="true"] + .accordion-content { max-height: 500px; }
.accordion-icon { transition: transform 0.3s ease; }
.accordion-header[aria-expanded="true"] .accordion-icon[data-icon-style="plus-minus"] { transform: rotate(45deg); }
.accordion-icon[data-icon-style$="plus-minus"]::before, .accordion-icon[data-icon-style$="plus-minus"]::after { content: ''; position: absolute; width: 12px; height: 2px; background-color: currentColor; }
.accordion-icon[data-icon-style$="plus-minus"]::after { transform: rotate(90deg); }
.accordion-header[aria-expanded="true"] .accordion-icon[data-icon-style="plus-minus"]::after { display: none; }
/* ... other icon styles ... */`;
            
            if (targetKey) { return { global: css.global, component: css[targetKey] || '' } }
            return css;
        }

        function getFullCSS() {
            const cssObject = generateComponentCSS();
            return [cssObject.global, ...Object.values(cssObject).filter(c => c !== cssObject.global)].join('\n');
        }
        
        function generateComponentJavaScript(targetKey = null) {
            const js = {};
            if (config.imageSlider.enabled) { js.imageSlider = generateImageSliderJS(); }
            if (config.accordion.enabled) { js.accordion = generateAccordionJS(); }
            if (targetKey) { return js[targetKey] || ''; }
            return js;
        }

        function getFullJS() { return config.componentOrder.map(key => (generateComponentJavaScript(key) || '')).filter(Boolean).join('\n\n'); }
        
        function generateImageSliderJS() {
            if (!config.imageSlider.enabled) return '';
            const { settings } = config.imageSlider;
            let thumbsSwiperJs = '';
            let mainSwiperOptions = {};
            
            if (settings.showThumbnails) {
                thumbsSwiperJs = `
    const thumbsSwiper = new Swiper('.gallery-thumbs', {
      spaceBetween: 10,
      slidesPerView: 4,
      freeMode: true,
      watchSlidesProgress: true,
    });`;
                mainSwiperOptions.thumbs = { swiper: 'thumbsSwiper' }; // Placeholder
            }
            
            mainSwiperOptions = {
                ...mainSwiperOptions,
                spaceBetween: 10,
                speed: settings.speed, loop: settings.loop, effect: settings.effect,
                slidesPerView: settings.slidesPerView, centeredSlides: settings.centeredSlides,
            };

            if (settings.autoplay) { mainSwiperOptions.autoplay = { delay: settings.delay, disableOnInteraction: !settings.pauseOnHover, pauseOnMouseEnter: settings.pauseOnHover, }; }
            if (settings.showPagination) { mainSwiperOptions.pagination = { el: '#swiper-pagination-dots', clickable: true }; }
            if (settings.showProgressBar) { mainSwiperOptions.pagination = { ...mainSwiperOptions.pagination, el: '#swiper-pagination-progressbar', type: 'progressbar' }; }
            if (settings.showArrows) { mainSwiperOptions.navigation = { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev' }; }
            if (settings.showScrollbar) { mainSwiperOptions.scrollbar = { el: '.swiper-scrollbar', hide: true }; }
            if (settings.keyboardControl) { mainSwiperOptions.keyboard = { enabled: true }; }
            if (settings.lazyLoad) { mainSwiperOptions.lazy = { loadPrevNext: true }; }
            if (settings.accessibility) { mainSwiperOptions.a11y = { prevSlideMessage: 'Previous slide', nextSlideMessage: 'Next slide' }; }

            let mainSwiperJs = `const mainSwiper = new Swiper('.gallery-main', ${JSON.stringify(mainSwiperOptions).replace('"thumbsSwiper"', 'thumbsSwiper')});`;
            
            return thumbsSwiperJs + '\n' + mainSwiperJs;
        }

        function generateAccordionJS() {
            if (!config.accordion.enabled) return '';
            return `
const accordionItems = document.querySelectorAll('.accordion-header');
accordionItems.forEach(item => {
    item.addEventListener('click', () => {
        const currentlyExpanded = item.getAttribute('aria-expanded') === 'true';
        if (!${config.accordion.allowMultipleOpen}) {
            accordionItems.forEach(otherItem => {
                if (otherItem !== item) otherItem.setAttribute('aria-expanded', 'false');
            });
        }
        item.setAttribute('aria-expanded', String(!currentlyExpanded));
    });
});`;
        }

        function getCombinedCode() { /* Unchanged but works with new code */ return `<!DOCTYPE html>...`; }
        function renderAll() {
            const fullJs = getFullJS();
            const previewContent = `<!DOCTYPE html><html><head><title>Preview</title><script src="https://cdn.tailwindcss.com"><\/script><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css"><link rel="stylesheet" href="https://unpkg.com/swiper/swiper-bundle.min.css" /><style>${getFullCSS()}</style></head><body><div class="site-wrapper">${getAllHtml()}</div><script src="https://unpkg.com/swiper/swiper-bundle.min.js"><\/script><script>document.addEventListener('DOMContentLoaded', () => { \n${fullJs} \n});<\/script></body></html>`;
            ui.previewIframe.srcdoc = previewContent;
        }

        // --- Component Specific Functions ---
        function setupImageSliderEventListeners() {
            const s = ui.imageSlider;
            const settings = config.imageSlider.settings;
            // Simplified example for one checkbox
            s.autoplay.addEventListener('change', e => { settings.autoplay = e.target.checked; renderAll(); });
            s.thumbnails.addEventListener('change', e => { settings.showThumbnails = e.target.checked; renderAll(); });
            s.lazyload.addEventListener('change', e => { settings.lazyLoad = e.target.checked; renderAll(); });
            s.progressbar.addEventListener('change', e => { settings.showProgressBar = e.target.checked; renderAll(); });
            s.keyboard.addEventListener('change', e => { settings.keyboardControl = e.target.checked; renderAll(); });
            s.a11y.addEventListener('change', e => { settings.accessibility = e.target.checked; renderAll(); });

            s.addSlideBtn.addEventListener('click', () => {
                config.imageSlider.slides.push({ id: Date.now(), type: 'image', imageUrl: 'https://via.placeholder.com/1280x720', videoUrl: '', posterUrl: '', title: 'New Slide', caption: 'Edit this.', link: '#' });
                renderSliderSlideControls(); renderAll();
            });
            s.slidesContainer.addEventListener('click', e => {
                const button = e.target.closest('button.remove-slide-btn');
                if (!button) return;
                config.imageSlider.slides = config.imageSlider.slides.filter(slide => slide.id !== parseInt(button.closest('.component-item-controls').dataset.id));
                renderSliderSlideControls(); renderAll();
            });
            s.slidesContainer.addEventListener('input, change', e => {
                 const input = e.target;
                 const slide = config.imageSlider.slides.find(s => s.id === parseInt(input.closest('.component-item-controls').dataset.id));
                 if (slide) { 
                    slide[input.dataset.key] = input.value;
                    if (input.dataset.key === 'type') {
                        renderSliderSlideControls(); // Re-render to show/hide fields
                    }
                    renderAll(); 
                 }
            });
        }
        function renderSliderSlideControls() {
            ui.imageSlider.slidesContainer.innerHTML = config.imageSlider.slides.map(slide => {
                const isImage = slide.type === 'image';
                return `
                <div class="component-item-controls space-y-2 text-xs" data-id="${slide.id}">
                    <div class="flex items-center justify-between">
                        <select class="p-1 border rounded-md" data-key="type">
                            <option value="image" ${isImage ? 'selected' : ''}>Image</option>
                            <option value="video" ${!isImage ? 'selected' : ''}>Video</option>
                        </select>
                        <button class="remove-slide-btn text-red-500 p-1"><i class="fas fa-trash-alt"></i></button>
                    </div>
                    <div class="space-y-2 image-fields" style="display: ${isImage ? 'block' : 'none'};">
                        <div><label>Image URL</label><input type="text" class="w-full p-1 border" data-key="imageUrl" value="${slide.imageUrl}"></div>
                    </div>
                    <div class="space-y-2 video-fields" style="display: ${!isImage ? 'block' : 'none'};">
                        <div><label>Video URL (.mp4)</label><input type="text" class="w-full p-1 border" data-key="videoUrl" value="${slide.videoUrl}"></div>
                        <div><label>Poster Image URL</label><input type="text" class="w-full p-1 border" data-key="posterUrl" value="${slide.posterUrl}"></div>
                    </div>
                    <div><label>Title</label><input type="text" class="w-full p-1 border" data-key="title" value="${slide.title}"></div>
                    <div><label>Caption</label><input type="text" class="w-full p-1 border" data-key="caption" value="${slide.caption}"></div>
                </div>`
            }).join('');
        }

        function setupAccordionEventListeners() { /* Unchanged */ }
        function renderAccordionItemControls() { /* Unchanged */ }

        // Initial Load
        function init() {
            // Init Global Settings
            
            // Init Image Slider
            const s = ui.imageSlider;
            const settings = config.imageSlider.settings;
            s.toggle.checked = config.imageSlider.enabled;
            s.autoplay.checked = settings.autoplay;
            s.thumbnails.checked = settings.showThumbnails;
            s.lazyload.checked = settings.lazyLoad;
            s.progressbar.checked = settings.showProgressBar;
            s.keyboard.checked = settings.keyboardControl;
            s.a11y.checked = settings.accessibility;
            renderSliderSlideControls();

            // Init Accordion
            renderAccordionItemControls();

            setupEventListeners();
            renderLayoutControls();
            renderAll();
            if(!document.querySelector('.control-nav-button.active')){
                ui.controls.nav.querySelector('.control-nav-button').click();
            }
        }

        init();
    });
    </script>
</body>
</html>