"use client"

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

import { FormSection } from "@/components/form-section"
import { PageHeader } from "@/components/page-header"
import { Button } from "@/components/ui/button"
import {
  Form,
  FormControl,
  FormField,
  FormItem,
  FormLabel,
  FormMessage,
} from "@/components/ui/form"
import { Input } from "@/components/ui/input"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"

const schema = z.object({
  domain: z.string().min(3, "Domain is required."),
  docroot: z.string().min(2, "Docroot is required."),
})

export default function Page() {
  const t = useTranslations("Tools.DomainMapping")

  const form = useForm<z.infer<typeof schema>>({
    resolver: zodResolver(schema),
    defaultValues: {
      domain: "",
      docroot: "",
    },
  })

  return (
    <div className="flex flex-col gap-4 md:gap-6 py-4 md:py-6">
      <PageHeader title={t("title")} />

      <Form {...form}>
        <form className="gap-6 grid" onSubmit={form.handleSubmit(() => {})}>
          <FormSection title={t("mapTitle")}>
            <div className="gap-4 grid md:grid-cols-2">
              <FormField
                control={form.control}
                name="domain"
                render={({ field }) => (
                  <FormItem>
                    <FormLabel>{t("labels.domain")}</FormLabel>
                    <FormControl>
                      <Input placeholder={t("placeholders.domain")} {...field} />
                    </FormControl>
                    <FormMessage />
                  </FormItem>
                )}
              />

              <FormField
                control={form.control}
                name="docroot"
                render={({ field }) => (
                  <FormItem>
                    <FormLabel>{t("labels.docroot")}</FormLabel>
                    <FormControl>
                      <Select
                        onValueChange={field.onChange}
                        defaultValue={field.value}
                      >
                        <SelectTrigger className="w-full">
                          <SelectValue placeholder={t("placeholders.docroot")} />
                        </SelectTrigger>
                        <SelectContent>
                          <SelectItem value="1">Multicart</SelectItem>
                          <SelectItem value="2">Sobkaha</SelectItem>
                          <SelectItem value="3">Bonik</SelectItem>
                          <SelectItem value="4">Balmy</SelectItem>
                        </SelectContent>
                      </Select>
                    </FormControl>
                    <FormMessage />
                  </FormItem>
                )}
              />
            </div>
          </FormSection>

          <div className="px-4 lg:px-6">
            <div className="flex justify-end items-center gap-2">
              <Button type="submit">{t("actions.saveMapping")}</Button>
            </div>
          </div>
        </form>
      </Form>
    </div>
  )
}

