function _extends() { _extends = Object.assign || 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); }

import React, { useContext, useMemo } from 'react';
import cls from 'clsx';
import ConfigProviderContext from '../../config-provider/ConfigProviderContext';

var SkuRowPropItem = function SkuRowPropItem(props) {
  var _props$skuValue;

  var _useContext = useContext(ConfigProviderContext),
      prefixCls = _useContext.prefixCls,
      createNamespace = _useContext.createNamespace;

  var _createNamespace = createNamespace('sku-row', prefixCls),
      bem = _createNamespace[0];

  var choosed = useMemo(function () {
    var selectedProp = props.selectedProp,
        skuKeyStr = props.skuKeyStr,
        skuValue = props.skuValue;

    if (selectedProp && selectedProp[skuKeyStr]) {
      return selectedProp[skuKeyStr].indexOf(skuValue.id) > -1;
    }

    return false;
  }, [JSON.stringify(props.selectedProp), JSON.stringify(props.skuValue), props.skuKeyStr]);

  var onSelect = function onSelect() {
    props.onSkuPropSelected(_extends({}, props.skuValue, {
      skuKeyStr: props.skuKeyStr,
      multiple: props.multiple
    }));
  };

  return /*#__PURE__*/React.createElement("span", {
    className: cls(bem('item', {
      active: choosed
    })),
    onClick: onSelect
  }, /*#__PURE__*/React.createElement("span", {
    className: cls(bem('item-name'))
  }, (_props$skuValue = props.skuValue) == null ? void 0 : _props$skuValue.name));
};

export default SkuRowPropItem;