File size: 48,177 Bytes
2d450d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>WooCommerce Product Import CSV Generator</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://cdn.jsdelivr.net/npm/@preline/[email protected]/dist/preline.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.3.0/papaparse.min.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        .variation-item {
            transition: all 0.3s ease;
        }
        .variation-item:hover {
            background-color: #f3f4f6;
        }
        .progress-bar {
            height: 6px;
            background-color: #e5e7eb;
            border-radius: 3px;
            overflow: hidden;
        }
        .progress-bar-fill {
            height: 100%;
            background-color: #10b981;
            transition: width 0.3s ease;
        }
        .toast {
            position: fixed;
            top: 20px;
            right: 20px;
            padding: 12px 20px;
            background-color: #10b981;
            color: white;
            border-radius: 6px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            transform: translateX(200%);
            transition: transform 0.3s ease;
            z-index: 1000;
        }
        .toast.show {
            transform: translateX(0);
        }
        .toast.error {
            background-color: #ef4444;
        }
        .back-to-top {
            position: fixed;
            bottom: 30px;
            right: 30px;
            width: 50px;
            height: 50px;
            border-radius: 50%;
            background-color: #3b82f6;
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            opacity: 0;
            transition: opacity 0.3s ease;
            z-index: 999;
        }
        .back-to-top.visible {
            opacity: 1;
        }
        .back-to-top:hover {
            background-color: #2563eb;
        }
    </style>
</head>
<body class="bg-gray-100">
    <div class="container mx-auto px-4 py-8">
        <div class="flex items-center justify-between mb-6">
            <div>
                <h1 class="text-3xl font-bold text-gray-800">WooCommerce Product Import CSV Generator</h1>
                <p class="text-gray-600 mt-1">Create CSV files for bulk importing products to WooCommerce</p>
            </div>
            <div class="flex items-center space-x-2">
                <span class="px-3 py-1 bg-blue-100 text-blue-800 rounded-full text-sm font-medium">
                    <i class="fas fa-box-open mr-1"></i>
                    <span id="productCount">0</span> products
                </span>
            </div>
        </div>
        
        <div class="bg-white rounded-lg shadow-md p-6 mb-6 border border-gray-200">
            <div class="flex justify-between items-center mb-4">
                <h2 class="text-xl font-semibold text-gray-700">Product List</h2>
                <button id="addProductBtn" class="px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 transition-colors">
                    <i class="fas fa-plus mr-2"></i>Add Product
                </button>
            </div>
            
            <div id="productList" class="space-y-4">
                <div class="text-center py-12 text-gray-500">
                    <i class="fas fa-box-open text-4xl mb-2"></i>
                    <p>No products added yet</p>
                    <button id="addFirstProductBtn" class="mt-4 px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 transition-colors">
                        <i class="fas fa-plus mr-2"></i>Add Your First Product
                    </button>
                </div>
            </div>
        </div>
        
        <div class="flex justify-end space-x-3 pt-4">
            <button id="resetBtn" class="px-4 py-2 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 bg-white hover:bg-gray-50 transition-colors">
                <i class="fas fa-trash-alt mr-2"></i>Reset All
            </button>
            <button id="generateBtn" class="px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-green-600 hover:bg-green-700 transition-colors">
                <i class="fas fa-file-csv mr-2"></i>Generate CSV
            </button>
        </div>
    </div>
    
    <!-- Back to top button -->
    <div id="backToTop" class="back-to-top">
        <i class="fas fa-arrow-up"></i>
    </div>
    
    <!-- Product Modal -->
    <div id="productModal" class="fixed z-10 inset-0 overflow-y-auto hidden">
        <div class="flex items-center justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0">
            <div class="fixed inset-0 transition-opacity" aria-hidden="true">
                <div class="absolute inset-0 bg-gray-500 opacity-75"></div>
            </div>
            <div class="inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-2xl sm:w-full">
                <div class="bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4">
                    <h3 class="text-lg font-medium text-gray-900 mb-4" id="modalTitle">Add New Product</h3>
                    <div class="mt-2">
                        <form id="productForm" class="space-y-4">
                            <input type="hidden" id="productId">
                            <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                                <div>
                                    <label for="productType" class="block text-sm font-medium text-gray-700">Product Type</label>
                                    <select id="productType" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
                                        <option value="simple">Simple</option>
                                        <option value="variable">Variable</option>
                                    </select>
                                </div>
                                <div>
                                    <label for="sku" class="block text-sm font-medium text-gray-700">SKU</label>
                                    <input type="text" id="sku" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
                                </div>
                            </div>
                            
                            <div>
                                <label for="productName" class="block text-sm font-medium text-gray-700">Product Name*</label>
                                <input type="text" id="productName" required class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
                            </div>
                            
                            <div>
                                <label for="shortDescription" class="block text-sm font-medium text-gray-700">Short Description</label>
                                <textarea id="shortDescription" rows="2" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500"></textarea>
                            </div>
                            
                            <div>
                                <label for="description" class="block text-sm font-medium text-gray-700">Description</label>
                                <textarea id="description" rows="4" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500"></textarea>
                            </div>
                            
                            <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                                <div>
                                    <label for="regularPrice" class="block text-sm font-medium text-gray-700">Regular Price</label>
                                    <input type="number" step="0.01" id="regularPrice" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
                                </div>
                                <div>
                                    <label for="salePrice" class="block text-sm font-medium text-gray-700">Sale Price</label>
                                    <input type="number" step="0.01" id="salePrice" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
                                </div>
                                <div>
                                    <label for="stock" class="block text-sm font-medium text-gray-700">Stock Quantity</label>
                                    <input type="number" id="stock" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
                                </div>
                            </div>
                            
                            <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                                <div>
                                    <label for="weight" class="block text-sm font-medium text-gray-700">Weight (kg)</label>
                                    <input type="number" step="0.01" id="weight" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
                                </div>
                                <div>
                                    <label for="category" class="block text-sm font-medium text-gray-700">Category Slug</label>
                                    <input type="text" id="category" placeholder="e.g. electronics" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
                                    <p class="text-xs text-gray-500 mt-1">Enter the category slug (e.g. electronics, clothing)</p>
                                </div>
                            </div>
                            
                            <div>
                                <label for="tags" class="block text-sm font-medium text-gray-700">Tags (comma separated)</label>
                                <input type="text" id="tags" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
                            </div>
                            
                            <div>
                                <label for="imageUrl" class="block text-sm font-medium text-gray-700">Image URL</label>
                                <input type="text" id="imageUrl" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
                            </div>
                            
                            <div id="variationsSection" class="hidden">
                                <div class="flex justify-between items-center mb-2">
                                    <label class="block text-sm font-medium text-gray-700">Weight Variations*</label>
                                    <button type="button" id="addVariationBtn" class="px-2 py-1 text-xs bg-blue-500 text-white rounded hover:bg-blue-600 transition-colors">
                                        <i class="fas fa-plus mr-1"></i>Add Variation
                                    </button>
                                </div>
                                <div id="variationsContainer" class="space-y-2">
                                    <!-- Variation items will be added here -->
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
                <div class="bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse">
                    <button type="button" id="saveProductBtn" class="w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-blue-600 text-base font-medium text-white hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 sm:ml-3 sm:w-auto sm:text-sm transition-colors">
                        Save Product
                    </button>
                    <button type="button" id="cancelProductBtn" class="mt-3 w-full inline-flex justify-center rounded-md border border-gray-300 shadow-sm px-4 py-2 bg-white text-base font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500 sm:mt-0 sm:ml-3 sm:w-auto sm:text-sm transition-colors">
                        Cancel
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!-- CSV Download Modal -->
    <div id="csvModal" class="fixed z-10 inset-0 overflow-y-auto hidden">
        <div class="flex items-center justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0">
            <div class="fixed inset-0 transition-opacity" aria-hidden="true">
                <div class="absolute inset-0 bg-gray-500 opacity-75"></div>
            </div>
            <div class="inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full">
                <div class="bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4">
                    <div class="sm:flex sm:items-start">
                        <div class="mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-green-100 sm:mx-0 sm:h-10 sm:w-10">
                            <i class="fas fa-file-csv text-green-600"></i>
                        </div>
                        <div class="mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left">
                            <h3 class="text-lg leading-6 font-medium text-gray-900" id="csvModalTitle">CSV Generated Successfully</h3>
                            <div class="mt-2">
                                <p class="text-sm text-gray-500">Your WooCommerce compatible CSV file is ready to download.</p>
                                <div class="mt-4">
                                    <div class="progress-bar">
                                        <div class="progress-bar-fill" style="width: 100%"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse">
                    <button type="button" id="downloadCsvBtn" class="w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-green-600 text-base font-medium text-white hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500 sm:ml-3 sm:w-auto sm:text-sm transition-colors">
                        <i class="fas fa-download mr-2"></i>Download CSV
                    </button>
                    <button type="button" id="closeCsvModalBtn" class="mt-3 w-full inline-flex justify-center rounded-md border border-gray-300 shadow-sm px-4 py-2 bg-white text-base font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500 sm:mt-0 sm:ml-3 sm:w-auto sm:text-sm transition-colors">
                        Close
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!-- Toast Notification -->
    <div id="toast" class="toast">
        <div class="flex items-center">
            <i class="fas fa-check-circle mr-2"></i>
            <span id="toastMessage">Operation completed successfully</span>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // Product data array
            let products = [];
            let currentProductId = 0;
            let editingProductId = null;
            let csvData = null;
            
            // DOM elements
            const addProductBtn = document.getElementById('addProductBtn');
            const addFirstProductBtn = document.getElementById('addFirstProductBtn');
            const productList = document.getElementById('productList');
            const productModal = document.getElementById('productModal');
            const productForm = document.getElementById('productForm');
            const saveProductBtn = document.getElementById('saveProductBtn');
            const cancelProductBtn = document.getElementById('cancelProductBtn');
            const resetBtn = document.getElementById('resetBtn');
            const generateBtn = document.getElementById('generateBtn');
            const productTypeSelect = document.getElementById('productType');
            const variationsSection = document.getElementById('variationsSection');
            const variationsContainer = document.getElementById('variationsContainer');
            const addVariationBtn = document.getElementById('addVariationBtn');
            const csvModal = document.getElementById('csvModal');
            const downloadCsvBtn = document.getElementById('downloadCsvBtn');
            const closeCsvModalBtn = document.getElementById('closeCsvModalBtn');
            const toast = document.getElementById('toast');
            const productCount = document.getElementById('productCount');
            const backToTop = document.getElementById('backToTop');
            
            // Event listeners
            addProductBtn.addEventListener('click', openAddProductModal);
            addFirstProductBtn.addEventListener('click', openAddProductModal);
            saveProductBtn.addEventListener('click', saveProduct);
            cancelProductBtn.addEventListener('click', closeModal);
            resetBtn.addEventListener('click', resetAll);
            generateBtn.addEventListener('click', generateCSV);
            productTypeSelect.addEventListener('change', toggleVariationsSection);
            addVariationBtn.addEventListener('click', addVariation);
            downloadCsvBtn.addEventListener('click', downloadCSV);
            closeCsvModalBtn.addEventListener('click', closeCsvModal);
            
            // Back to top button
            window.addEventListener('scroll', function() {
                if (window.pageYOffset > 300) {
                    backToTop.classList.add('visible');
                } else {
                    backToTop.classList.remove('visible');
                }
            });
            
            backToTop.addEventListener('click', function() {
                window.scrollTo({
                    top: 0,
                    behavior: 'smooth'
                });
            });
            
            // Functions
            function openAddProductModal() {
                editingProductId = null;
                document.getElementById('modalTitle').textContent = 'Add New Product';
                productForm.reset();
                variationsContainer.innerHTML = '';
                document.getElementById('productId').value = '';
                productModal.classList.remove('hidden');
            }
            
            function openEditProductModal(productId) {
                const product = products.find(p => p.id === productId);
                if (!product) return;
                
                editingProductId = productId;
                document.getElementById('modalTitle').textContent = 'Edit Product';
                document.getElementById('productId').value = product.id;
                document.getElementById('productType').value = product.type;
                document.getElementById('sku').value = product.sku || '';
                document.getElementById('productName').value = product.name;
                document.getElementById('shortDescription').value = product.shortDescription || '';
                document.getElementById('description').value = product.description || '';
                document.getElementById('regularPrice').value = product.regularPrice || '';
                document.getElementById('salePrice').value = product.salePrice || '';
                document.getElementById('stock').value = product.stock || '';
                document.getElementById('weight').value = product.weight || '';
                document.getElementById('category').value = product.category || '';
                document.getElementById('tags').value = product.tags || '';
                document.getElementById('imageUrl').value = product.imageUrl || '';
                
                // Handle variations
                variationsContainer.innerHTML = '';
                if (product.type === 'variable' && product.variations && product.variations.length > 0) {
                    product.variations.forEach(variation => {
                        addVariation(variation.weight, variation.price);
                    });
                }
                
                toggleVariationsSection();
                productModal.classList.remove('hidden');
            }
            
            function closeModal() {
                productModal.classList.add('hidden');
            }
            
            function closeCsvModal() {
                csvModal.classList.add('hidden');
            }
            
            function toggleVariationsSection() {
                if (productTypeSelect.value === 'variable') {
                    variationsSection.classList.remove('hidden');
                } else {
                    variationsSection.classList.add('hidden');
                }
            }
            
            function addVariation(weight = '', price = '') {
                const variationId = Date.now();
                const variationItem = document.createElement('div');
                variationItem.className = 'variation-item p-3 border rounded-md';
                variationItem.dataset.id = variationId;
                variationItem.innerHTML = `
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-3">
                        <div>
                            <label class="block text-xs font-medium text-gray-500">Weight (kg)*</label>
                            <input type="number" step="0.01" class="variation-weight w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500" value="${weight}" required>
                        </div>
                        <div>
                            <label class="block text-xs font-medium text-gray-500">Price*</label>
                            <input type="number" step="0.01" class="variation-price w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500" value="${price}" required>
                        </div>
                    </div>
                    <div class="mt-2 flex justify-end">
                        <button type="button" class="remove-variation text-xs text-red-500 hover:text-red-700 transition-colors">
                            <i class="fas fa-trash mr-1"></i>Remove
                        </button>
                    </div>
                `;
                variationsContainer.appendChild(variationItem);
                
                // Add event listener to remove button
                variationItem.querySelector('.remove-variation').addEventListener('click', function() {
                    variationsContainer.removeChild(variationItem);
                });
            }
            
            function saveProduct() {
                const productId = document.getElementById('productId').value;
                const productType = document.getElementById('productType').value;
                const sku = document.getElementById('sku').value;
                const productName = document.getElementById('productName').value;
                const shortDescription = document.getElementById('shortDescription').value;
                const description = document.getElementById('description').value;
                const regularPrice = document.getElementById('regularPrice').value;
                const salePrice = document.getElementById('salePrice').value;
                const stock = document.getElementById('stock').value;
                const weight = document.getElementById('weight').value;
                const category = document.getElementById('category').value;
                const tags = document.getElementById('tags').value;
                const imageUrl = document.getElementById('imageUrl').value;
                
                // Collect variations if product is variable
                let variations = [];
                if (productType === 'variable') {
                    const variationItems = variationsContainer.querySelectorAll('.variation-item');
                    variationItems.forEach(item => {
                        const weight = item.querySelector('.variation-weight').value;
                        const price = item.querySelector('.variation-price').value;
                        if (weight && price) {
                            variations.push({
                                weight: weight,
                                price: price
                            });
                        }
                    });
                }
                
                // Validate required fields
                if (!productName) {
                    showToast('Product name is required', true);
                    return;
                }
                
                if (productType === 'variable' && variations.length === 0) {
                    showToast('Please add at least one weight variation for variable products', true);
                    return;
                }
                
                // Create or update product
                const productData = {
                    id: productId || ++currentProductId,
                    type: productType,
                    sku: sku,
                    name: productName,
                    shortDescription: shortDescription,
                    description: description,
                    regularPrice: regularPrice,
                    salePrice: salePrice,
                    stock: stock,
                    weight: weight,
                    category: category,
                    tags: tags,
                    imageUrl: imageUrl,
                    variations: variations
                };
                
                if (editingProductId !== null) {
                    // Update existing product
                    const index = products.findIndex(p => p.id === editingProductId);
                    if (index !== -1) {
                        products[index] = productData;
                        showToast('Product updated successfully');
                    }
                } else {
                    // Add new product
                    products.push(productData);
                    showToast('Product added successfully');
                }
                
                renderProductList();
                closeModal();
            }
            
            function renderProductList() {
                productList.innerHTML = '';
                
                if (products.length === 0) {
                    productList.innerHTML = `
                        <div class="text-center py-12 text-gray-500">
                            <i class="fas fa-box-open text-4xl mb-2"></i>
                            <p>No products added yet</p>
                            <button id="addFirstProductBtn" class="mt-4 px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 transition-colors">
                                <i class="fas fa-plus mr-2"></i>Add Your First Product
                            </button>
                        </div>
                    `;
                    
                    // Re-add event listener for the new button
                    document.getElementById('addFirstProductBtn').addEventListener('click', openAddProductModal);
                    
                    productCount.textContent = '0';
                    return;
                }
                
                productCount.textContent = products.length;
                
                products.forEach(product => {
                    const productCard = document.createElement('div');
                    productCard.className = 'bg-white border rounded-lg overflow-hidden shadow-sm hover:shadow-md transition-shadow border-gray-200';
                    productCard.innerHTML = `
                        <div class="p-4">
                            <div class="flex justify-between items-start">
                                <div>
                                    <h3 class="font-medium text-gray-900">${product.name}</h3>
                                    <p class="text-sm text-gray-500 mt-1">
                                        ${product.type === 'simple' ? 'Simple Product' : 'Variable Product'}
                                        ${product.sku ? `• SKU: ${product.sku}` : ''}
                                    </p>
                                </div>
                                <div class="flex space-x-2">
                                    <button class="edit-product p-1 text-blue-500 hover:text-blue-700 transition-colors" data-id="${product.id}" title="Edit">
                                        <i class="fas fa-edit"></i>
                                    </button>
                                    <button class="duplicate-product p-1 text-purple-500 hover:text-purple-700 transition-colors" data-id="${product.id}" title="Duplicate">
                                        <i class="fas fa-copy"></i>
                                    </button>
                                    <button class="delete-product p-1 text-red-500 hover:text-red-700 transition-colors" data-id="${product.id}" title="Delete">
                                        <i class="fas fa-trash"></i>
                                    </button>
                                </div>
                            </div>
                            ${product.type === 'variable' ? `
                            <div class="mt-3">
                                <p class="text-xs font-medium text-gray-500">Weight Variations:</p>
                                <div class="flex flex-wrap gap-1 mt-1">
                                    ${product.variations.map(v => `
                                        <span class="text-xs bg-gray-100 px-2 py-1 rounded">${v.weight}kg (${v.price}৳)</span>
                                    `).join('')}
                                </div>
                            </div>
                            ` : ''}
                            ${product.regularPrice ? `
                            <div class="mt-2">
                                <span class="text-sm font-medium">Price: ${product.regularPrice}৳</span>
                                ${product.salePrice ? `<span class="text-sm text-gray-500 ml-2 line-through">${product.salePrice}৳</span>` : ''}
                            </div>
                            ` : ''}
                            ${product.category ? `
                            <div class="mt-2">
                                <span class="text-xs bg-gray-100 px-2 py-1 rounded">Category: ${product.category}</span>
                            </div>
                            ` : ''}
                        </div>
                    `;
                    productList.appendChild(productCard);
                });
                
                // Add event listeners to edit, duplicate and delete buttons
                document.querySelectorAll('.edit-product').forEach(btn => {
                    btn.addEventListener('click', function() {
                        openEditProductModal(parseInt(this.dataset.id));
                    });
                });
                
                document.querySelectorAll('.duplicate-product').forEach(btn => {
                    btn.addEventListener('click', function() {
                        duplicateProduct(parseInt(this.dataset.id));
                    });
                });
                
                document.querySelectorAll('.delete-product').forEach(btn => {
                    btn.addEventListener('click', function() {
                        deleteProduct(parseInt(this.dataset.id));
                    });
                });
            }
            
            function duplicateProduct(productId) {
                const product = products.find(p => p.id === productId);
                if (!product) return;
                
                // Create a deep copy of the product
                const productCopy = JSON.parse(JSON.stringify(product));
                productCopy.id = ++currentProductId;
                productCopy.name = `${productCopy.name} (Copy)`;
                
                // Add the duplicated product
                products.push(productCopy);
                renderProductList();
                showToast('Product duplicated successfully');
            }
            
            function deleteProduct(productId) {
                if (confirm('Are you sure you want to delete this product?')) {
                    products = products.filter(p => p.id !== productId);
                    renderProductList();
                    showToast('Product deleted successfully');
                }
            }
            
            function resetAll() {
                if (products.length === 0 || confirm('Are you sure you want to reset all products? This cannot be undone.')) {
                    products = [];
                    currentProductId = 0;
                    renderProductList();
                    showToast('All products have been reset');
                }
            }
            
            function generateCSV() {
                if (products.length === 0) {
                    showToast('No products to generate CSV', true);
                    return;
                }
                
                // Prepare CSV data
                const csvRows = [];
                
                // Add header row
                const headers = [
                    'ID', 'Type', 'SKU', 'Name', 'Published', 'Is featured?', 'Visibility in catalog', 
                    'Short description', 'Description', 'Date sale price starts', 'Date sale price ends', 
                    'Tax status', 'Tax class', 'In stock?', 'Stock', 'Backorders', 'Sold individually?', 
                    'Weight (kg)', 'Length (cm)', 'Width (cm)', 'Height (cm)', 'Allow customer reviews?', 
                    'Purchase note', 'Sale price', 'Regular price', 'Categories', 'Tags', 'Shipping class', 
                    'Images', 'Download limit', 'Download expiry days', 'Parent', 'Grouped products', 
                    'Upsells', 'Cross-sells', 'External URL', 'Button text', 'Position', 'Attribute 1 name', 
                    'Attribute 1 value(s)', 'Attribute 1 visible', 'Attribute 1 global', 'Attribute 2 name', 
                    'Attribute 2 value(s)', 'Attribute 2 visible', 'Attribute 2 global', 'Meta: _wpcom_is_markdown', 
                    'Download 1 name', 'Download 1 URL', 'Download 2 name', 'Download 2 URL'
                ];
                
                csvRows.push(headers);
                
                // Add product rows
                products.forEach(product => {
                    if (product.type === 'simple') {
                        // Simple product
                        const row = [
                            '', // ID
                            'simple', // Type
                            product.sku || '', // SKU
                            product.name, // Name
                            '1', // Published
                            '0', // Is featured?
                            'visible', // Visibility in catalog
                            product.shortDescription || '', // Short description
                            product.description || '', // Description
                            '', // Date sale price starts
                            '', // Date sale price ends
                            'taxable', // Tax status
                            '', // Tax class
                            product.stock ? '1' : '0', // In stock?
                            product.stock || '', // Stock
                            '0', // Backorders
                            '0', // Sold individually?
                            product.weight || '', // Weight (kg)
                            '', // Length (cm)
                            '', // Width (cm)
                            '', // Height (cm)
                            '1', // Allow customer reviews?
                            '', // Purchase note
                            product.salePrice || '', // Sale price
                            product.regularPrice || '', // Regular price
                            product.category ? `${product.category}:${product.category}` : '', // Categories
                            product.tags || '', // Tags
                            '', // Shipping class
                            product.imageUrl || '', // Images
                            '', // Download limit
                            '', // Download expiry days
                            '', // Parent
                            '', // Grouped products
                            '', // Upsells
                            '', // Cross-sells
                            '', // External URL
                            '', // Button text
                            '0', // Position
                            '', // Attribute 1 name
                            '', // Attribute 1 value(s)
                            '0', // Attribute 1 visible
                            '0', // Attribute 1 global
                            '', // Attribute 2 name
                            '', // Attribute 2 value(s)
                            '0', // Attribute 2 visible
                            '0', // Attribute 2 global
                            '0', // Meta: _wpcom_is_markdown
                            '', // Download 1 name
                            '', // Download 1 URL
                            '', // Download 2 name
                            '', // Download 2 URL
                        ];
                        
                        csvRows.push(row);
                    } else if (product.type === 'variable') {
                        // Variable product - first add the parent product
                        const parentRow = [
                            '', // ID
                            'variable', // Type
                            product.sku || '', // SKU
                            product.name, // Name
                            '1', // Published
                            '0', // Is featured?
                            'visible', // Visibility in catalog
                            product.shortDescription || '', // Short description
                            product.description || '', // Description
                            '', // Date sale price starts
                            '', // Date sale price ends
                            'taxable', // Tax status
                            '', // Tax class
                            '1', // In stock?
                            '', // Stock
                            '0', // Backorders
                            '0', // Sold individually?
                            '', // Weight (kg)
                            '', // Length (cm)
                            '', // Width (cm)
                            '', // Height (cm)
                            '1', // Allow customer reviews?
                            '', // Purchase note
                            '', // Sale price
                            '', // Regular price
                            product.category ? `${product.category}:${product.category}` : '', // Categories
                            product.tags || '', // Tags
                            '', // Shipping class
                            product.imageUrl || '', // Images
                            '', // Download limit
                            '', // Download expiry days
                            '', // Parent
                            '', // Grouped products
                            '', // Upsells
                            '', // Cross-sells
                            '', // External URL
                            '', // Button text
                            '0', // Position
                            'Weight', // Attribute 1 name
                            product.variations.map(v => v.weight).join('|'), // Attribute 1 value(s)
                            '1', // Attribute 1 visible
                            '1', // Attribute 1 global
                            '', // Attribute 2 name
                            '', // Attribute 2 value(s)
                            '0', // Attribute 2 visible
                            '0', // Attribute 2 global
                            '0', // Meta: _wpcom_is_markdown
                            '', // Download 1 name
                            '', // Download 1 URL
                            '', // Download 2 name
                            '', // Download 2 URL
                        ];
                        
                        csvRows.push(parentRow);
                        
                        // Then add each variation
                        product.variations.forEach((variation, index) => {
                            const variationRow = [
                                '', // ID
                                'variation', // Type
                                product.sku ? `${product.sku}-${index + 1}` : '', // SKU
                                `${product.name} (${variation.weight}kg)`, // Name
                                '1', // Published
                                '0', // Is featured?
                                'visible', // Visibility in catalog
                                '', // Short description
                                '', // Description
                                '', // Date sale price starts
                                '', // Date sale price ends
                                'taxable', // Tax status
                                '', // Tax class
                                '1', // In stock?
                                '', // Stock
                                '0', // Backorders
                                '0', // Sold individually?
                                variation.weight, // Weight (kg)
                                '', // Length (cm)
                                '', // Width (cm)
                                '', // Height (cm)
                                '1', // Allow customer reviews?
                                '', // Purchase note
                                '', // Sale price
                                variation.price, // Regular price
                                '', // Categories
                                '', // Tags
                                '', // Shipping class
                                '', // Images
                                '', // Download limit
                                '', // Download expiry days
                                product.name, // Parent
                                '', // Grouped products
                                '', // Upsells
                                '', // Cross-sells
                                '', // External URL
                                '', // Button text
                                '0', // Position
                                'Weight', // Attribute 1 name
                                variation.weight, // Attribute 1 value(s)
                                '1', // Attribute 1 visible
                                '1', // Attribute 1 global
                                '', // Attribute 2 name
                                '', // Attribute 2 value(s)
                                '0', // Attribute 2 visible
                                '0', // Attribute 2 global
                                '0', // Meta: _wpcom_is_markdown
                                '', // Download 1 name
                                '', // Download 1 URL
                                '', // Download 2 name
                                '', // Download 2 URL
                            ];
                            
                            csvRows.push(variationRow);
                        });
                    }
                });
                
                // Convert to CSV string
                csvData = Papa.unparse(csvRows);
                
                // Show CSV download modal
                csvModal.classList.remove('hidden');
            }
            
            function downloadCSV() {
                if (!csvData) return;
                
                const blob = new Blob([csvData], { type: 'text/csv;charset=utf-8;' });
                const url = URL.createObjectURL(blob);
                const link = document.createElement('a');
                link.setAttribute('href', url);
                link.setAttribute('download', 'woocommerce_products_import.csv');
                link.style.visibility = 'hidden';
                document.body.appendChild(link);
                link.click();
                document.body.removeChild(link);
                
                showToast('CSV downloaded successfully');
                closeCsvModal();
            }
            
            function showToast(message, isError = false) {
                const toastMessage = document.getElementById('toastMessage');
                toastMessage.textContent = message;
                
                if (isError) {
                    toast.classList.add('error');
                } else {
                    toast.classList.remove('error');
                }
                
                toast.classList.add('show');
                
                setTimeout(() => {
                    toast.classList.remove('show');
                }, 3000);
            }
            
            // Initialize
            renderProductList();
        });
    </script>
    <footer class="text-center text-gray-500 text-sm mt-8">
        <p>WC Product CSV Generator App | Created by <a href="https://github.com/almahmudbd/" target="_blank" class="text-blue-500 hover:text-blue-700">almahmud</a></p>
    </footer>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=almahmud/wc-product-cvs-generator" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>