"use client";

import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
import { z } from "zod";

import { Button } from "@/components/ui/button";
import {
  Form,
  FormControl,
  FormField,
  FormItem,
  FormLabel,
} from "@/components/ui/form";
import { gameConfigPatchSchema } from "@/lib/validations/game";
import { Switch } from "@/components/ui/switch";

export default function GameConfigForm() {
  // ...
  const form = useForm<z.infer<typeof gameConfigPatchSchema>>({
    resolver: zodResolver(gameConfigPatchSchema),
    defaultValues: {
      allowHints: false,
      scoreMultiplier: 1,
      timeLimit: 2,
    },
  });

  // 2. Define a submit handler.
  function onSubmit(values: z.infer<typeof gameConfigPatchSchema>) {
    // Do something with the form values.
    // ✅ This will be type-safe and validated.
    console.log(values);
  }
  return (
    <Form {...form}>
      <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8">
        <FormField
          control={form.control}
          name="allowHints"
          render={({ field }) => (
            <FormItem className="container-bg flex flex-row items-center justify-between p-3">
              <div className="space-y-0.5">
                <FormLabel>Allow hints</FormLabel>
              </div>
              <FormControl>
                <Switch
                  checked={field.value}
                  onCheckedChange={field.onChange}
                />
              </FormControl>
            </FormItem>
          )}
        />
        {/* <Button type="submit">Submit</Button> */}
      </form>
    </Form>
  );
}
