"use strict";

exports.__esModule = true;
exports.default = Actions;

var _react = _interopRequireDefault(require("react"));

var _styles = require("@mui/material/styles");

var _material = require("@mui/material");

var _Vote = _interopRequireDefault(require("./Vote"));

var _Comment = _interopRequireDefault(require("./Comment"));

var _Share = _interopRequireDefault(require("./Share"));

var _core = require("@selfcommunity/core");

var _feedObject = require("../../../types/feedObject");

var _classnames = _interopRequireDefault(require("classnames"));

var _useThemeProps = _interopRequireDefault(require("@mui/material/styles/useThemeProps"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

const PREFIX = 'SCFeedObjectActions';
const classes = {
  root: `${PREFIX}-root`,
  action: `${PREFIX}-action`
};
const Root = (0, _styles.styled)(_material.Grid, {
  name: PREFIX,
  slot: 'Root',
  overridesResolver: (props, styles) => styles.root
})(() => ({
  margin: '0px 0px',
  color: '#3A3A3A',
  [`& .${classes.action}`]: {
    textAlign: 'center'
  }
}));

function Actions(inProps) {
  // PROPS
  const props = (0, _useThemeProps.default)({
    props: inProps,
    name: PREFIX
  });
  const {
    className,
    feedObjectId,
    feedObject,
    feedObjectType = _core.SCFeedObjectTypologyType.POST,
    feedObjectTemplate = _feedObject.SCFeedObjectTemplateType.PREVIEW,
    hideVoteAction = false,
    hideShareAction = false,
    hideCommentAction = false,
    handleExpandActivities,
    VoteActionProps = {
      inlineAction: false
    },
    CommentActionProps = {
      inlineAction: false
    },
    ShareActionProps = {
      inlineAction: false
    }
  } = props; // STATE

  const {
    obj,
    setObj
  } = (0, _core.useSCFetchFeedObject)({
    id: feedObjectId,
    feedObject,
    feedObjectType
  });

  if (!obj) {
    return null;
  }
  /**
   * Calculate column width
   */


  function getColumnWidth() {
    let width = 4;

    if (hideShareAction && hideCommentAction) {
      width = 12;
    } else if (hideCommentAction || hideCommentAction) {
      width = 6;
    }

    return width;
  }
  /**
   * Renders action section
   */


  const columnWidth = getColumnWidth();
  return /*#__PURE__*/_react.default.createElement(Root, {
    container: true,
    className: (0, _classnames.default)(classes.root, className)
  }, !hideVoteAction && /*#__PURE__*/_react.default.createElement(_material.Grid, {
    item: true,
    xs: columnWidth,
    className: classes.action
  }, /*#__PURE__*/_react.default.createElement(_Vote.default, _extends({
    feedObject: obj,
    feedObjectType: feedObjectType
  }, VoteActionProps))), !hideCommentAction && /*#__PURE__*/_react.default.createElement(_material.Grid, {
    item: true,
    xs: columnWidth,
    className: classes.action
  }, /*#__PURE__*/_react.default.createElement(_Comment.default, _extends({
    feedObject: obj,
    feedObjectType: feedObjectType,
    feedObjectTemplate: feedObjectTemplate,
    onCommentAction: handleExpandActivities
  }, CommentActionProps))), !hideShareAction && /*#__PURE__*/_react.default.createElement(_material.Grid, {
    item: true,
    xs: columnWidth,
    className: classes.action
  }, /*#__PURE__*/_react.default.createElement(_Share.default, _extends({
    feedObject: obj,
    feedObjectType: feedObjectType,
    id: feedObjectId
  }, ShareActionProps))));
}