import React, { PureComponent } from "react";
import classnames from "classnames";
import iconfont from "../../iconfont/iconfont.css";
import styles from "./index.less";

/**
 * 自定义 icon 展示
 * @description 用法：<CustIcon type="icon-qiuguanzhu" status={item.inFav} onClick={this.ifClickAlert.bind(this)} />
 */
export default class CustIcon extends PureComponent {
  render() {
    const { type, status, onClick, ...props } = this.props;
    const _status = status ? status : STATUS.NORMAL;
    return (
      <i
        className={classnames(
          iconfont[NAMESPACE],
          styles.iconStyle,
          _status == STATUS.ACTIVITY ? iconfont[`${type}-i`] : iconfont[type],
          {
            "icon-disable": _status == STATUS.DISABLE,
            "icon-activity": _status == STATUS.ACTIVITY,
            "icon-normal": _status == STATUS.NORMAL
          }
        )}
        {...props}
        onClick={
          onClick ||
          function() {
            return true;
          }
        }
      />
    );
  }
}

export const STATUS = Object.freeze({
  DISABLE: -1, // 禁用
  NORMAL: 0, // 正常
  ACTIVITY: 1 // 激活
});
export const NAMESPACE = "buyer-iconfont";
