"use strict";

exports.__esModule = true;
exports.default = PollSnippet;

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

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

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

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

var _reactIntl = require("react-intl");

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

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

var _contribution = require("../../../utils/contribution");

var _BaseItemButton = _interopRequireDefault(require("../../../shared/BaseItemButton"));

const _excluded = ["feedObj", "className", "autoHide"];

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); }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

const PREFIX = 'SCPollSnippet';
const classes = {
  root: `${PREFIX}-root`,
  title: `${PREFIX}-title`,
  action: `${PREFIX}-action`,
  seeItem: `${PREFIX}-see-item`
};
const Root = (0, _styles.styled)(_BaseItemButton.default, {
  name: PREFIX,
  slot: 'Root',
  overridesResolver: (props, styles) => styles.root
})(({
  theme
}) => ({}));

/**
 * > API documentation for the Community-UI PollSnippet component. Learn about the available props and the CSS API.
 *
 * #### Import
 ```jsx
 import {PollSnippet} from '@selfcommunity/ui';
 ```
 #### Component Name
 The name `SCPollSnippet` can be used when providing style overrides in the theme.

 #### CSS

 |Rule Name|Global class|Description|
 |---|---|---|
 |root|.SCPollSnippet-root|Styles applied to the root element.|
 |title|.SCPollSnippet-title|Styles applied to the title element.|
 |action|.SCPollSnippet-actions|Styles applied to action section.|
 |seeItem|.SCPollSnippet-see-item|Styles applied to the see item button element.|

 * @param inProps
 */
function PollSnippet(inProps) {
  // PROPS
  const props = (0, _useThemeProps.default)({
    props: inProps,
    name: PREFIX
  });

  const {
    feedObj = null,
    className = null,
    autoHide = false
  } = props,
        rest = _objectWithoutPropertiesLoose(props, _excluded); // CONTEXT


  const scRoutingContext = (0, _core.useSCRouting)(); // RENDER

  if (!autoHide) {
    var _feedObj$summary;

    return /*#__PURE__*/_react.default.createElement(Root, _extends({}, rest, {
      className: (0, _classnames.default)(classes.root, className),
      primary: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_material.Typography, null, feedObj.author.username), /*#__PURE__*/_react.default.createElement(_material.Typography, {
        variant: "body1",
        className: classes.title
      }, feedObj.poll.title)),
      secondary: /*#__PURE__*/_react.default.createElement(_material.Typography, {
        variant: "body2",
        sx: {
          whiteSpace: 'nowrap',
          overflow: 'hidden',
          textOverflow: 'ellipsis'
        },
        dangerouslySetInnerHTML: {
          __html: (_feedObj$summary = feedObj.summary) != null ? _feedObj$summary : null
        }
      }),
      actions: /*#__PURE__*/_react.default.createElement(_material.Button, {
        size: "small",
        variant: "outlined",
        className: classes.seeItem,
        component: _core.Link,
        to: scRoutingContext.url((0, _contribution.getContributionRouteName)(feedObj), (0, _contribution.getRouteData)(feedObj))
      }, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
        id: "ui.pollSuggestion.pollSnippet.button.seeItem",
        defaultMessage: "ui.pollSuggestion.pollSnippet.button.seeItem"
      }))
    }));
  }

  return null;
}