meatloaf-config/src/app/components/IECPage.tsx

227 lines
8.8 KiB
TypeScript

import { useState } from 'react';
import { FolderOpen } from 'lucide-react';
import FileBrowser from './FileBrowser';
interface IECPageProps {
config: any;
setConfig: (config: any) => void;
}
export default function IECPage({ config, setConfig }: IECPageProps) {
const [showFileBrowser, setShowFileBrowser] = useState(false);
const updateSetting = (path: string[], value: any) => {
const newConfig = JSON.parse(JSON.stringify(config));
let current = newConfig;
for (let i = 0; i < path.length - 1; i++) {
current = current[path[i]];
}
current[path[path.length - 1]] = value;
setConfig(newConfig);
};
const iec = config.iec || {};
return (
<div className="p-4 space-y-4">
<h2 className="text-sm text-neutral-500">IEC Settings</h2>
<div className="bg-white border border-neutral-200 rounded-lg divide-y divide-neutral-200">
<div className="p-4 flex items-center justify-between">
<label className="text-sm text-neutral-500">IEC Enabled</label>
<button
onClick={() => updateSetting(['iec', 'enabled'], iec.enabled ? 0 : 1)}
className={`relative w-12 h-6 rounded-full transition-colors ${
iec.enabled ? 'bg-blue-600' : 'bg-neutral-300'
}`}
>
<div
className={`absolute top-0.5 w-5 h-5 bg-white rounded-full transition-transform ${
iec.enabled ? 'translate-x-6' : 'translate-x-0.5'
}`}
/>
</button>
</div>
<div className="p-4 flex items-center justify-between">
<label className="text-sm text-neutral-500">VIC-20 Mode</label>
<button
onClick={() => updateSetting(['iec', 'vic20_mode'], iec.vic20_mode ? 0 : 1)}
className={`relative w-12 h-6 rounded-full transition-colors ${
iec.vic20_mode ? 'bg-blue-600' : 'bg-neutral-300'
}`}
>
<div
className={`absolute top-0.5 w-5 h-5 bg-white rounded-full transition-transform ${
iec.vic20_mode ? 'translate-x-6' : 'translate-x-0.5'
}`}
/>
</button>
</div>
<div className="p-4">
<label className="text-sm text-neutral-500 block mb-2">Boot Disk</label>
<div className="flex gap-2">
<input
type="text"
value={iec.boot_disk || ''}
onChange={(e) => updateSetting(['iec', 'boot_disk'], e.target.value)}
className="flex-1 px-3 py-2 border border-neutral-300 rounded-lg"
/>
<button
onClick={() => setShowFileBrowser(true)}
className="px-3 py-2 border border-neutral-300 rounded-lg bg-neutral-50 hover:bg-neutral-100"
title="Browse files"
>
<FolderOpen className="w-5 h-5" />
</button>
</div>
</div>
{showFileBrowser && (
<FileBrowser
currentPath={iec.boot_disk || '/'}
onSelect={(path) => {
updateSetting(['iec', 'boot_disk'], path);
setShowFileBrowser(false);
}}
onClose={() => setShowFileBrowser(false)}
/>
)}
</div>
<h2 className="text-sm text-neutral-500 pt-4">Directory Settings</h2>
<div className="bg-white border border-neutral-200 rounded-lg divide-y divide-neutral-200">
{Object.entries(iec.directory || {}).map(([key, value]) => (
<div key={key} className="p-4 flex items-center justify-between">
<label className="text-sm text-neutral-500">
{key.replace(/_/g, ' ').replace(/\b\w/g, l => l.toUpperCase())}
</label>
{typeof value === 'number' ? (
<button
onClick={() => updateSetting(['iec', 'directory', key], value ? 0 : 1)}
className={`relative w-12 h-6 rounded-full transition-colors ${
value ? 'bg-blue-600' : 'bg-neutral-300'
}`}
>
<div
className={`absolute top-0.5 w-5 h-5 bg-white rounded-full transition-transform ${
value ? 'translate-x-6' : 'translate-x-0.5'
}`}
/>
</button>
) : (
<input
type="number"
value={value}
onChange={(e) => updateSetting(['iec', 'directory', key], parseInt(e.target.value))}
className="w-24 px-3 py-1 border border-neutral-300 rounded-lg text-right"
/>
)}
</div>
))}
</div>
<h2 className="text-sm text-neutral-500 pt-4">Hardware Fastloaders</h2>
<div className="bg-white border border-neutral-200 rounded-lg divide-y divide-neutral-200">
<div className="p-3 bg-neutral-50">
<h3 className="text-xs text-neutral-600">Serial</h3>
</div>
{Object.entries(iec.fastloaders?.hardware?.serial || {}).map(([key, value]) => (
<div key={key} className="p-4 flex items-center justify-between">
<label className="text-sm text-neutral-500">
{key.replace(/_/g, ' ').replace(/\b\w/g, l => l.toUpperCase())}
</label>
<button
onClick={() => updateSetting(['iec', 'fastloaders', 'hardware', 'serial', key], value ? 0 : 1)}
className={`relative w-12 h-6 rounded-full transition-colors ${
value ? 'bg-blue-600' : 'bg-neutral-300'
}`}
>
<div
className={`absolute top-0.5 w-5 h-5 bg-white rounded-full transition-transform ${
value ? 'translate-x-6' : 'translate-x-0.5'
}`}
/>
</button>
</div>
))}
<div className="p-3 bg-neutral-50">
<h3 className="text-xs text-neutral-600">Parallel</h3>
</div>
{Object.entries(iec.fastloaders?.hardware?.parallel || {}).map(([key, value]) => (
<div key={key} className="p-4 flex items-center justify-between">
<label className="text-sm text-neutral-500">
{key.replace(/_/g, ' ').replace(/\b\w/g, l => l.toUpperCase())}
</label>
<button
onClick={() => updateSetting(['iec', 'fastloaders', 'hardware', 'parallel', key], value ? 0 : 1)}
className={`relative w-12 h-6 rounded-full transition-colors ${
value ? 'bg-blue-600' : 'bg-neutral-300'
}`}
>
<div
className={`absolute top-0.5 w-5 h-5 bg-white rounded-full transition-transform ${
value ? 'translate-x-6' : 'translate-x-0.5'
}`}
/>
</button>
</div>
))}
</div>
<h2 className="text-sm text-neutral-500 pt-4">Software Fastloaders</h2>
<div className="bg-white border border-neutral-200 rounded-lg divide-y divide-neutral-200">
{Object.entries(iec.fastloaders?.software || {}).map(([key, value]) => (
<div key={key} className="p-4 flex items-center justify-between">
<label className="text-sm text-neutral-500">
{key.replace(/_/g, ' ').replace(/\b\w/g, l => l.toUpperCase())}
</label>
<button
onClick={() => updateSetting(['iec', 'fastloaders', 'software', key], value ? 0 : 1)}
className={`relative w-12 h-6 rounded-full transition-colors ${
value ? 'bg-blue-600' : 'bg-neutral-300'
}`}
>
<div
className={`absolute top-0.5 w-5 h-5 bg-white rounded-full transition-transform ${
value ? 'translate-x-6' : 'translate-x-0.5'
}`}
/>
</button>
</div>
))}
</div>
<h2 className="text-sm text-neutral-500 pt-4">Chainloaders</h2>
<div className="bg-white border border-neutral-200 rounded-lg divide-y divide-neutral-200">
{Object.entries(iec.chainloaders || {}).map(([key, value]) => (
<div key={key} className="p-4 flex items-center justify-between">
<label className="text-sm text-neutral-500">
{key.toUpperCase()}
</label>
<button
onClick={() => updateSetting(['iec', 'chainloaders', key], value ? 0 : 1)}
className={`relative w-12 h-6 rounded-full transition-colors ${
value ? 'bg-blue-600' : 'bg-neutral-300'
}`}
>
<div
className={`absolute top-0.5 w-5 h-5 bg-white rounded-full transition-transform ${
value ? 'translate-x-6' : 'translate-x-0.5'
}`}
/>
</button>
</div>
))}
</div>
</div>
);
}