Spaces:
Running

File size: 4,093 Bytes
de55c35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import React, { useState, useEffect } from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import { X, Check, Info } from 'lucide-react';

const Modal = ({ 
  isOpen, 
  onClose, 
  onConfirm, 
  title, 
  message, 
  type = 'confirm', 
  initialValue = '',
  placeholder = 'Enter something...',
  confirmText = 'OK',
  cancelText = 'Cancel'
}) => {
  const [inputValue, setInputValue] = useState(initialValue);

  useEffect(() => {
    if (isOpen) {
      setInputValue(initialValue);
    }
  }, [isOpen, initialValue]);

  const handleSubmit = (e) => {
    e.preventDefault();
    if (type === 'prompt') {
      onConfirm(inputValue);
    } else {
      onConfirm();
    }
    onClose();
  };

  return (
    <AnimatePresence>
      {isOpen && (
        <div className="fixed inset-0 z-50 flex items-center justify-center p-4 sm:p-6">
          {/* Backdrop */}
          <motion.div 
            initial={{ opacity: 0 }}
            animate={{ opacity: 1 }}
            exit={{ opacity: 0 }}
            onClick={onClose}
            className="absolute inset-0 bg-primary/20 backdrop-blur-sm"
          />

          {/* Modal Content */}
          <motion.div
            initial={{ scale: 0.9, opacity: 0, y: 20, rotate: -1 }}
            animate={{ scale: 1, opacity: 1, y: 0, rotate: 0 }}
            exit={{ scale: 0.9, opacity: 0, y: 20, rotate: 1 }}
            className="relative bg-surface-container-lowest w-full max-w-md p-8 rough-border rough-shadow flex flex-col gap-6"
          >
            <button 
              onClick={onClose}
              className="absolute top-4 right-4 text-on-surface-variant hover:text-primary transition-colors"
            >
              <X size={24} />
            </button>

            <div className="flex flex-col gap-2">
              <h2 className="text-4xl font-display-lg text-primary leading-tight">
                {title}
              </h2>
              {message && (
                <p className="font-body-md text-on-surface-variant italic">
                  {message}
                </p>
              )}
            </div>

            <form onSubmit={handleSubmit} className="flex flex-col gap-8">
              {type === 'prompt' && (
                <div className="relative group">
                  <input
                    autoFocus
                    type="text"
                    value={inputValue}
                    onChange={(e) => setInputValue(e.target.value)}
                    placeholder={placeholder}
                    className="w-full bg-surface-container-low border-b-2 border-primary/20 focus:border-primary px-2 py-3 text-xl font-body-md outline-none transition-all"
                  />
                  <div className="absolute bottom-0 left-0 h-0.5 bg-primary w-0 group-focus-within:w-full transition-all duration-300" />
                </div>
              )}

              <div className="flex items-center justify-end gap-4 mt-2">
                <button
                  type="button"
                  onClick={onClose}
                  className="px-6 py-2 font-bold text-lg text-on-surface-variant hover:text-primary transition-all"
                >
                  {cancelText}
                </button>
                <motion.button
                  whileHover={{ scale: 1.05, rotate: -1 }}
                  whileTap={{ scale: 0.95 }}
                  type="submit"
                  className="bg-primary text-on-primary px-8 py-3 text-xl font-bold rough-border rough-shadow-hover flex items-center gap-2"
                >
                  <Check size={20} />
                  <span>{confirmText}</span>
                </motion.button>
              </div>
            </form>

            {/* Decorative Sketched Element */}
            <div className="absolute -bottom-6 -left-6 pointer-events-none opacity-[0.03] overflow-hidden">
               <Info size={160} className="-rotate-12 translate-x-4 translate-y-4" />
            </div>
          </motion.div>
        </div>
      )}
    </AnimatePresence>
  );
};

export default Modal;