"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// tmp-babel/content-feed/web/PostImageDropzone/index.js
var _react = require('react');
var _dropzones = require('@baseapp-frontend/design-system/components/web/dropzones');
var _material = require('@mui/material');
var _image = require('next/image'); var _image2 = _interopRequireDefault(_image);
var _jsxruntime = require('react/jsx-runtime');
function _toConsumableArray(r) {
  return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
}
function _nonIterableSpread() {
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _iterableToArray(r) {
  if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
}
function _arrayWithoutHoles(r) {
  if (Array.isArray(r)) return _arrayLikeToArray(r);
}
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 PostImageDropzone = function PostImageDropzone2(_ref) {
  var form = _ref.form;
  var _useState = _react.useState.call(void 0, ), _useState2 = _slicedToArray(_useState, 2), selectedPreview = _useState2[0], setSelectedPreview = _useState2[1];
  var _useState3 = _react.useState.call(void 0, ), _useState4 = _slicedToArray(_useState3, 2), selectedPreviewIndex = _useState4[0], setSelectedPreviewIndex = _useState4[1];
  var watch = form.watch;
  var formFiles = watch("images");
  var handleRemoveFile = function handleRemoveFile2(fileIndex) {
    var updatedFiles = formFiles === null || formFiles === void 0 ? void 0 : formFiles.filter(function(_, index) {
      return index !== fileIndex;
    });
    form.setValue("images", updatedFiles || [], {
      shouldValidate: true
    });
    if (selectedPreviewIndex === fileIndex) {
      setSelectedPreview(void 0);
      setSelectedPreviewIndex(void 0);
    }
  };
  var onSelect = function onSelect2(files) {
    if (files.length) {
      form.setValue("images", [].concat(_toConsumableArray(formFiles || []), _toConsumableArray(files)));
    }
  };
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _material.Box, {
    children: [selectedPreview && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Box, {
      width: "100%",
      position: "relative",
      height: "500px",
      mb: "24px",
      children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _image2.default, {
        src: URL.createObjectURL(selectedPreview),
        alt: selectedPreview.name,
        fill: true,
        style: {
          objectFit: "cover",
          borderRadius: "8px",
          height: "100%",
          width: "100%"
        },
        onLoad: function onLoad() {
          return URL.revokeObjectURL(URL.createObjectURL(selectedPreview));
        }
      })
    }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _dropzones.Dropzone, {
      onSelect,
      includeActionButton: false,
      maxFileSize: 15,
      onRemove: handleRemoveFile,
      InputContainerStyle: {
        backgroundColor: "transparent"
      },
      asBase64: false,
      multiple: true,
      accept: {
        "image/png": [".png"],
        "image/gif": [".gif"],
        "image/jpeg": [".jpg", ".jpeg"]
      },
      title: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Typography, {
        variant: "body2",
        sx: {
          color: "text.secondary"
        },
        children: "Click to browse or drag and drop images and videos."
      }),
      onFileClick: function onFileClick(selectedFile, index) {
        setSelectedPreview(selectedFile);
        setSelectedPreviewIndex(index);
      }
    })]
  });
};
var PostImageDropzone_default = PostImageDropzone;



exports.PostImageDropzone_default = PostImageDropzone_default;
//# sourceMappingURL=chunk-BZEK64RM.js.map