"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

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

var _propTypes = _interopRequireDefault(require("prop-types"));

var _Tooltip = _interopRequireDefault(require("@material-ui/core/Tooltip"));

var _GridListTile = _interopRequireDefault(require("@material-ui/core/GridListTile"));

var _GridListTileBar = _interopRequireDefault(require("@material-ui/core/GridListTileBar"));

var _IconButton = _interopRequireDefault(require("@material-ui/core/IconButton"));

var _PlayArrow = _interopRequireDefault(require("@material-ui/icons/PlayArrow"));

var _api = require("subfirelib/api");

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

const CoverGridTile = props => {
  const useIdforArt = props.useIdforArt;
  const className = props.variant || '';
  const Icon = props.Icon;
  const onClick = props.onClick ? props.onClick.bind(props.onClick, props.id) : null;
  const onImageClick = props.onImageClick ? props.onImageClick.bind(props.onImageClick, props.id) : null;
  const coverArt = props.coverArt || (useIdforArt ? props.id : null);
  return /*#__PURE__*/_react.default.createElement(_Tooltip.default, {
    title: (props.name || props.title || '') + (props.subTitle ? ' - ' + props.subTitle : ''),
    arrow: true,
    placement: "top-start"
  }, /*#__PURE__*/_react.default.createElement(_GridListTile.default, {
    style: props.style
  }, /*#__PURE__*/_react.default.createElement("img", {
    crossOrigin: "anonymous",
    src: _api.Subsonic.getCoverArtURL(coverArt, props.size),
    alt: props.name || props.title || '',
    onClick: onImageClick,
    loading: "lazy"
  }), /*#__PURE__*/_react.default.createElement(_GridListTileBar.default, {
    title: props.name || props.title || '',
    subtitle: props.subTitle || props.artist || '',
    className: className,
    actionIcon: /*#__PURE__*/_react.default.createElement(_IconButton.default, {
      onClick: onClick,
      style: {
        color: '#fff'
      }
    }, /*#__PURE__*/_react.default.createElement(Icon, null))
  })));
};

CoverGridTile.propTypes = {
  name: _propTypes.default.string,
  title: _propTypes.default.string,
  // music directory when child recognized as an album
  subTitle: _propTypes.default.string,
  // populated by wrapper, defaults to artist for id3 album
  artist: _propTypes.default.string,
  // album or isDir album music directory
  id: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]).isRequired,
  onClick: _propTypes.default.func,
  onImageClick: _propTypes.default.func,
  size: _propTypes.default.number,
  Icon: _propTypes.default.object,
  variant: _propTypes.default.string,
  coverArt: _propTypes.default.string,
  useIdforArt: _propTypes.default.bool,
  style: _propTypes.default.any // passed in from GridList, and needs to be passed down.

};
CoverGridTile.defaultProps = {
  size: 192,
  Icon: _PlayArrow.default,
  useIdforArt: true
};
var _default = CoverGridTile;
exports.default = _default;