"use strict";

exports.__esModule = true;
exports.default = CustomAdv;

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

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

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

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

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

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

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

const PREFIX = 'SCCustomAdv';
const classes = {
  root: `${PREFIX}-root`,
  image: `${PREFIX}-image`
};
const Root = (0, _styles.styled)(_material.Box, {
  name: PREFIX,
  slot: 'Root',
  overridesResolver: (props, styles) => styles.root
})(({
  theme
}) => ({
  marginBottom: theme.spacing(2),
  [`& .${classes.image}`]: {
    width: '100%'
  }
}));

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

 #### CSS

 |Rule Name|Global class|Description|
 |---|---|---|
 |root|.SCCustomAdv-root|Styles applied to the root element.|
 |image|.SCCustomAdv-image|Styles applied to the image element.|

 * @param inProps
 */
function CustomAdv(inProps) {
  // PROPS
  const props = (0, _useThemeProps.default)({
    props: inProps,
    name: PREFIX
  });
  const {
    id = 'custom_adv',
    className = null,
    position,
    categoriesId = null
  } = props; // retrieve adv

  const {
    scCustomAdv
  } = (0, _core.useSCFetchCustomAdv)({
    position,
    categoriesId
  });

  if (!scCustomAdv) {
    return null;
  }

  const adv = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, scCustomAdv.image && /*#__PURE__*/_react.default.createElement("img", {
    src: scCustomAdv.image,
    alt: scCustomAdv.title,
    className: classes.image
  }), scCustomAdv.embed_code && /*#__PURE__*/_react.default.createElement("span", {
    dangerouslySetInnerHTML: {
      __html: scCustomAdv.embed_code
    }
  }));

  return /*#__PURE__*/_react.default.createElement(Root, {
    id: id,
    className: (0, _classnames.default)(classes.root, className)
  }, scCustomAdv.link ? /*#__PURE__*/_react.default.createElement("a", {
    href: scCustomAdv.link,
    title: scCustomAdv.title
  }, adv) : adv);
}