function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

/**
 * 更改 Table 疏密度 Icon
 */
import { Button, Dropdown, Menu, Balloon } from '@alicloudfe/components';
import TeamixIcon from '@teamix/icon';
import { baseClass, getMessage } from '@teamix/utils';
import React, { useEffect, useState } from 'react';
import './index.scss';
var RadioItem = Menu.RadioItem;
var cls = baseClass('teamix-pro-table-toolbar-icon');

var DensityIcon = function DensityIcon(props) {
  var _actionRef$current3, _actionRef$current3$o;

  var actionRef = props.actionRef;

  var _useState = useState('medium'),
      _useState2 = _slicedToArray(_useState, 2),
      size = _useState2[0],
      setSize = _useState2[1];

  var _useState3 = useState(false),
      _useState4 = _slicedToArray(_useState3, 2),
      fullscreen = _useState4[0],
      setFullscreen = _useState4[1]; // 设置大小


  var radioOnchange = function radioOnchange(mode) {
    var _actionRef$current, _actionRef$current$se;

    setSize(mode);
    (_actionRef$current = actionRef.current) === null || _actionRef$current === void 0 ? void 0 : (_actionRef$current$se = _actionRef$current.setSize) === null || _actionRef$current$se === void 0 ? void 0 : _actionRef$current$se.call(_actionRef$current, mode);
  }; // 销毁监听函数


  useEffect(function () {
    return function () {
      var _actionRef$current2, _actionRef$current2$o;

      (_actionRef$current2 = actionRef.current) === null || _actionRef$current2 === void 0 ? void 0 : (_actionRef$current2$o = _actionRef$current2.off) === null || _actionRef$current2$o === void 0 ? void 0 : _actionRef$current2$o.call(_actionRef$current2, 'densityIcon');
    };
  }, []); // 监听全屏变化

  (_actionRef$current3 = actionRef.current) === null || _actionRef$current3 === void 0 ? void 0 : (_actionRef$current3$o = _actionRef$current3.on) === null || _actionRef$current3$o === void 0 ? void 0 : _actionRef$current3$o.call(_actionRef$current3, function (state) {
    setFullscreen(state);
  }, 'fullScreenState', 'densityIcon');

  var renderDropdown = function renderDropdown() {
    return /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement(Dropdown // safeNode={() => sizeMenuRef.current || document}
    , {
      // safeNode={() => sizeMenuRef.current || document}
      trigger: /*#__PURE__*/React.createElement(Button, {
        iconSize: "small",
        className: cls()
      }, /*#__PURE__*/React.createElement(TeamixIcon, {
        size: "small",
        type: "space-line"
      })),
      triggerType: ['click'],
      // key={index}
      align: "tr br"
    }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Menu, null, /*#__PURE__*/React.createElement(RadioItem, {
      key: "medium",
      checked: size === 'medium',
      onChange: function onChange(checked) {
        return radioOnchange('medium');
      }
    }, getMessage('default')), /*#__PURE__*/React.createElement(RadioItem, {
      key: "small",
      checked: size === 'small',
      onChange: function onChange(checked) {
        return radioOnchange('small');
      }
    }, getMessage('compact'))))));
  };

  return /*#__PURE__*/React.createElement(Balloon.Tooltip, {
    trigger: renderDropdown(),
    align: fullscreen ? 'b' : 't',
    popupProps: {
      offset: fullscreen ? [5, 20] : [5, -18],
      animation: {
        in: 'fadeIn',
        out: 'fadeOut'
      }
    }
  }, getMessage('density'));
};

export default DensityIcon;