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 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, { useMemo } from 'react';
import { Icon } from '@pisell/materials';
import "./index.less";
import { PREFIX, productCardDefault } from "../../status";
var Action = function Action(_ref) {
  var props = _ref.props,
    className = _ref.className;
  var skuActionConfig = props.skuActionConfig,
    dataSource = props.dataSource,
    onAction = props.onAction;
  var _ref2 = skuActionConfig || (productCardDefault === null || productCardDefault === void 0 ? void 0 : productCardDefault.skuActionDefault) || {},
    isOpen = _ref2.isOpen,
    method = _ref2.method,
    slot = _ref2.slot,
    iconMethod = _ref2.iconMethod,
    radioMethod = _ref2.radioMethod,
    checkboxMethod = _ref2.checkboxMethod,
    buttonMethod = _ref2.buttonMethod;

  // 不开启
  if (!isOpen) return null;

  // 开启插槽
  if (slot) {
    return /*#__PURE__*/React.createElement("div", {
      className: "".concat(PREFIX, "__card-action ").concat(className)
    }, slot);
  }
  var Com = useMemo(function () {
    if (!method) return null;
    var key = {
      icon: iconMethod,
      radio: radioMethod,
      checkbox: checkboxMethod,
      button: buttonMethod
    };
    var _key$method = key[method],
      background = _key$method.background,
      paddingY = _key$method.paddingY,
      paddingX = _key$method.paddingX,
      isBorder = _key$method.isBorder,
      borderWidth = _key$method.borderWidth,
      borderColor = _key$method.borderColor,
      radius = _key$method.radius;
    var baseStyle = {
      background: background,
      padding: "".concat(paddingY, "px ").concat(paddingX, "px"),
      border: isBorder ? "".concat(borderWidth, "px solid ").concat(borderColor) : 'none',
      borderRadius: "".concat(radius, "px")
    };

    // icon类型
    if (method === 'icon' || method === 'radio') {
      var _key$method2;
      return /*#__PURE__*/React.createElement("div", {
        style: _objectSpread({}, baseStyle)
      }, ((_key$method2 = key[method]) === null || _key$method2 === void 0 ? void 0 : _key$method2.icon) || /*#__PURE__*/React.createElement(Icon, {
        type: method === 'icon' ? 'pisell2-arrow-right' : 'pisell2-plus',
        size: 24,
        rotate: 0,
        spin: false,
        color: "#ffffff"
      }));
    }

    // 按钮类型
    if (method === 'checkbox' || method === 'button') {
      var _key$method3 = key[method],
        text = _key$method3.text,
        fontSize = _key$method3.fontSize,
        fontWeight = _key$method3.fontWeight,
        color = _key$method3.color;
      return /*#__PURE__*/React.createElement("div", {
        style: _objectSpread(_objectSpread({}, baseStyle), {}, {
          color: color,
          fontSize: fontSize,
          fontWeight: fontWeight,
          width: method === 'button' ? '100%' : 'auto',
          textAlign: 'center'
        })
      }, text);
    }
    return null;
  }, [method, radioMethod, checkboxMethod, buttonMethod, iconMethod]);
  return /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__card-action ").concat(PREFIX, "__card-action-").concat(method, " ").concat(className)
  }, /*#__PURE__*/React.createElement("div", {
    onClick: function onClick(e) {
      e.stopPropagation();
      onAction === null || onAction === void 0 || onAction(dataSource);
    }
  }, Com));
};
export default Action;