"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 = {
  "": "\u0627\u0646\u062A\u062E\u0627\u0628 \u062D\u0642\u0648\u0642 \u0627\u0633\u062A\u0641\u0627\u062F\u0647...",
  own_copyright: "\u062D\u0642 \u0646\u0634\u0631 \u062F\u0627\u0631\u0645",
  used_by_permission: "\u0645\u062C\u0648\u0632 \u0627\u0633\u062A\u0641\u0627\u062F\u0647 \u0627\u0632 \u0627\u06CC\u0646 \u0641\u0627\u06CC\u0644 \u0631\u0627 \u0628\u0647 \u062F\u0633\u062A \u0622\u0648\u0631\u062F\u0647 \u0627\u0645.",
  public_domain: "\u0645\u0637\u0644\u0628 \u062F\u0631 \u062F\u0627\u0645\u0646\u0647 \u0639\u0645\u0648\u0645\u06CC \u0627\u0633\u062A",
  fair_use: "\u0645\u0637\u0644\u0628 \u0645\u0634\u0645\u0648\u0644 \u0627\u0633\u062A\u062B\u0646\u0627\u0621 \u0627\u0633\u062A\u0641\u0627\u062F\u0647 \u0645\u0646\u0635\u0641\u0627\u0646\u0647 \u0627\u0633\u062A",
  creative_commons: "\u0645\u0637\u0644\u0628 \u062A\u062D\u062A \u0645\u062C\u0648\u0632 \u06A9\u0631\u06CC\u062A\u06CC\u0648 \u06A9\u0627\u0645\u0646\u0632 \u0627\u0633\u062A"
}; // 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: "\u0627\u0631\u062C\u0627\u0639 \u06A9\u0631\u06CC\u062A\u06CC\u0648 \u06A9\u0627\u0645\u0646\u0632\u060C \u063A\u06CC\u0631 \u062A\u062C\u0627\u0631\u06CC\u060C \u0628\u062F\u0648\u0646 \u0622\u062B\u0627\u0631 \u0627\u0634\u062A\u0642\u0627\u0642\u06CC",
  cc_by_nc_sa: "\u0627\u0631\u062C\u0627\u0639 \u06A9\u0631\u06CC\u062A\u06CC\u0648 \u06A9\u0627\u0645\u0646\u0632\u060C \u063A\u06CC\u0631 \u062A\u062C\u0627\u0631\u06CC\u060C \u0627\u0634\u062A\u0631\u0627\u06A9 \u0633\u0627\u0632\u06CC \u06CC\u06A9\u0633\u0627\u0646",
  cc_by_nc: "\u0627\u0631\u062C\u0627\u0639 \u06A9\u0631\u06CC\u062A\u06CC\u0648 \u06A9\u0627\u0645\u0646\u0632\u060C \u063A\u06CC\u0631 \u062A\u062C\u0627\u0631\u06CC",
  cc_by_nd: "\u0627\u0631\u062C\u0627\u0639 \u06A9\u0631\u06CC\u062A\u06CC\u0648 \u06A9\u0627\u0645\u0646\u0632\u060C \u0628\u062F\u0648\u0646 \u0622\u062B\u0627\u0631 \u0627\u0634\u062A\u0642\u0627\u0642\u06CC",
  cc_by_sa: "\u0627\u0631\u062C\u0627\u0639 \u06A9\u0631\u06CC\u062A\u06CC\u0648 \u06A9\u0627\u0645\u0646\u0632\u060C \u0627\u0634\u062A\u0631\u0627\u06A9 \u0633\u0627\u0632\u06CC \u06CC\u06A9\u0633\u0627\u0646",
  cc_by: "\u0627\u0631\u062C\u0627\u0639 \u06A9\u0631\u06CC\u062A\u06CC\u0648 \u06A9\u0627\u0645\u0646\u0632"
};

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: "\u062D\u0642 \u0627\u0633\u062A\u0641\u0627\u062F\u0647:",
        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: "\u0645\u062C\u0648\u0632 \u06A9\u0631\u06CC\u062A\u06CC\u0648 \u06A9\u0627\u0645\u0646\u0632:",
        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: "\u062F\u0627\u0631\u0646\u062F\u0647 \u062D\u0642 \u0646\u0634\u0631:",
        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"
      }), " If you do not select usage rights now, this file will be unpublished after it's uploaded."));
    }
  }]);
  UsageRightsForm.displayName = "UsageRightsForm";
  return UsageRightsForm;
}(_react.Component);

exports.default = UsageRightsForm;