import "./Content.css";
/* script */
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
import { createComponentName, componentMixin } from '../_utils/component';
import Button from '../Button';
import Icon from '../Icon';
import { REQUEST_RUL } from '../_utils/constant';
const DESC_MAP = {
  'praise': '谢谢您的支持',
  'blame': '我们将继续改进'
};
const __vue_script__ = {
  name: createComponentName('editor-help-content'),
  components: {
    Button,
    Icon
  },
  mixins: [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 REQUEST_RUL + '/help/' + this.id;
    },

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

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

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

    isBlame() {
      let 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: {
    async praise() {
      this.$emit('clickPraise');
    },

    async blame() {
      this.$emit('clickBlame');
    }

  }
};
/* template */

var __vue_render__ = function () {
  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 */

const __vue_inject_styles__ = undefined;
/* scoped */

const __vue_scope_id__ = undefined;
/* module identifier */

const __vue_module_identifier__ = undefined;
/* functional template */

const __vue_is_functional_template__ = false;
/* component normalizer */

import __vue_normalize__ from '../_utils/vue-normalize-component.js';
/* style inject */

/* style inject SSR */

export default __vue_normalize__({
  render: __vue_render__,
  staticRenderFns: __vue_staticRenderFns__
}, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__, __vue_module_identifier__, undefined, undefined);