"use strict";

require("core-js/modules/web.dom-collections.iterator.js");

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

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

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

var _VolumeDown = _interopRequireDefault(require("@material-ui/icons/VolumeDown"));

var _VolumeOff = _interopRequireDefault(require("@material-ui/icons/VolumeOff"));

var _VolumeUp = _interopRequireDefault(require("@material-ui/icons/VolumeUp"));

var _Slider = _interopRequireDefault(require("@material-ui/core/Slider"));

var _TG = require("subfirelib/ui/TG");

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

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

// import { makeStyles } from '@material-ui/core/styles';
function VolumeControl(props) {
  const {
    volume = 1,
    setVolume
  } = props;
  const [volumeBeforeMute, setVolumeBeforeMute] = (0, _react.useState)(volume);

  const muteClick = () => {
    if (volume === 0) {
      setVolume(volumeBeforeMute);
    } else {
      setVolumeBeforeMute(volume);
      setVolume(0);
    }
  };

  const maxClick = () => {
    setVolume(Math.min(volume + 0.1, 1));
  };

  return /*#__PURE__*/_react.default.createElement(_TG.Gc, {
    spacing: 2
  }, /*#__PURE__*/_react.default.createElement(_TG.Gi, null, volume === 0 ? /*#__PURE__*/_react.default.createElement(_VolumeOff.default, {
    onClick: muteClick
  }) : /*#__PURE__*/_react.default.createElement(_VolumeDown.default, {
    onClick: muteClick
  })), /*#__PURE__*/_react.default.createElement(_TG.Gi, {
    xs: true
  }, /*#__PURE__*/_react.default.createElement(_Slider.default, {
    min: 0,
    max: 40,
    step: 1,
    value: volume * 40,
    onChange: (event, newValue) => setVolume(newValue / 40)
  })), /*#__PURE__*/_react.default.createElement(_TG.Gi, null, /*#__PURE__*/_react.default.createElement(_VolumeUp.default, {
    onClick: maxClick
  })));
}

VolumeControl.propTypes = {
  volume: _propTypes.default.number,
  setVolume: _propTypes.default.func
};
var _default = VolumeControl;
exports.default = _default;