"use strict";Object.defineProperty(exports, "__esModule", {value: true});


var _chunkOUOFVKJUjs = require('./chunk-OUOFVKJU.js');


var _chunkIDQWBAHKjs = require('./chunk-IDQWBAHK.js');


var _chunkRS5K4U5Wjs = require('./chunk-RS5K4U5W.js');

// tmp-babel/content-feed/web/PostCreate/index.js
var _react = require('react');
var _utils = require('@baseapp-frontend/utils');
var _zod = require('@hookform/resolvers/zod');
var _navigation = require('next/navigation');
var _reacthookform = require('react-hook-form');
var _jsxruntime = require('react/jsx-runtime');
function _slicedToArray(r, e) {
  return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
}
function _nonIterableRest() {
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _unsupportedIterableToArray(r, a) {
  if (r) {
    if ("string" == typeof r) return _arrayLikeToArray(r, a);
    var t = {}.toString.call(r).slice(8, -1);
    return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
  }
}
function _arrayLikeToArray(r, a) {
  (null == a || a > r.length) && (a = r.length);
  for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
  return n;
}
function _iterableToArrayLimit(r, l) {
  var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
  if (null != t) {
    var e, n, i, u, a = [], f = true, o = false;
    try {
      if (i = (t = t.call(r)).next, 0 === l) {
        if (Object(t) !== t) return;
        f = false;
      } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = true) ;
    } catch (r2) {
      o = true, n = r2;
    } finally {
      try {
        if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return;
      } finally {
        if (o) throw n;
      }
    }
    return a;
  }
}
function _arrayWithHoles(r) {
  if (Array.isArray(r)) return r;
}
var PostCreate = function PostCreate2() {
  var router = _navigation.useRouter.call(void 0, );
  var _useNotification = _utils.useNotification.call(void 0, ), sendToast = _useNotification.sendToast;
  var _useContentPostCreate = _chunkRS5K4U5Wjs.useContentPostCreateMutation.call(void 0, ), _useContentPostCreate2 = _slicedToArray(_useContentPostCreate, 2), commitMutation = _useContentPostCreate2[0], isMutationInFlight = _useContentPostCreate2[1];
  var form = _reacthookform.useForm.call(void 0, {
    defaultValues: _chunkOUOFVKJUjs.DEFAULT_CONTENT_POST_CREATE_FORM_VALUES,
    resolver: _zod.zodResolver.call(void 0, _chunkOUOFVKJUjs.CONTENT_POST_CREATE_FORM_VALIDATION),
    mode: "onBlur"
  });
  var onSubmit = form.handleSubmit(function(data) {
    var uploadables = {};
    if (data.images) {
      data.images.forEach(function(image, index) {
        uploadables["images.".concat(index)] = image;
      });
    }
    commitMutation({
      variables: {
        input: {
          content: data.content,
          isReactionsEnabled: data.isReactionsEnabled
        }
      },
      uploadables,
      onCompleted: function onCompleted(response) {
        var _response$contentPost;
        var errors = (_response$contentPost = response.contentPostCreate) === null || _response$contentPost === void 0 ? void 0 : _response$contentPost.errors;
        if (errors) {
          sendToast("Something went wrong", {
            type: "error"
          });
          _utils.setFormRelayErrors.call(void 0, form, errors);
        } else {
          var _response$contentPost2;
          form.reset({
            content: "",
            isReactionsEnabled: true
          });
          sendToast("Post Created Successfully", {
            type: "success"
          });
          router.push("/posts/".concat((_response$contentPost2 = response.contentPostCreate) === null || _response$contentPost2 === void 0 || (_response$contentPost2 = _response$contentPost2.contentPost) === null || _response$contentPost2 === void 0 || (_response$contentPost2 = _response$contentPost2.node) === null || _response$contentPost2 === void 0 ? void 0 : _response$contentPost2.id));
        }
      }
    });
  });
  var onCancel = _react.useCallback.call(void 0, function() {
    router.push("/posts");
  }, [router]);
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkIDQWBAHKjs.PostForm_default, {
    form,
    isSaving: isMutationInFlight,
    onSubmit,
    onCancel
  });
};
var PostCreate_default = PostCreate;



exports.PostCreate_default = PostCreate_default;
//# sourceMappingURL=chunk-YLG3L6MD.js.map