"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
exports.uuid = uuid;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var React = _interopRequireWildcard(require("react"));
require("./index.less");
var _excluded = ["dataSource", "marginLeft", "style", "slectstyles", "slectstylesbgc"];
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var myTagChange = function myTagChange(_ref) {
  var dataSource = _ref.dataSource,
    marginLeft = _ref.marginLeft,
    style = _ref.style,
    slectstyles = _ref.slectstyles,
    slectstylesbgc = _ref.slectstylesbgc,
    otherProps = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded);
  var _style = style || {};
  var _otherProps = otherProps || {};
  _otherProps.style = _style;
  var _useState = (0, React.useState)(0),
    currentIndex = _useState[0],
    setCurrentIndex = _useState[1];
  var _useState2 = (0, React.useState)(''),
    ID = _useState2[0],
    setID = _useState2[1];
  (0, React.useEffect)(function () {
    setID("myTeg_" + uuid());
  }, []);
  var changeTag = function changeTag(index) {
    setCurrentIndex(index);
  };
  (0, React.useEffect)(function () {

    // let aa = JSON.parse(JSON.stringify(_otherProps.style))
    // aa.backgroundColor = slectstylesbgc
    // _otherProps.style = aa
    // console.log({..._otherProps});
    // document.querySelector('.isActive').style.backgroundColor = slectstylesbgc
    // document.querySelector('.defult').parentNode.childNodes.forEach(item=>{
    //   if(item.classList.contains('defult')){
    //     item.style.backgroundColor = _otherProps.style.backgroundColor
    //   }
    // })
  }, [currentIndex]);
  (0, React.useEffect)(function () {
    if (ID) {
      document.getElementById(ID).style.setProperty('--yxtag', slectstylesbgc ? slectstylesbgc : '#10b3b3');
    }
  });
  return /*#__PURE__*/React.createElement("ul", {
    className: "my-tag-change",
    id: ID
  }, dataSource.map(function (item, index) {
    return /*#__PURE__*/React.createElement("li", (0, _extends2["default"])({
      className: currentIndex == index ? 'isActive' : 'defult',
      onClick: function onClick() {
        changeTag(index);
      }
    }, _otherProps), /*#__PURE__*/React.createElement("span", {
      style: {
        "color": currentIndex == index ? slectstyles : _otherProps.style.color
      }
    }, item.name));
  }));
};
myTagChange.displayName = 'myTagChange';
var _default = myTagChange;
exports["default"] = _default;
function uuid() {
  return (Math.random() * 1e6 >> 0).toString(36);
}