'use client';
import { useState } from 'react';
import { Theme, PlatformTheme } from '@/types/theme';
function ColorInput({
label,
value,
onChange,
}: {
label: string;
value: string;
onChange: (value: string) => void;
}) {
return (
onChange(e.target.value)}
className="w-12 h-8 border rounded cursor-pointer"
/>
onChange(e.target.value)}
className="flex-1 px-2 py-1 border rounded text-sm font-mono"
placeholder="#000000"
/>
);
}
function PlatformSection({
title,
colors,
onChange,
}: {
title: string;
colors: PlatformTheme;
onChange: (key: keyof PlatformTheme, value: string) => void;
}) {
return (
{title}
onChange('primary', v)} />
onChange('secondary', v)}
/>
onChange('accent', v)} />
onChange('background', v)}
/>
onChange('surface', v)} />
onChange('error', v)} />
onChange('warning', v)} />
onChange('success', v)} />
{title === 'Desktop' && (
<>
onChange('idle', v)}
/>
onChange('listening', v)}
/>
onChange('processing', v)}
/>
onChange('offline', v)}
/>
>
)}
);
}
interface ThemeEditorProps {
theme?: Theme;
onSave: (theme: Partial) => void;
onCancel: () => void;
}
export default function ThemeEditor({ theme, onSave, onCancel }: ThemeEditorProps) {
const [name, setName] = useState(theme?.name || '');
const [description, setDescription] = useState(theme?.description || '');
const [iosColors, setIosColors] = useState(
theme?.ios || {
primary: '#4caf50',
secondary: '#2e7d32',
accent: '#66bb6a',
background: '#ffffff',
surface: '#f5f5f5',
error: '#f44336',
warning: '#ff9800',
success: '#4caf50',
}
);
const [androidColors, setAndroidColors] = useState(theme?.android || iosColors);
const [desktopColors, setDesktopColors] = useState(
theme?.desktop || {
...iosColors,
idle: '#4caf50',
listening: '#e94560',
processing: '#f5a623',
offline: '#9e9e9e',
}
);
const handleColorChange = (
platform: 'ios' | 'android' | 'desktop',
colorKey: keyof PlatformTheme,
value: string
) => {
// Validate hex color format
const hexPattern = /^#[0-9A-Fa-f]{6}$/;
if (value && !hexPattern.test(value)) {
return; // Don't update if invalid
}
const setter =
platform === 'ios'
? setIosColors
: platform === 'android'
? setAndroidColors
: setDesktopColors;
setter(prev => ({ ...prev, [colorKey]: value }));
};
const handleSave = () => {
onSave({
name,
description,
ios: iosColors,
android: androidColors,
desktop: desktopColors,
});
};
return (
{theme ? 'Edit Theme' : 'Create New Theme'}
handleColorChange('ios', key, value)}
/>
handleColorChange('android', key, value)}
/>
handleColorChange('desktop', key, value)}
/>
);
}