"use client";
import { useToast } from "@/components/ui/use-toast";
import { useRouter } from "next/navigation";

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

import {
  Form,
  FormControl,
  FormDescription,
  FormField,
  FormItem,
  FormLabel,
  FormMessage,
} from "@/components/ui/form";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";

const createFeatureSchema = z.object({
  name: z.string().min(2, {
    message: "Feature name must be at least 2 characters.",
  }),
  description: z.string().min(2, {
    message: "Feature description must be at least 2 characters.",
  }),
});

export function CreateFeature() {
  const { toast } = useToast();
  const router = useRouter();

  const form = useForm<z.infer<typeof createFeatureSchema>>({
    resolver: zodResolver(createFeatureSchema),
    defaultValues: {
      name: "",
      description: "",
    },
  });

  async function createFeature(values: z.infer<typeof createFeatureSchema>) {
    try {
      // TODO: create feature
    } catch (err: any) {
      console.error(err);
      toast({
        variant: "destructive",
        title: "Uh oh! There was an error creating the feature.",
        description: err.error,
      });
    }
  }

  return (
    <div>
      <h1>Create Feature</h1>
    </div>
  );
}
