import React from 'react';

import { Button } from '@/components/ui/button';
import { SystemWindowDialog } from '@/components/ui/system-window-dialog';
import { Lang } from '@/lang/Lang';

import {
    HALL_SEAT_FILL_DIRECTION_LANG_KEY,
    HALL_SEAT_FILL_DIRECTIONS,
    type HallSeatFillDirection,
} from '../hallSeatOrder';

type Props = {
    open: boolean;
    onOpenChange: (open: boolean) => void;
    startFrom: string;
    fillDirection: HallSeatFillDirection;
    onStartFromChange: (value: string) => void;
    onFillDirectionChange: (direction: HallSeatFillDirection) => void;
    onApply: () => void;
    stackIndex?: number;
};

export default function SeatNumberingDialog({
    open,
    onOpenChange,
    startFrom,
    fillDirection,
    onStartFromChange,
    onFillDirectionChange,
    onApply,
    stackIndex = 1,
}: Props) {
    return (
        <SystemWindowDialog
            open={open}
            onOpenChange={onOpenChange}
            title={Lang.key('hall_seat_numbering_title')}
            width={448}
            stackIndex={stackIndex}
            footer={
                <>
                    <Button
                        onClick={() => onOpenChange(false)}
                        type="button"
                        variant="outline"
                    >
                        {Lang.key('cancel')}
                    </Button>
                    <Button onClick={onApply} type="button">
                        {Lang.key('apply')}
                    </Button>
                </>
            }
        >
            <div className="space-y-4">
                <div className="space-y-2">
                    <div className="text-xs text-slate-600">{Lang.key('hall_seat_start_from')}</div>
                    <input
                        className="w-full border rounded-md h-9 px-3 text-sm"
                        type="text"
                        inputMode="text"
                        autoComplete="off"
                        value={startFrom}
                        onChange={(e) => onStartFromChange(e.target.value)}
                    />
                    <div className="text-xs text-slate-500">{Lang.key('hall_seat_start_hint')}</div>
                </div>
                <div className="space-y-2">
                    <div className="text-xs text-slate-600">{Lang.key('hall_seat_direction_label')}</div>
                    <select
                        className="w-full border rounded-md h-9 px-3 text-sm bg-white"
                        value={fillDirection}
                        onChange={(e) => onFillDirectionChange(e.target.value as HallSeatFillDirection)}
                    >
                        {HALL_SEAT_FILL_DIRECTIONS.map((dir) => (
                            <option key={dir} value={dir}>
                                {Lang.key(HALL_SEAT_FILL_DIRECTION_LANG_KEY[dir])}
                            </option>
                        ))}
                    </select>
                </div>
            </div>
        </SystemWindowDialog>
    );
}
