"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.useStyledContent = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _react = _interopRequireWildcard(require("react"));
var _FillPreviewSt = require("../FillPreview.st.css.js");
var _FillPreview = require("../FillPreview.utils");
var _classnames = _interopRequireDefault(require("classnames"));
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/FillPreview/hooks/useStyledContent.tsx";
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(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 (var _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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var useStyledContent = _ref => {
  var {
    contentClassName,
    disabled,
    fill
  } = _ref;
  return (0, _react.useMemo)(() => {
    if (!fill) {
      return {};
    }
    if (/*#__PURE__*/_react.default.isValidElement(fill)) {
      return {
        children: fill
      };
    }
    var backgroundStyles = (0, _FillPreview.getBackgroundStyles)(fill);
    var isMultiColor = Array.isArray(backgroundStyles);
    var colorCount = isMultiColor ? backgroundStyles.length : 1;
    var baseContentClassName = (0, _classnames.default)(contentClassName, (0, _FillPreviewSt.st)(_FillPreviewSt.classes.content, {
      colorCount
    }));
    if (disabled) {
      return {
        contentClassName: baseContentClassName
      };
    }
    if (isMultiColor) {
      var varMap = backgroundStyles.reduce((cssVarMap, bg, idx) => _objectSpread(_objectSpread({}, cssVarMap), {}, {
        [_FillPreviewSt.vars["fill-preview-background-color-".concat(idx)]]: bg.backgroundColor
      }), {});
      return {
        contentClassName: (0, _classnames.default)(baseContentClassName, _FillPreviewSt.classes.colorBackdrop),
        style: varMap,
        children: backgroundStyles.map((_, idx) => /*#__PURE__*/_react.default.createElement("span", {
          key: idx,
          __self: void 0,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 49,
            columnNumber: 52
          }
        }))
      };
    }
    return {
      contentClassName: (0, _classnames.default)(baseContentClassName, _FillPreviewSt.classes.imageBackdrop),
      style: _objectSpread(_objectSpread({}, backgroundStyles), {}, {
        [_FillPreviewSt.vars['fill-preview-background-image']]: backgroundStyles == null ? void 0 : backgroundStyles.backgroundImage
      })
    };
  }, [fill, disabled, contentClassName]);
};
exports.useStyledContent = useStyledContent;
//# sourceMappingURL=useStyledContent.js.map