// =============================================================================
// 📋 ХУК ДЛЯ УПРАВЛЕНИЯ ФОРМОЙ СОЗДАНИЯ ПОСТАВКИ
// =============================================================================

import { useState, useCallback } from 'react'

import type { 
  FulfillmentConsumableSupplier,
  SelectedFulfillmentConsumable,
  UseSupplyFormReturn, 
} from '../types'

export function useSupplyForm(): UseSupplyFormReturn {
  // Состояние формы
  const [selectedSupplier, setSelectedSupplier] = useState<FulfillmentConsumableSupplier | null>(null)
  const [selectedLogistics, setSelectedLogistics] = useState<FulfillmentConsumableSupplier | null>(null)
  const [selectedConsumables, setSelectedConsumables] = useState<SelectedFulfillmentConsumable[]>([])
  const [searchQuery, setSearchQuery] = useState('')
  const [productSearchQuery, setProductSearchQuery] = useState('')
  const [deliveryDate, setDeliveryDate] = useState('')
  const [notes, setNotes] = useState('')

  // Функция сброса формы
  const resetForm = useCallback(() => {
    setSelectedSupplier(null)
    setSelectedLogistics(null)
    setSelectedConsumables([])
    setSearchQuery('')
    setProductSearchQuery('')
    setDeliveryDate('')
    setNotes('')
  }, [])

  return {
    // Состояние формы
    selectedSupplier,
    selectedLogistics,
    selectedConsumables,
    searchQuery,
    productSearchQuery,
    deliveryDate,
    notes,

    // Действия формы
    setSelectedSupplier,
    setSelectedLogistics,
    setSelectedConsumables,
    setSearchQuery,
    setProductSearchQuery,
    setDeliveryDate,
    setNotes,

    // Сброс формы
    resetForm,
  }
}