File size: 8,404 Bytes
2a196ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// ============================================================================
// FRITREE ENTERPRISE PLATFORM - DEVELOPMENT TESTING & MOCK DATA UTILITY
// File: modules/mockData.js (Complete & Hardened Implementation)
// ============================================================================

(function(global) {
    'use strict';

    /**

     * Generates a randomized date within the last 7 days

     */
    function getRandomDateInLastWeek() {
        const now = new Date();
        const pastDays = Math.floor(Math.random() * 7);
        const hours = Math.floor(Math.random() * 24);
        const minutes = Math.floor(Math.random() * 60);
        now.setDate(now.getDate() - pastDays);
        now.setHours(hours, minutes, 0, 0);
        return now.toISOString();
    }

    /**

     * Populates mock categories, assets, and campaign history logs into local storage.

     * Use this to instantly populate the Analytics graphs, Dashboard metrics, and 

     * Campaign History table.

     */
    async function injectMockWorkspaceData() {
        try {
            console.log("[Fritree Mock Utility] Preparing data payload injection...");

            // 1. Generate Mock Categories
            const mockCategories = [
                { id: "cat_realestate", name: "Real Estate Promotions", color: "#1877f2", parentId: null },
                { id: "cat_ecom", name: "E-Commerce Deals", color: "#10b981", parentId: null },
                { id: "cat_tech", name: "Software & Technology", color: "#8b5cf6", parentId: null },
                { id: "cat_clearance", name: "Seasonal Clearance", color: "#f59e0b", parentId: null }
            ];

            // 2. Generate Mock Content Library Assets
            const mockAssets = [
                {
                    uuid: "cl_asset_001",
                    title: "Modern Apartment Showcase",
                    textMain: "Stunning 2-bedroom luxury apartments available now in the downtown district! {High ceilings|Floor-to-ceiling windows} with premium finishes and {amazing views|spacious balconies}. Contact us today to schedule an exclusive tour! #RealEstate #LuxuryLiving",
                    textSec: "Luxury downtown living awaits you. Schedule a viewing today!",
                    status: "Active",
                    categories: ["cat_realestate"],
                    keywords: ["apartments", "luxury", "rent"],
                    priority: 80,
                    expireDate: "",
                    cooldownMinutes: 15,
                    notes: "High conversion rate on urban development groups",
                    media: [],
                    creationDate: getRandomDateInLastWeek(),
                    modifiedDate: new Date().toISOString(),
                    stats: { usage: 12, success: 10, fail: 1, pending: 1, realInteractions: 45 },
                    scores: { quality: 85, performance: 83 },
                    lastPublished: getRandomDateInLastWeek()
                },
                {
                    uuid: "cl_asset_002",
                    title: "Flash Sale 50% Off Promo",
                    textMain: "⚡ FLASH SALE! Get 50% off on all items across our store for the next {24 hours|12 hours} only! Use code {FLASH50|HALFPRICE} at checkout. {Don't miss out!|Order now before stocks run out!}",
                    textSec: "50% off sitewide. Limited time only!",
                    status: "Active",
                    categories: ["cat_ecom", "cat_clearance"],
                    keywords: ["sale", "promo", "discount"],
                    priority: 95,
                    expireDate: "",
                    cooldownMinutes: 30,
                    notes: "High-priority flash promotion",
                    media: [],
                    creationDate: getRandomDateInLastWeek(),
                    modifiedDate: new Date().toISOString(),
                    stats: { usage: 24, success: 20, fail: 2, pending: 2, realInteractions: 112 },
                    scores: { quality: 90, performance: 83 },
                    lastPublished: getRandomDateInLastWeek()
                },
                {
                    uuid: "cl_asset_003",
                    title: "SaaS Automation Platform launch",
                    textMain: "Scale up your workflow with our advanced {no-code automation engine|all-in-one productivity suite}. Free 14-day trial, {no credit card required|instant setup}. Discover why thousands of businesses trust us.",
                    textSec: "Automate your daily operational workflows easily.",
                    status: "Active",
                    categories: ["cat_tech"],
                    keywords: ["saas", "software", "productivity"],
                    priority: 60,
                    expireDate: "",
                    cooldownMinutes: 10,
                    notes: "Excellent for professional B2B communities",
                    media: [],
                    creationDate: getRandomDateInLastWeek(),
                    modifiedDate: new Date().toISOString(),
                    stats: { usage: 8, success: 6, fail: 1, pending: 1, realInteractions: 14 },
                    scores: { quality: 75, performance: 75 },
                    lastPublished: getRandomDateInLastWeek()
                }
            ];

            // 3. Generate Historical Campaign Reports
            const mockHistory = [];
            const platforms = ['facebook', 'whatsapp'];

            for (let i = 1; i <= 15; i++) {
                const platform = platforms[Math.floor(Math.random() * platforms.length)];
                const isFb = platform === 'facebook';
                const total = Math.floor(Math.random() * 25) + 5;
                const success = Math.round(total * (0.7 + Math.random() * 0.3));
                const failed = total - success;

                const campaignDate = new Date();
                campaignDate.setDate(campaignDate.getDate() - Math.floor(Math.random() * 7));

                const logs = [];
                for (let j = 0; j < total; j++) {
                    logs.push({
                        groupId: isFb ? `1234567890${j}` : `+1555000000${j}`,
                        status: j < success ? 'success' : 'failed',
                        error: j < success ? null : 'Group post submission restricted',
                        postUrl: j < success ? `https://www.facebook.com/groups/posts/${Date.now() + j}/` : null
                    });
                }

                const mockHistoryRecord = {
                    id: 'hist_mock_' + i + '_' + Date.now(),
                    name: isFb ? `Historical Campaign Wave #${i}` : 'Bulk Product Announcement',
                    date: campaignDate.toISOString(),
                    platform: platform,
                    type: Math.random() > 0.5 ? 'Manual' : 'Scheduled',
                    status: 'Completed',
                    isLibraryMode: Math.random() > 0.5,
                    config: { text: "Sample marketing campaign test payload.", images: [] },
                    stats: { total: total, success: success, pending: 0, failed: failed },
                    logs: logs
                };

                mockHistory.unshift(mockHistoryRecord);
            }

            // Save elements securely using FritreeStorage (which handles encryption)
            await FritreeStorage.set('local_content_library', mockAssets);
            await FritreeStorage.set('local_content_categories', mockCategories);
            await FritreeStorage.set('campaignHistoryData', mockHistory);

            if (typeof window.addLog === 'function') {
                window.addLog("Content Library and campaign history successfully seeded with metrics data.", "success");
            }

            alert("Diagnostics Workspace Environment Mock Data Generated successfully! Reloading to sync widgets...");
            window.location.reload();

        } catch (e) {
            console.error("Failed to generate and commit mock data.", e);
        }
    }

    // Exported Helper APIs
    global.FritreeDeveloperTools = {
        seedMockData: injectMockWorkspaceData
    };

})(typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : this);