"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.UploadButton = exports.InsertButton = exports.DownloadButton = exports.DeleteButton = exports.CopyToClipBoardButton = void 0;
var _base = _interopRequireDefault(require("@emotion/styled/base"));
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react2 = require("@emotion/react");
var _copyTextToClipboard = _interopRequireDefault(require("copy-text-to-clipboard"));
var _decapCmsLibUtil = require("decap-cms-lib-util");
var _decapCmsUiDefault = require("decap-cms-ui-default");
var _UI = require("../UI");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
const styles = {
  button: /*#__PURE__*/(0, _react2.css)(_decapCmsUiDefault.buttons.button, ";", _decapCmsUiDefault.buttons.default, ";display:inline-block;margin-left:15px;margin-right:2px;&[disabled]{", _decapCmsUiDefault.buttons.disabled, ";cursor:default;};label:button;" + (process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 4216 characters] */"))
};
const UploadButton = exports.UploadButton = /*#__PURE__*/(0, _base.default)(_UI.FileUploadButton, {
  target: "e288rjk3",
  label: "UploadButton"
})(styles.button, ";", _decapCmsUiDefault.buttons.gray, ";", _decapCmsUiDefault.shadows.dropMain, ";margin-bottom:0;span{font-size:14px;font-weight:500;display:flex;justify-content:center;align-items:center;}input{height:0.1px;width:0.1px;margin:0;padding:0;opacity:0;overflow:hidden;position:absolute;z-index:", _decapCmsUiDefault.zIndex.zIndex0, ";outline:none;}" + (process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 4220 characters] */"));
const DeleteButton = exports.DeleteButton = /*#__PURE__*/(0, _base.default)("button", {
  target: "e288rjk2",
  label: "DeleteButton"
})(styles.button, ";", _decapCmsUiDefault.buttons.lightRed, ";" + (process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 4220 characters] */"));
const InsertButton = exports.InsertButton = /*#__PURE__*/(0, _base.default)("button", {
  target: "e288rjk1",
  label: "InsertButton"
})(styles.button, ";", _decapCmsUiDefault.buttons.green, ";" + (process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 4220 characters] */"));
const ActionButton = /*#__PURE__*/(0, _base.default)("button", {
  target: "e288rjk0",
  label: "ActionButton"
})(styles.button, ";", props => !props.disabled && /*#__PURE__*/(0, _react2.css)(_decapCmsUiDefault.buttons.gray, ";;label:ActionButton;" + (process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 4216 characters] */")), ";" + (process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 4220 characters] */"));
const DownloadButton = exports.DownloadButton = ActionButton;
class CopyToClipBoardButton extends _react.default.Component {
  constructor(...args) {
    super(...args);
    _defineProperty(this, "mounted", false);
    _defineProperty(this, "timeout", void 0);
    _defineProperty(this, "state", {
      copied: false
    });
    _defineProperty(this, "handleCopy", () => {
      clearTimeout(this.timeout);
      const {
        path,
        draft,
        name
      } = this.props;
      (0, _copyTextToClipboard.default)((0, _decapCmsLibUtil.isAbsolutePath)(path) || !draft ? path : name);
      this.setState({
        copied: true
      });
      this.timeout = setTimeout(() => this.mounted && this.setState({
        copied: false
      }), 1500);
    });
    _defineProperty(this, "getTitle", () => {
      const {
        t,
        path,
        draft
      } = this.props;
      if (this.state.copied) {
        return t('mediaLibrary.mediaLibraryCard.copied');
      }
      if (!path) {
        return t('mediaLibrary.mediaLibraryCard.copy');
      }
      if ((0, _decapCmsLibUtil.isAbsolutePath)(path)) {
        return t('mediaLibrary.mediaLibraryCard.copyUrl');
      }
      if (draft) {
        return t('mediaLibrary.mediaLibraryCard.copyName');
      }
      return t('mediaLibrary.mediaLibraryCard.copyPath');
    });
  }
  componentDidMount() {
    this.mounted = true;
  }
  componentWillUnmount() {
    this.mounted = false;
  }
  render() {
    const {
      disabled
    } = this.props;
    return (0, _react2.jsx)(ActionButton, {
      disabled: disabled,
      onClick: this.handleCopy
    }, this.getTitle());
  }
}
exports.CopyToClipBoardButton = CopyToClipBoardButton;
CopyToClipBoardButton.propTypes = {
  disabled: _propTypes.default.bool.isRequired,
  draft: _propTypes.default.bool,
  path: _propTypes.default.string,
  name: _propTypes.default.string,
  t: _propTypes.default.func.isRequired
};