import DateTimeField from '@/components/common/DateTimeField'
import Label from '@/components/common/Label'

import type { FC } from 'react'

type Props = {
    originalCreatedFrom:      string | null
    setOriginalCreatedFrom:   (x: string | null) => void
    originalCreatedBefore:    string | null
    setOriginalCreatedBefore: (x: string | null) => void }


export default (({ originalCreatedFrom,
		   setOriginalCreatedFrom,
		   originalCreatedBefore,
		   setOriginalCreatedBefore }: Props) => (
    <div>
      <Label>オリジナルの作成日時</Label>
      <div className="my-1">
	<DateTimeField
	    className="mr-2"
	    value={originalCreatedFrom ?? undefined}
	    onChange={setOriginalCreatedFrom}
	    onBlur={ev => {
	      const v = ev.target.value
	      if (!(v))
		return
	      const d = new Date (v)
	      if (d.getSeconds () === 0)
		{
		  if (d.getMinutes () === 0 && d.getHours () === 0)
		    d.setDate (d.getDate () + 1)
		  else
		    d.setMinutes (d.getMinutes () + 1)
		}
	      else
		d.setSeconds (d.getSeconds () + 1)
	      setOriginalCreatedBefore (d.toISOString ())
	    }}/>
	以降
      </div>
      <div className="my-1">
	<DateTimeField
	    className="mr-2"
	    value={originalCreatedBefore ?? undefined}
	    onChange={setOriginalCreatedBefore}/>
	より前
      </div>
    </div>)) satisfies FC<Props>
