import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
var _excluded = ["dataSource", "marginLeft", "style", "slectstyles", "slectstylesbgc"];
import * as React from 'react';
import { useState, useEffect } from 'react';
import "./index.less";
var myTagChange = function myTagChange(_ref) {
  var dataSource = _ref.dataSource,
    marginLeft = _ref.marginLeft,
    style = _ref.style,
    slectstyles = _ref.slectstyles,
    slectstylesbgc = _ref.slectstylesbgc,
    otherProps = _objectWithoutPropertiesLoose(_ref, _excluded);
  var _style = style || {};
  var _otherProps = otherProps || {};
  _otherProps.style = _style;
  var _useState = useState(0),
    currentIndex = _useState[0],
    setCurrentIndex = _useState[1];
  var _useState2 = useState(''),
    ID = _useState2[0],
    setID = _useState2[1];
  useEffect(function () {
    setID("myTeg_" + uuid());
  }, []);
  var changeTag = function changeTag(index) {
    setCurrentIndex(index);
  };
  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]);
  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", _extends({
      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';
export default myTagChange;
export function uuid() {
  return (Math.random() * 1e6 >> 0).toString(36);
}