"use strict";

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

var _react = require("react");

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

var _copyToClipboard = _interopRequireDefault(require("copy-to-clipboard"));

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

var _lodash = require("lodash");

var _window = _interopRequireDefault(require("global/window"));

var _CivicStoryLink = _interopRequireDefault(require("./CivicStoryLink"));

var _styleConstants = require("../styleConstants");

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

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _templateObject3() {
  var data = _taggedTemplateLiteral(["\n  margin-right: 0;\n  display: flex;\n"]);

  _templateObject3 = function _templateObject3() {
    return data;
  };

  return data;
}

function _templateObject2() {
  var data = _taggedTemplateLiteral(["\n  margin-left: 0;\n  display: flex;\n"]);

  _templateObject2 = function _templateObject2() {
    return data;
  };

  return data;
}

function _templateObject() {
  var data = _taggedTemplateLiteral(["\n  background: #eee;\n  display: flex;\n  justify-content: space-between;\n  margin: -3em;\n  margin-top: 2em;\n  padding: 0 3em;\n  @media (max-width: 640px) {\n    margin: -3em -2em;\n    margin-top: 2em;\n    padding: 0;\n  }\n"]);

  _templateObject = function _templateObject() {
    return data;
  };

  return data;
}

function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }

var MS_TO_SWITCH_TEXT = 3000;
var actionsClass = (0, _core.css)(_templateObject());
var alignRight = (0, _core.css)(_templateObject2());
var alignLeft = (0, _core.css)(_templateObject3());

var StoryFooter = function (_Component) {
  _inherits(StoryFooter, _Component);

  function StoryFooter(props) {
    var _this;

    _classCallCheck(this, StoryFooter);

    _this = _possibleConstructorReturn(this, _getPrototypeOf(StoryFooter).call(this, props));

    _defineProperty(_assertThisInitialized(_this), "setToFalse", function () {
      return _this.setState({
        copied: false
      });
    });

    _defineProperty(_assertThisInitialized(_this), "handleCopy", function () {
      var slug = _this.props.slug;
      (0, _copyToClipboard["default"])("".concat((0, _lodash.get)(_window["default"], "location.origin", ""), "/cards/").concat(slug));

      _this.switchState(MS_TO_SWITCH_TEXT);

      _this.setState({
        copied: true
      });
    });

    _defineProperty(_assertThisInitialized(_this), "switchState", function (ms) {
      return setTimeout(_this.setToFalse, ms);
    });

    _this.state = {
      copied: false
    };
    return _this;
  }

  _createClass(StoryFooter, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          slug = _this$props.slug,
          source = _this$props.source;
      var copied = this.state.copied;
      var shareTxt = copied ? "Copied!" : "Share";
      var shareIcon = copied ? _styleConstants.ICONS.check : _styleConstants.ICONS.link;
      var isEmbedded = "".concat((0, _lodash.get)(_window["default"], "location.origin", ""), "/cards/").concat(slug, "/embed/") === (0, _lodash.get)(_window["default"], "location.href", "");
      var issue = "https://github.com/hackoregon/civic/issues/new?labels=type%3Astory-card&template=story-card-improve.md&title=[FEEDBACK] ".concat(slug);
      return (0, _core.jsx)("div", {
        css: actionsClass
      }, (0, _core.jsx)("div", {
        css: alignLeft
      }, (0, _core.jsx)(_CivicStoryLink["default"], {
        link: source,
        embed: isEmbedded,
        route: source ? undefined : "/cards/".concat(slug),
        icon: _styleConstants.ICONS.info
      }, "Source")), (0, _core.jsx)("div", {
        css: alignRight
      }, (0, _core.jsx)(_CivicStoryLink["default"], {
        additionalClassName: alignRight,
        link: issue,
        embed: isEmbedded,
        icon: _styleConstants.ICONS.improve
      }, "Improve"), (0, _core.jsx)(_CivicStoryLink["default"], {
        additionalClassName: alignRight,
        action: this.handleCopy,
        icon: shareIcon
      }, shareTxt)));
    }
  }]);

  return StoryFooter;
}(_react.Component);

exports["default"] = StoryFooter;

_defineProperty(StoryFooter, "defaultProps", {
  slug: "some-card-id"
});

_defineProperty(StoryFooter, "propTypes", {
  slug: _propTypes["default"].string,
  source: _propTypes["default"].string
});