"use strict";

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

exports.__esModule = true;
exports.default = void 0;

var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));

require("regenerator-runtime/runtime");

var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/asyncToGenerator"));

require("./content.css");

var _base = require("../../utils/base");

var _button = _interopRequireDefault(require("../button"));

var _icon = _interopRequireDefault(require("../icon"));

var _constant = require("../../utils/constant");

var _vueNormalizeComponent = _interopRequireDefault(require("../../utils/vue-normalize-component.js"));

/* script */
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
var DESC_MAP = {
  'praise': '谢谢您的支持',
  'blame': '我们将继续改进'
};
var __vue_script__ = {
  name: (0, _base.createComponentName)('editor-help-content'),
  components: {
    Button: _button.default,
    Icon: _icon.default
  },
  mixins: [_base.componentMixin],
  model: {
    name: 'status',
    event: 'change'
  },
  props: {
    content: {
      type: String,
      default: null
    },
    status: {
      // status: praise(👍) onpraise(👍...) blame(👎) onblame(👎...)
      type: String,
      default: null
    },
    // 了解更多地址
    id: {
      type: Number,
      required: true
    }
  },

  data() {
    return {
      lastStatus: this.status
    };
  },

  computed: {
    link() {
      return _constant.REQUEST_RUL + '/help/' + this.id;
    },

    decs() {
      if (this.error) return '加载失败，请重试!';
      var status = this.loading ? this.lastStatus : this.status;
      return DESC_MAP[status] || '这条帮助对您有帮助吗?';
    },

    loading() {
      return this.status && this.status.indexOf('on') > -1;
    },

    isPraise() {
      var status = this.error ? this.lastStatus : this.status;
      status = this.loading ? this.lastStatus : this.status;
      return status && status.indexOf('praise') > -1;
    },

    isBlame() {
      var status = this.error ? this.lastStatus : this.status;
      status = this.loading ? this.lastStatus : this.status;
      return status && status.indexOf('blame') > -1;
    },

    error() {
      return this.status && this.status.indexOf('error') > -1;
    }

  },
  watch: {
    status(value, old) {
      if (old === 'praise' || old === 'blame' || old === null) {
        this.lastStatus = old;
      }
    }

  },
  methods: {
    praise() {
      var _this = this;

      return (0, _asyncToGenerator2.default)(
      /*#__PURE__*/
      _regenerator.default.mark(function _callee() {
        return _regenerator.default.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                _this.$emit('clickPraise');

              case 1:
              case "end":
                return _context.stop();
            }
          }
        }, _callee, this);
      }))();
    },

    blame() {
      var _this2 = this;

      return (0, _asyncToGenerator2.default)(
      /*#__PURE__*/
      _regenerator.default.mark(function _callee2() {
        return _regenerator.default.wrap(function _callee2$(_context2) {
          while (1) {
            switch (_context2.prev = _context2.next) {
              case 0:
                _this2.$emit('clickBlame');

              case 1:
              case "end":
                return _context2.stop();
            }
          }
        }, _callee2, this);
      }))();
    }

  }
};
/* template */

var __vue_render__ = function __vue_render__() {
  var _vm = this;

  var _h = _vm.$createElement;

  var _c = _vm._self._c || _h;

  return _c("div", {
    class: _vm.bem()
  }, [_c("div", {
    class: _vm.bem("html"),
    domProps: {
      innerHTML: _vm._s(_vm.content)
    }
  }), _vm._v(" "), _c("div", {
    class: _vm.bem("footer")
  }, [_c("transition-group", {
    class: _vm.bem("panel"),
    attrs: {
      name: _vm.bem("fade")
    }
  }, [_c("span", {
    key: "desc"
  }, [_vm._v(_vm._s(_vm.decs))]), _vm._v(" "), !_vm.isBlame ? _c("Button", {
    key: "praise",
    attrs: {
      icon: "praise",
      round: "",
      disabled: _vm.loading,
      type: _vm.isPraise ? "primary" : null
    },
    on: {
      click: _vm.praise
    }
  }, [_vm._v("\n                有用\n            ")]) : _vm._e(), _vm._v(" "), !_vm.isPraise ? _c("Button", {
    key: "blame",
    attrs: {
      icon: "blame",
      round: "",
      disabled: _vm.loading,
      type: _vm.isBlame ? "primary" : null
    },
    on: {
      click: _vm.blame
    }
  }, [_vm._v("\n                没用\n            ")]) : _vm._e()], 1), _vm._v(" "), _vm.link ? _c("Button", {
    attrs: {
      type: "text",
      target: "_block",
      href: _vm.link
    }
  }, [_vm._v("\n            了解更多\n            "), _c("Icon", {
    attrs: {
      name: "double-right"
    }
  })], 1) : _vm._e()], 1)]);
};

var __vue_staticRenderFns__ = [];
__vue_render__._withStripped = true;
/* style */

var __vue_inject_styles__ = undefined;
/* scoped */

var __vue_scope_id__ = undefined;
/* module identifier */

var __vue_module_identifier__ = undefined;
/* functional template */

var __vue_is_functional_template__ = false;
/* component normalizer */

/* style inject */

/* style inject SSR */
var _default = (0, _vueNormalizeComponent.default)({
  render: __vue_render__,
  staticRenderFns: __vue_staticRenderFns__
}, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__, __vue_module_identifier__, undefined, undefined);

exports.default = _default;