import { useStyles } from '../styles';
import { useCategoryCollection } from '../../../../hooks/collections/category/useCategoryCollection';
import { useRoute } from '@react-navigation/native';
import * as z from 'zod';
import { zodResolver } from '@hookform/resolvers/zod';
import { useForm } from 'react-hook-form';
function useAddCategory() {
  var _route$params;
  const {
    styles,
    theme
  } = useStyles();
  const schema = z.object({
    categories: z.array(z.custom()).min(1)
  });
  const query = useCategoryCollection({
    params: {
      limit: 20
    }
  });
  const route = useRoute();
  const {
    formState: {
      isDirty,
      isSubmitting,
      isValid
    },
    handleSubmit,
    control,
    watch
  } = useForm({
    resolver: zodResolver(schema),
    mode: 'onChange',
    defaultValues: {
      categories: ((_route$params = route.params) === null || _route$params === void 0 ? void 0 : _route$params.categories) ?? []
    }
  });
  const onSubmit = () => {
    var _route$params2;
    (_route$params2 = route.params) !== null && _route$params2 !== void 0 && _route$params2.onAddedAction ? route.params.onAddedAction(watch('categories')) : null;
  };
  return {
    ...query,
    categories: query.data,
    styles,
    theme,
    isDirty,
    isSubmitting,
    isValid,
    handleSubmit,
    control,
    onSubmit
  };
}
export default useAddCategory;
//# sourceMappingURL=useAddCategory.js.map