function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import React from 'react';
import Wrapper from "./Wrapper";

// 内库使用-start
import DOMUtil from "./../../../utils/DOMUtil";
import Checkbox from "./../../Checkbox";
// 内库使用-end

/* 测试使用-start
import { DOMUtil,Checkbox } from 'seedsui-react'
测试使用-end */

var Item = function Item(_ref) {
  var wrapper = _ref.wrapper,
    disabled = _ref.disabled,
    image = _ref.image,
    avatar = _ref.avatar,
    title = _ref.title,
    description = _ref.description,
    note = _ref.note,
    content = _ref.content,
    action = _ref.action,
    itemData = _ref.itemData,
    layout = _ref.layout,
    checkable = _ref.checkable,
    checkbox = _ref.checkbox,
    checkboxProps = _ref.checkboxProps,
    _ref$checkboxPosition = _ref.checkboxPosition,
    checkboxPosition = _ref$checkboxPosition === void 0 ? 'left' : _ref$checkboxPosition,
    checked = _ref.checked,
    onChange = _ref.onChange,
    className = _ref.className,
    style = _ref.style;
  // 获取checkbox
  function getCheckboxNode() {
    if (!checkable) return null;
    if (typeof checkbox === 'function') {
      var newCheckBox = checkbox(_objectSpread(_objectSpread({}, itemData || {}), {}, {
        checked: checked,
        checkboxProps: checkboxProps
      }));
      if (newCheckBox !== undefined) return newCheckBox;
    }
    return /*#__PURE__*/React.createElement(Checkbox, _extends({
      checked: checked
    }, checkboxProps));
  }

  // 获取note
  function getNoteNode() {
    var Note = null;
    if (typeof note === 'function') {
      Note = note(_objectSpread(_objectSpread({}, itemData || {}), {}, {
        checked: checked
      }));
    } else if (typeof note === 'string') {
      Note = note;
    } else {
      Note = note;
    }
    return /*#__PURE__*/React.createElement("div", {
      className: "list-item-meta-note"
    }, Note);
  }

  // 渲染图片
  function getImageNode() {
    if (!image) return null;
    if (typeof image === 'function') {
      return image(_objectSpread(_objectSpread({}, itemData || {}), {}, {
        checked: checked
      }));
    }
    if (typeof image === 'string') {
      return /*#__PURE__*/React.createElement("div", {
        className: "list-item-meta-image"
      }, /*#__PURE__*/React.createElement("img", {
        alt: "",
        src: image,
        onError: function onError(e) {
          e.target.parentNode.classList.add('fail');
        },
        onLoad: function onLoad(e) {
          e.target.parentNode.classList.add('success');
        },
        className: "avatar"
      }));
    }
    return image;
  }

  // 渲染头像
  function getAvatarNode() {
    if (!avatar) return null;
    if (typeof avatar === 'function') {
      return avatar(_objectSpread(_objectSpread({}, itemData || {}), {}, {
        checked: checked
      }));
    }
    if (typeof avatar === 'string') {
      return /*#__PURE__*/React.createElement("div", {
        className: "list-item-meta-avatar"
      }, /*#__PURE__*/React.createElement("img", {
        alt: "",
        src: avatar,
        onError: function onError(e) {
          e.target.parentNode.classList.add('fail');
        },
        onLoad: function onLoad(e) {
          e.target.parentNode.classList.add('success');
        },
        className: "avatar"
      }));
    }
    return avatar;
  }

  // 获取action
  function getActionNode() {
    if (typeof action === 'function') {
      return action(_objectSpread(_objectSpread({}, itemData || {}), {}, {
        checked: checked
      }));
    }
    return null;
  }

  // 获取item节点
  function getItemNode() {
    return /*#__PURE__*/React.createElement("div", {
      style: wrapper ? undefined : style,
      className: DOMUtil.classNames('list-item', wrapper ? undefined : className, disabled ? 'disabled' : '', checked ? 'active' : '', layout ? layout : ''),
      onClick: function onClick(e) {
        e.stopPropagation();
        onChange && onChange(!checked);
      }
    }, checkboxPosition !== 'right' && getCheckboxNode(checked), /*#__PURE__*/React.createElement("div", {
      className: "list-item-main"
    }, /*#__PURE__*/React.createElement("div", {
      className: "list-item-meta"
    }, getImageNode(), getAvatarNode(), /*#__PURE__*/React.createElement("div", {
      className: "list-item-meta-content"
    }, /*#__PURE__*/React.createElement("div", {
      className: "list-item-meta-title"
    }, title), description && /*#__PURE__*/React.createElement("div", {
      className: "list-item-meta-description"
    }, description)), getNoteNode()), content && /*#__PURE__*/React.createElement("div", {
      className: "list-item-content"
    }, content), action && /*#__PURE__*/React.createElement("div", {
      className: "list-item-action"
    }, getActionNode())), checkboxPosition === 'right' && getCheckboxNode(checked));
  }

  // Custom Wrapper or Item
  if (wrapper) {
    var WrapperNode = Wrapper;
    if (typeof wrapper === 'function') {
      return wrapper({
        checked: checked,
        onChange: onChange,
        // data
        itemData: itemData,
        // config
        layout: layout,
        checkable: checkable,
        checkbox: checkbox,
        checkboxProps: checkboxProps,
        checkboxPosition: checkboxPosition,
        // Node
        children: getItemNode(),
        // Item style
        style: style,
        className: className
      });
    }
    if ( /*#__PURE__*/React.isValidElement(wrapper)) {
      WrapperNode = wrapper;
    }
    return /*#__PURE__*/React.createElement(WrapperNode, {
      checked: checked,
      checkboxProps: checkboxProps,
      onChange: onChange
      // data
      ,
      itemData: itemData
      // config
      ,
      layout: layout,
      checkbox: checkbox,
      checkboxPosition: checkboxPosition
      // Item style
      ,
      style: style,
      className: className
    }, getItemNode());
  }
  return getItemNode();
};
export default Item;