import { CalendarIcon } from '@radix-ui/react-icons'

import { format } from 'date-fns'
import * as React from 'react'

import { Button } from '@components/ui/button/button'
import { Calendar } from '@components/ui/calendar/calendar'
import { Popover, PopoverContent, PopoverTrigger } from '@components/ui/popover/popover'
import { cn } from '@lib/utils'

export function DatePickerDemo() {
  const [date, setDate] = React.useState<Date>()

  return (
    <Popover>
      <PopoverTrigger asChild>
        <Button
          variant={'outline'}
          className={cn('w-[240px] justify-start text-left font-normal', !date && 'text-muted-foreground')}
        >
          <CalendarIcon className="mr-2 h-4 w-4" />
          {date ? format(date, 'PPP') : <span>Pick a date</span>}
        </Button>
      </PopoverTrigger>
      <PopoverContent className="w-auto p-0" align="start">
        <Calendar mode="single" selected={date} onSelect={setDate} initialFocus />
      </PopoverContent>
    </Popover>
  )
}
