"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _styles = require("../styles");
var _useCategoryCollection = require("../../../../hooks/collections/category/useCategoryCollection");
var _native = require("@react-navigation/native");
var z = _interopRequireWildcard(require("zod"));
var _zod2 = require("@hookform/resolvers/zod");
var _reactHookForm = require("react-hook-form");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
function useAddCategory() {
  var _route$params;
  const {
    styles,
    theme
  } = (0, _styles.useStyles)();
  const schema = z.object({
    categories: z.array(z.custom()).min(1)
  });
  const query = (0, _useCategoryCollection.useCategoryCollection)({
    params: {
      limit: 20
    }
  });
  const route = (0, _native.useRoute)();
  const {
    formState: {
      isDirty,
      isSubmitting,
      isValid
    },
    handleSubmit,
    control,
    watch
  } = (0, _reactHookForm.useForm)({
    resolver: (0, _zod2.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
  };
}
var _default = exports.default = useAddCategory;
//# sourceMappingURL=useAddCategory.js.map