98 lines
3 KiB
TypeScript
98 lines
3 KiB
TypeScript
import React from 'react';
|
|
import { motion } from 'framer-motion';
|
|
import { X, Settings, Loader2 } from 'lucide-react';
|
|
import { GameConfigPanel } from './GameConfigPanel';
|
|
import { useBodyScrollLock } from '../hooks/useBodyScrollLock';
|
|
import type { GameConfig } from '../types';
|
|
|
|
interface DefaultConfigModalProps {
|
|
isOpen: boolean;
|
|
onClose: () => void;
|
|
config: GameConfig;
|
|
onChange: (config: GameConfig) => void;
|
|
onSave: () => void;
|
|
saving: boolean;
|
|
maxPlayersLimit?: number;
|
|
}
|
|
|
|
export const DefaultConfigModal: React.FC<DefaultConfigModalProps> = ({
|
|
isOpen,
|
|
onClose,
|
|
config,
|
|
onChange,
|
|
onSave,
|
|
saving,
|
|
maxPlayersLimit = 150,
|
|
}) => {
|
|
useBodyScrollLock(isOpen);
|
|
|
|
if (!isOpen) return null;
|
|
|
|
return (
|
|
<motion.div
|
|
initial={{ opacity: 0 }}
|
|
animate={{ opacity: 1 }}
|
|
exit={{ opacity: 0 }}
|
|
className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4"
|
|
onClick={onClose}
|
|
>
|
|
<motion.div
|
|
initial={{ scale: 0.9, opacity: 0 }}
|
|
animate={{ scale: 1, opacity: 1 }}
|
|
exit={{ scale: 0.9, opacity: 0 }}
|
|
className="bg-white rounded-2xl max-w-lg w-full shadow-xl max-h-[90vh] overflow-hidden flex flex-col"
|
|
onClick={(e) => e.stopPropagation()}
|
|
>
|
|
<div className="p-6 border-b border-gray-100 flex items-center justify-between bg-theme-primary">
|
|
<div className="flex items-center gap-3 text-white">
|
|
<div className="p-2 bg-white/20 rounded-xl">
|
|
<Settings size={24} />
|
|
</div>
|
|
<div>
|
|
<h2 className="text-xl font-black">Default Game Settings</h2>
|
|
<p className="text-sm opacity-80">Applied to all new quizzes</p>
|
|
</div>
|
|
</div>
|
|
<button
|
|
onClick={onClose}
|
|
className="p-2 hover:bg-white/20 rounded-xl transition text-white"
|
|
>
|
|
<X size={24} />
|
|
</button>
|
|
</div>
|
|
|
|
<div className="p-6 overflow-y-auto flex-1 bg-gray-50">
|
|
<GameConfigPanel
|
|
config={config}
|
|
onChange={onChange}
|
|
questionCount={10}
|
|
maxPlayersLimit={maxPlayersLimit}
|
|
/>
|
|
</div>
|
|
|
|
<div className="p-6 border-t border-gray-100 flex gap-3">
|
|
<button
|
|
onClick={onClose}
|
|
className="flex-1 py-3 rounded-xl font-bold border-2 border-gray-200 text-gray-600 hover:bg-gray-50 transition"
|
|
>
|
|
Cancel
|
|
</button>
|
|
<button
|
|
onClick={onSave}
|
|
disabled={saving}
|
|
className="flex-1 py-3 rounded-xl font-bold bg-theme-primary text-white hover:bg-theme-primary/90 transition disabled:opacity-50 flex items-center justify-center gap-2"
|
|
>
|
|
{saving ? (
|
|
<>
|
|
<Loader2 size={20} className="animate-spin" />
|
|
Saving...
|
|
</>
|
|
) : (
|
|
'Save Defaults'
|
|
)}
|
|
</button>
|
|
</div>
|
|
</motion.div>
|
|
</motion.div>
|
|
);
|
|
};
|