File size: 11,975 Bytes
227c43a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import React, { useState, useMemo, useCallback } from 'react';
import { motion } from 'framer-motion';
import { 
  Activity, 
  BarChart3, 
  FileText, 
  Download, 
  Share2, 
  Maximize2,
  Copy,
  CheckCircle2
} from 'lucide-react';
import PropTypes from 'prop-types';
import Button from '../../design-system/components/Button';
import Card from '../../design-system/components/Card';
import SimpleTabs from './SimpleTabs';
import QuantumVisualization from './QuantumVisualization';

const EnhancedPluginResultsPanel = ({ result, loading, onExport, onShare }) => {
  const [isFullscreen, setIsFullscreen] = useState(false);
  const [copied, setCopied] = useState(false);

  const handleCopyData = useCallback(async () => {
    if (!result || !result.output) return;
    
    try {
      await navigator.clipboard.writeText(JSON.stringify(result.output, null, 2));
      setCopied(true);
      setTimeout(() => setCopied(false), 2000);
    } catch (err) {
      console.error('Failed to copy data:', err);
    }
  }, [result]);

  const tabs = useMemo(() => {
    if (!result) {
      return [
        {
          id: 'visualization',
          label: 'Visualization',
          icon: <Activity size={16} />,
          available: true,
          content: <QuantumVisualization result={null} />
        }
      ];
    }

    return [
      {
        id: 'visualization',
        label: 'Visualization',
        icon: <Activity size={16} />,
        available: true,
        content: <QuantumVisualization result={result} />
      },
      {
        id: 'data',
        label: 'Raw Data',
        icon: <BarChart3 size={16} />,
        available: !!(result && result.output),
        content: (
          <motion.div

            initial={{ opacity: 0 }}

            animate={{ opacity: 1 }}

            className="space-y-4"

          >

            <div className="flex items-center justify-between">

              <h4 className="text-sm font-medium text-neutral-700">Raw Output Data</h4>

              <Button

                variant="ghost"

                size="sm"

                onClick={handleCopyData}

                icon={copied ? <CheckCircle2 size={14} /> : <Copy size={14} />}

              >

                {copied ? 'Copied!' : 'Copy JSON'}

              </Button>

            </div>

            

            <div className="bg-neutral-50 rounded-lg p-4 max-h-96 overflow-auto">

              <pre className="text-sm text-neutral-800 whitespace-pre-wrap">

                {result && result.output ? JSON.stringify(result.output, null, 2) : 'No data available'}

              </pre>

            </div>

          </motion.div>
        )
      },
      {
        id: 'log',
        label: 'Process Log',
        icon: <FileText size={16} />,
        available: !!(result && result.log),
        content: (
          <motion.div

            initial={{ opacity: 0 }}

            animate={{ opacity: 1 }}

            className="space-y-4"

          >

            <h4 className="text-sm font-medium text-neutral-700">Process Log</h4>

            

            <div className="bg-neutral-900 rounded-lg p-4 max-h-96 overflow-auto">

              <pre className="text-sm text-green-400 font-mono whitespace-pre-wrap">

                {(result && result.log) ? result.log : 'No log data available.'}

              </pre>

            </div>

          </motion.div>
        )
      },
    ].filter(tab => tab.available);
  }, [result, copied, handleCopyData]);

  const handleExport = () => {
    if (!result?.output) return;
    
    const dataStr = JSON.stringify(result.output, null, 2);
    const dataBlob = new Blob([dataStr], { type: 'application/json' });
    const url = URL.createObjectURL(dataBlob);
    const link = document.createElement('a');
    link.href = url;
    link.download = `quantum-simulation-${Date.now()}.json`;
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
    URL.revokeObjectURL(url);
    
    onExport?.(result);
  };

  if (loading) {
    return (
      <Card variant="elevated" padding="lg">

        <div className="flex flex-col items-center justify-center py-12">

          <motion.div

            animate={{ rotate: 360 }}

            transition={{ duration: 2, repeat: Infinity, ease: "linear" }}

            className="mb-4"

          >

            <Activity size={48} className="text-primary-500" />

          </motion.div>

          <motion.h3

            initial={{ opacity: 0 }}

            animate={{ opacity: 1 }}

            className="text-lg font-semibold text-neutral-900 mb-2"

          >

            Processing Quantum Simulation

          </motion.h3>

          <motion.p

            initial={{ opacity: 0 }}

            animate={{ opacity: 1 }}

            transition={{ delay: 0.2 }}

            className="text-neutral-600 text-center max-w-md"

          >

            Your quantum computation is being executed. This may take a few moments depending on the complexity.

          </motion.p>

          

          {/* Animated progress indicators */}

          <div className="flex gap-2 mt-6">

            {[0, 1, 2].map((i) => (

              <motion.div

                key={i}

                animate={{ 

                  scale: [1, 1.2, 1],

                  opacity: [0.3, 1, 0.3]

                }}

                transition={{ 

                  duration: 1.5, 

                  repeat: Infinity,

                  delay: i * 0.2

                }}

                className="w-2 h-2 bg-primary-500 rounded-full"

              />

            ))}

          </div>

        </div>

      </Card>
    );
  }

  if (!result) {
    return (
      <Card variant="outlined" padding="lg">

        <div className="flex flex-col items-center justify-center py-12 text-neutral-500">

          <Activity size={48} className="mb-4 opacity-50" />

          <h3 className="text-lg font-semibold mb-2">Ready for Simulation</h3>

          <p className="text-center max-w-md">

            Configure your parameters and run a simulation to see quantum results and visualizations.

          </p>

        </div>

      </Card>
    );
  }

  return (
    <motion.div

      initial={{ opacity: 0, y: 20 }}

      animate={{ opacity: 1, y: 0 }}

      transition={{ duration: 0.5 }}

      className={isFullscreen ? 'fixed inset-4 z-50 bg-base-100 dark:bg-base-200 rounded-xl shadow-2xl' : ''}

    >

      <Card variant="elevated" padding="none" className="h-full">

        <div className="p-4 sm:p-6 border-b border-neutral-200 dark:border-neutral-700 bg-base-100 dark:bg-base-200">

          {/* Main Header */}

          <div className="flex items-center justify-between mb-3 sm:mb-0">

            <div className="flex items-center gap-2 sm:gap-3 min-w-0 flex-1">

              <div className="w-8 h-8 sm:w-10 sm:h-10 rounded-lg bg-gradient-to-br from-primary-500 to-secondary-500 flex items-center justify-center flex-shrink-0">

                <Activity size={16} className="sm:w-5 sm:h-5 text-white" />

              </div>

              <div className="min-w-0 flex-1">

                <h3 className="text-base sm:text-lg font-semibold text-neutral-900 truncate">

                  Simulation Results

                </h3>

                <p className="text-xs sm:text-sm text-neutral-600 hidden sm:block">

                  Quantum computation completed successfully

                </p>

              </div>

            </div>

            

            {/* Mobile: Only show fullscreen button */}

            <div className="sm:hidden flex-shrink-0">

              <button

                onClick={() => setIsFullscreen(!isFullscreen)}

                className="p-2 rounded-lg bg-base-200 hover:bg-neutral-200 dark:hover:bg-neutral-700 text-neutral-600 dark:text-neutral-200 transition-colors min-h-[44px] min-w-[44px] flex items-center justify-center"

                title={isFullscreen ? 'Exit Fullscreen' : 'Fullscreen'}

              >

                <Maximize2 size={16} />

              </button>

            </div>

            

            {/* Desktop: Show all buttons */}

            <div className="hidden sm:flex items-center gap-2 flex-shrink-0">

              <Button

                variant="ghost"

                size="sm"

                onClick={handleCopyData}

                icon={copied ? <CheckCircle2 size={16} /> : <Copy size={16} />}

                disabled={!result?.output}

              >

                {copied ? 'Copied!' : 'Copy'}

              </Button>

              

              <Button

                variant="ghost"

                size="sm"

                onClick={handleExport}

                icon={<Download size={16} />}

                disabled={!result?.output}

              >

                Export

              </Button>

              

              <Button

                variant="ghost"

                size="sm"

                onClick={() => onShare?.(result)}

                icon={<Share2 size={16} />}

                disabled={!result?.output}

              >

                Share

              </Button>

              

              <Button

                variant="ghost"

                size="sm"

                onClick={() => setIsFullscreen(!isFullscreen)}

                icon={<Maximize2 size={16} />}

              >

                {isFullscreen ? 'Exit' : 'Fullscreen'}

              </Button>

            </div>

          </div>

          

          {/* Mobile Action Buttons Row */}

          <div className="flex gap-2 sm:hidden overflow-x-auto pb-1">

            <button

              onClick={handleCopyData}

              disabled={!result?.output}

              className={`

                flex items-center gap-2 px-3 py-2 rounded-lg text-sm font-medium whitespace-nowrap transition-all min-h-[44px]

                ${copied 

                  ? 'bg-green-100 text-green-700' 

                  : 'bg-base-200 text-neutral-700 dark:text-neutral-200 hover:bg-neutral-200 dark:hover:bg-neutral-700 disabled:opacity-50'

                }

              `}

            >

              {copied ? <CheckCircle2 size={14} /> : <Copy size={14} />}

              {copied ? 'Copied!' : 'Copy'}

            </button>

            

            <button

              onClick={handleExport}

              disabled={!result?.output}

              className="flex items-center gap-2 px-3 py-2 rounded-lg text-sm font-medium bg-blue-100 text-blue-700 hover:bg-blue-200 disabled:opacity-50 whitespace-nowrap min-h-[44px]"

            >

              <Download size={14} />

              Export

            </button>

            

            <button

              onClick={() => onShare?.(result)}

              disabled={!result?.output}

              className="flex items-center gap-2 px-3 py-2 rounded-lg text-sm font-medium bg-purple-100 text-purple-700 hover:bg-purple-200 disabled:opacity-50 whitespace-nowrap min-h-[44px]"

            >

              <Share2 size={14} />

              Share

            </button>

          </div>

        </div>



        <div className="p-4 sm:p-6">

          <SimpleTabs tabs={tabs} defaultTab="visualization" />

        </div>

      </Card>

      

      {isFullscreen && (

        <motion.div

          initial={{ opacity: 0 }}

          animate={{ opacity: 1 }}

          exit={{ opacity: 0 }}

          className="fixed inset-0 bg-black/50 z-40"

          onClick={() => setIsFullscreen(false)}

        />

      )}

    </motion.div>
  );
};

EnhancedPluginResultsPanel.propTypes = {
  result: PropTypes.object,
  loading: PropTypes.bool,
  onExport: PropTypes.func,
  onShare: PropTypes.func,
};

export default EnhancedPluginResultsPanel;