import v from "../../../@babel/runtime/helpers/esm/toConsumableArray.mjs";
import g from "../../../@babel/runtime/helpers/esm/defineProperty.mjs";
import u from "../../../@babel/runtime/helpers/esm/objectSpread2.mjs";
import _ from "../../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import * as c from "react";
import { COMMON_PROPS as l } from "../common.mjs";
function y(n) {
  var s = c.useState({}), i = _(s, 2), o = i[0], f = i[1], m = c.useCallback(function(r, t) {
    return f(function(e) {
      return u(u({}, e), {}, g({}, r, t));
    }), function() {
      f(function(e) {
        var a = u({}, e);
        return delete a[r], a;
      });
    };
  }, []), d = c.useMemo(function() {
    return n ? n.map(function(r) {
      if (typeof r == "string")
        return {
          data: {
            src: r
          }
        };
      var t = {};
      return Object.keys(r).forEach(function(e) {
        ["src"].concat(v(l)).includes(e) && (t[e] = r[e]);
      }), {
        data: t
      };
    }) : Object.keys(o).reduce(function(r, t) {
      var e = o[t], a = e.canPreview, p = e.data;
      return a && r.push({
        data: p,
        id: t
      }), r;
    }, []);
  }, [n, o]);
  return [d, m];
}
export {
  y as default
};
