"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

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

var _formatMessage = _interopRequireDefault(require("../../format-message"));

var _Select = _interopRequireDefault(require("@instructure/ui-core/lib/components/Select"));

var _TextInput = _interopRequireDefault(require("@instructure/ui-forms/lib/components/TextInput"));

var _Alert = _interopRequireDefault(require("@instructure/ui-alerts/lib/components/Alert"));

/*
 * Copyright (C) 2018 - present Instructure, Inc.
 *
 * This file is part of Canvas.
 *
 * Canvas is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License as published by the Free
 * Software Foundation, version 3 of the License.
 *
 * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */
var usageRightsValues = {
  "": "\u9009\u62E9\u4F7F\u7528\u6743\u9650...",
  own_copyright: "\u6211\u6301\u6709\u7248\u6743",
  used_by_permission: "\u6211\u5DF2\u83B7\u5F97\u4F7F\u7528\u6B64\u6587\u4EF6\u7684\u6743\u9650\u3002",
  public_domain: "\u6750\u6599\u5728\u516C\u5F00\u57DF\u4E2D",
  fair_use: "\u6750\u6599\u53D7\u516C\u6B63\u4F7F\u7528\u4F8B\u5916\u7684\u7EA6\u675F",
  creative_commons: "\u6750\u6599\u5DF2\u6839\u636E Creative Commons \u8BB8\u53EF"
}; // Note: These are hard-coded here to avoid making an additional API call to
// get the hard-coded list from the server. This will need to change if the
// license options become more dynamic in the future.

var creativeCommonsLicenses = {
  cc_by_nc_nd: "CC \u7F72\u540D\u3001\u975E\u5546\u4E1A\u3001\u7981\u6B62\u6539\u5199",
  cc_by_nc_sa: "CC \u7F72\u540D\u3001\u975E\u5546\u4E1A\u3001\u76F8\u540C\u65B9\u5F0F\u5171\u4EAB",
  cc_by_nc: "CC \u7F72\u540D\u3001\u975E\u5546\u4E1A",
  cc_by_nd: "CC \u7F72\u540D\u3001\u7981\u6B62\u6539\u5199",
  cc_by_sa: "CC \u7F72\u540D\u3001\u76F8\u540C\u65B9\u5F0F\u5171\u4EAB",
  cc_by: "CC \u7F72\u540D"
};

var UsageRightsForm =
/*#__PURE__*/
function (_Component) {
  (0, _inherits2.default)(UsageRightsForm, _Component);

  function UsageRightsForm() {
    var _this;

    (0, _classCallCheck2.default)(this, UsageRightsForm);
    _this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(UsageRightsForm).call(this));

    _this.handleUsageRight = function (ev) {
      _this.setState({
        usageRight: ev.target.value
      });
    };

    _this.handleCCLicense = function (ev) {
      _this.setState({
        ccLicense: ev.target.value
      });
    };

    _this.handleCopyrightHolder = function (ev) {
      _this.setState({
        copyrightHolder: ev.target.value
      });
    };

    _this.state = {
      usageRight: Object.keys(usageRightsValues)[0],
      copyrightHolder: ""
    };
    return _this;
  }

  (0, _createClass2.default)(UsageRightsForm, [{
    key: "isCreativeCommons",
    value: function isCreativeCommons() {
      return this.state.usageRight === "creative_commons";
    }
  }, {
    key: "isNotSelected",
    value: function isNotSelected() {
      return this.state.usageRight === Object.keys(usageRightsValues)[0];
    }
  }, {
    key: "value",
    value: function value() {
      if (this.isNotSelected()) {
        return null;
      }

      var state = (0, _objectSpread2.default)({}, this.state);

      if (!this.isCreativeCommons()) {
        delete state.ccLicense;
      }

      return state;
    }
  }, {
    key: "render",
    value: function render() {
      return _react.default.createElement("div", {
        className: "rcs-UsageRightsForm"
      }, _react.default.createElement(_Select.default, {
        label: "\u4F7F\u7528\u6743\u9650\uFF1A",
        value: this.state.usageRight,
        onChange: this.handleUsageRight
      }, Object.keys(usageRightsValues).map(function (key) {
        return _react.default.createElement("option", {
          key: key,
          value: key
        }, usageRightsValues[key]);
      })), this.isCreativeCommons() && _react.default.createElement(_Select.default, {
        label: "Creative Commons \u8BB8\u53EF\u8BC1\uFF1A",
        value: this.state.ccLicense,
        onChange: this.handleCCLicense
      }, Object.keys(creativeCommonsLicenses).map(function (key) {
        return _react.default.createElement("option", {
          key: key,
          value: key
        }, creativeCommonsLicenses[key]);
      })), _react.default.createElement(_TextInput.default, {
        label: "\u7248\u6743\u6301\u6709\u8005\uFF1A",
        placeholder: "(c) 2001 Acme Inc.",
        value: this.state.copyrightHolder,
        onChange: this.handleCopyrightHolder
      }), this.isNotSelected() && _react.default.createElement(_Alert.default, {
        variant: "warning"
      }, _react.default.createElement("i", {
        className: "icon-warning"
      }), " \u5982\u679C\u60A8\u73B0\u5728\u4E0D\u9009\u62E9\u4F7F\u7528\u6743\u9650\uFF0C\u8BE5\u6587\u4EF6\u5728\u4E0A\u4F20\u540E\u4E0D\u4F1A\u88AB\u53D1\u5E03\u3002"));
    }
  }]);
  UsageRightsForm.displayName = "UsageRightsForm";
  return UsageRightsForm;
}(_react.Component);

exports.default = UsageRightsForm;