import { type FC } from 'react'
import type { FormikProps } from 'formik'
import { Checkbox } from '@/components/ui/checkbox'
import type { CreateFoodType } from '../types/Types'

type MealTimesSectionProps = {
  formik: FormikProps<CreateFoodType>
}

const MealTimesSection: FC<MealTimesSectionProps> = ({ formik }) => {
  const mealTypes = [
    { value: 'breakfast', label: 'صبحانه' },
    { value: 'lunch', label: 'ناهار' },
    { value: 'dinner', label: 'شام' },
    { value: 'snack', label: 'عصرانه' }
  ] as const

  const handleMealTypeChange = (mealType: string, checked: boolean) => {
    const currentMealTypes = formik.values.mealTypes || []
    if (checked) {
      if (!currentMealTypes.includes(mealType)) {
        formik.setFieldValue('mealTypes', [...currentMealTypes, mealType])
      }
    } else {
      formik.setFieldValue('mealTypes', currentMealTypes.filter(m => m !== mealType))
    }
  }

  return (
    <div className='mt-6'>
      <div className='text-sm mb-3'>وعده‌های کالایی</div>
      <div className='text-xs text-gray-500 mb-3 bg-gray-50 p-3 rounded-lg border border-gray-200'>
        <div>ساعات 6 تا 11 صبح :صبحانه</div>
        <div>11 تا 15 ناهار</div>
        <div>15 تا 19 عصرانه</div>
        <div>18 تا 24 شام</div>
      </div>
      <div className='flex gap-4 sm:gap-6 flex-wrap'>
        {mealTypes.map((mealType) => (
          <div key={mealType.value} className='flex items-center gap-2'>
            <Checkbox
              checked={(formik.values.mealTypes || []).includes(mealType.value)}
              onCheckedChange={(checked) => handleMealTypeChange(mealType.value, checked as boolean)}
            />
            <label className='text-xs cursor-pointer'>{mealType.label}</label>
          </div>
        ))}
      </div>
    </div>
  )
}

export default MealTimesSection

