import { useState } from "react";

export function useMultiState<T extends object>(initialValues: T) {
  const [values, setValues] = useState<T>(initialValues);

  const set = <K extends keyof T>(key: K, value: T[K]) => {
    setValues((prev) => ({ ...prev, [key]: value }));
  };

  const setAll = (newValues: Partial<T>) => {
    setValues((prev) => ({ ...prev, ...newValues }));
  };

  const reset = () => setValues(initialValues);

  return { values, set, setAll, reset };
}
