File size: 5,820 Bytes
2740e39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import React, { useState } from 'react';
import { motion } from 'framer-motion';
import { useTranslation } from 'react-i18next';
import { X, Layers, Check, Ungroup, Trash2 } from 'lucide-react';

const COLORS = {
  purple: '#a855f7', blue: '#3b82f6', green: '#22c55e', yellow: '#eab308', pink: '#ec4899', orange: '#f97316', white: '#78716c',
};

const GroupSettingsModal = ({ node, childCount, onClose, onSave, onUngroup, onDelete }) => {
  const { t } = useTranslation();
  const [label, setLabel] = useState(node.data.label || '');
  const [description, setDescription] = useState(node.data.description || '');
  const [color, setColor] = useState(node.data.color || 'purple');
  const [confirmDelete, setConfirmDelete] = useState(false);

  return (
    <div className="fixed inset-0 bg-primary/40 backdrop-blur-md z-[60] flex items-center justify-center p-4" onClick={onClose}>
      <motion.div
        initial={{ opacity: 0, y: 24, scale: 0.96 }}
        animate={{ opacity: 1, y: 0, scale: 1 }}
        transition={{ type: 'spring', stiffness: 280, damping: 24 }}
        onClick={(e) => e.stopPropagation()}
        className="bg-surface-container-lowest border-4 border-primary rounded-3xl p-7 max-w-md w-full shadow-[8px_8px_0px_0px_var(--color-primary)] relative flex flex-col gap-5"
      >
        <button onClick={onClose} className="absolute top-5 right-5 p-1.5 border-2 border-primary rounded-xl hover:bg-red-500/20 cursor-pointer text-primary">
          <X size={18} />
        </button>
        <h3 className="text-2xl font-display-lg text-primary flex items-center gap-2 pr-10">
          <Layers size={24} className="text-purple-500" />
          {t('groups.settings', 'Group settings')}
        </h3>

        <label className="flex flex-col gap-1.5">
          <span className="text-[11px] font-bold uppercase tracking-widest text-primary/60">{t('groups.name', 'Name')}</span>
          <input
            autoFocus
            value={label}
            onChange={(e) => setLabel(e.target.value)}
            placeholder={t('groups.name_placeholder', 'e.g. Chapter 1: Prepare')}
            className="w-full px-4 py-3 bg-secondary/10 border-2 border-primary rounded-xl font-bold text-primary focus:outline-none focus:bg-surface-container-lowest"
          />
        </label>
        <label className="flex flex-col gap-1.5">
          <span className="text-[11px] font-bold uppercase tracking-widest text-primary/60">{t('groups.description', 'Description')}</span>
          <textarea
            value={description}
            onChange={(e) => setDescription(e.target.value)}
            className="w-full h-20 px-4 py-2.5 bg-secondary/10 border-2 border-primary rounded-xl font-bold text-primary text-xs focus:outline-none resize-none"
          />
        </label>
        <div className="flex flex-col gap-1.5">
          <span className="text-[11px] font-bold uppercase tracking-widest text-primary/60">{t('groups.color', 'Color')}</span>
          <div className="flex gap-2">
            {Object.entries(COLORS).map(([key, value]) => (
              <button
                key={key}
                onClick={() => setColor(key)}
                className="w-8 h-8 rounded-full border-2 flex items-center justify-center cursor-pointer hover:scale-110 transition-transform"
                style={{ backgroundColor: value, borderColor: color === key ? 'var(--color-primary)' : 'transparent' }}
              >
                {color === key && <Check size={14} className="text-white" strokeWidth={3} />}
              </button>
            ))}
          </div>
        </div>

        <div className="flex flex-col gap-2 pt-1 border-t-2 border-primary/10">
          <button
            onClick={onUngroup}
            className="flex items-center justify-center gap-2 py-2.5 rounded-xl border-2 border-primary/20 hover:border-primary text-xs font-bold uppercase tracking-wider text-primary cursor-pointer"
          >
            <Ungroup size={15} /> {t('groups.ungroup', 'Ungroup (keep the contents)')}
          </button>
          {confirmDelete ? (
            <div className="flex gap-2">
              <button onClick={onDelete} className="flex-1 py-2.5 rounded-xl bg-red-500 text-white text-xs font-bold uppercase tracking-wider cursor-pointer">
                {t('groups.delete_confirm', { count: childCount, defaultValue: `Delete group and ${childCount} nodes` })}
              </button>
              <button onClick={() => setConfirmDelete(false)} className="px-4 py-2.5 rounded-xl border-2 border-primary/20 text-xs font-bold cursor-pointer text-primary">
                {t('common.cancel', 'Cancel')}
              </button>
            </div>
          ) : (
            <button
              onClick={() => setConfirmDelete(true)}
              className="flex items-center justify-center gap-2 py-2.5 rounded-xl border-2 border-red-500/30 hover:border-red-500 text-xs font-bold uppercase tracking-wider text-red-600 cursor-pointer"
            >
              <Trash2 size={15} /> {t('groups.delete', 'Delete group with contents')}
            </button>
          )}
        </div>

        <div className="flex gap-3">
          <button onClick={onClose} className="flex-1 py-3 text-xs font-bold uppercase tracking-wider text-primary border-2 border-primary rounded-xl cursor-pointer">
            {t('common.cancel', 'Cancel')}
          </button>
          <button
            onClick={() => onSave({ label: label.trim(), description, color })}
            className="flex-1 py-3 text-xs font-bold uppercase tracking-wider text-on-primary bg-primary border-2 border-primary rounded-xl cursor-pointer"
          >
            {t('common.apply', 'Apply')}
          </button>
        </div>
      </motion.div>
    </div>
  );
};

export default GroupSettingsModal;