File size: 7,117 Bytes
3afcae2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Code Editor - CodeCraft AI</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ace.js"></script>
    <script src="https://unpkg.com/feather-icons"></script>
    <style>
        #editor { 
            position: absolute;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
        }
        .editor-container {
            height: 70vh;
            position: relative;
        }
    </style>
</head>
<body class="bg-gray-100">
    <header class="bg-gray-900 text-white p-4">
        <div class="container mx-auto flex justify-between items-center">
            <div class="flex items-center">
                <i data-feather="code" class="mr-2"></i>
                <h1 class="text-xl font-bold">CodeCraft AI Editor</h1>
            </div>
            <div class="flex items-center space-x-4">
                <div class="bg-purple-600 px-3 py-1 rounded-full text-sm">
                    Credits: <span id="credit-counter">100,000</span>
                </div>
                <button id="ai-assist" class="px-3 py-1 bg-green-600 hover:bg-green-700 rounded text-sm">
                    AI Assist (50,000 credits)
                </button>
                <a href="pricing.html" class="px-3 py-1 bg-yellow-600 hover:bg-yellow-700 rounded text-sm">
                    Get More Credits
                </a>
            </div>
        </div>
    </header>

    <div class="container mx-auto p-4">
        <div class="grid grid-cols-1 lg:grid-cols-2 gap-4">
            <div class="bg-white rounded-lg shadow-lg overflow-hidden">
                <div class="p-3 bg-gray-800 text-white flex justify-between">
                    <div class="flex space-x-2">
                        <button class="px-2 py-1 bg-gray-700 rounded text-xs active-tab" data-lang="html">HTML</button>
                        <button class="px-2 py-1 bg-gray-700 rounded text-xs" data-lang="css">CSS</button>
                        <button class="px-2 py-1 bg-gray-700 rounded text-xs" data-lang="javascript">JS</button>
                    </div>
                    <button id="run-code" class="px-3 py-1 bg-purple-600 hover:bg-purple-700 rounded text-xs">
                        Run (20,000 credits)
                    </button>
                </div>
                <div class="editor-container">
                    <div id="editor"></div>
                </div>
            </div>
            <div class="bg-white rounded-lg shadow-lg overflow-hidden">
                <div class="p-3 bg-gray-800 text-white">
                    <h3 class="text-sm font-bold">Output</h3>
                </div>
                <iframe id="output-frame" class="w-full h-full min-h-[70vh] border-0"></iframe>
            </div>
        </div>

        <div class="mt-4 bg-white rounded-lg shadow-lg overflow-hidden hidden" id="ai-panel">
            <div class="p-3 bg-gray-800 text-white">
                <h3 class="text-sm font-bold">AI Coding Assistant</h3>
            </div>
            <div class="p-4">
                <textarea id="ai-prompt" class="w-full p-2 border rounded mb-2" placeholder="Describe what you want the AI to help with..."></textarea>
                <button id="ai-submit" class="px-4 py-2 bg-green-600 hover:bg-green-700 text-white rounded">
                    Generate Code (50,000 credits)
                </button>
                <div id="ai-response" class="mt-4 p-2 bg-gray-100 rounded hidden"></div>
            </div>
        </div>
    </div>

    <script>
        feather.replace();
        
        // Initialize editor
        const editor = ace.edit("editor");
        editor.setTheme("ace/theme/monokai");
        editor.session.setMode("ace/mode/html");
        editor.setValue(`<!DOCTYPE html>
<html>
<head>
    <title>My Project</title>
    <style>
        body {
            font-family: Arial;
            text-align: center;
            padding: 20px;
        }
        h1 {
            color: #6366f1;
        }
    </style>
</head>
<body>
    <h1>Hello CodeCraft!</h1>
    <p>Start coding here...</p>
    
    <script>
        console.log('Welcome to CodeCraft AI Editor');
    </script>
</body>
</html>`, -1);

        // Tab switching
        document.querySelectorAll('[data-lang]').forEach(tab => {
            tab.addEventListener('click', () => {
                document.querySelector('.active-tab').classList.remove('active-tab');
                tab.classList.add('active-tab');
                const mode = `ace/mode/${tab.dataset.lang}`;
                editor.session.setMode(mode);
            });
        });

        // Run code
        document.getElementById('run-code').addEventListener('click', () => {
            const credits = parseInt(document.getElementById('credit-counter').textContent);
            if (credits < 20000) {
                alert('Not enough credits! Please upgrade to CA Plus.');
                return;
            }
            
            const code = editor.getValue();
            const frame = document.getElementById('output-frame');
            frame.srcdoc = code;
            
            // Deduct credits
            document.getElementById('credit-counter').textContent = credits - 20000;
        });

        // AI Assist
        document.getElementById('ai-assist').addEventListener('click', () => {
            document.getElementById('ai-panel').classList.toggle('hidden');
        });

        document.getElementById('ai-submit').addEventListener('click', () => {
            const credits = parseInt(document.getElementById('credit-counter').textContent);
            if (credits < 50000) {
                alert('Not enough credits for AI assist! Please upgrade to CA Plus.');
                return;
            }
            
            const prompt = document.getElementById('ai-prompt').value;
            if (!prompt.trim()) {
                alert('Please enter a prompt for the AI');
                return;
            }
            
            // Simulate AI response
            document.getElementById('ai-response').classList.remove('hidden');
            document.getElementById('ai-response').innerHTML = `
                <p class="text-green-600 font-bold">AI Response:</p>
                <p>Here's a suggested implementation based on your request:</p>
                <pre class="bg-gray-200 p-2 mt-2 rounded">${prompt.includes('button') ? 
                    '<button class="px-4 py-2 bg-purple-600 text-white rounded">New Button</button>' : 
                    '// AI generated code would appear here'}</pre>
                <button class="mt-2 px-3 py-1 bg-blue-600 text-white rounded text-sm">
                    Insert into Editor
                </button>
            `;
            
            // Deduct credits
            document.getElementById('credit-counter').textContent = credits - 50000;
        });
    </script>
</body>
</html>