import React__default, { useCallback } from 'react';
import { Checkbox, Row, Col, Tooltip } from 'antd';
import FormCollapsedLayout from '../FormCollapsedLayout/index.js';
import '../Title/index.js';
import '../IconFont/index.js';
import '../_rollupPluginBabelHelpers-736b301a.js';
import '@zenview/micro-utils';
import '../BetweenBox/index.js';

const CheckGroup = Checkbox.Group;

// showMore 显示更多 收起时只展示3行
const CheckboxGroup = ({
  className = '',
  icon,
  maxLength = 9,
  title,
  sourceData = [],
  onCheckAllCb,
  renderExtraTip,
  showCheckAll = false,
  titleExt,
  value,
  onChange
}) => {
  const checkAllChange = useCallback(e => {
    const checkAll = sourceData.map(v => v.value);
    const checkValue = e.target.checked ? checkAll : [];
    onChange && onChange(checkValue);
    onCheckAllCb && onCheckAllCb(checkValue);
  }, [onChange, onCheckAllCb, sourceData]);
  return /*#__PURE__*/React__default.createElement(FormCollapsedLayout, {
    className: `lm-filter-checkbox-group-wrapper ${className}`,
    visibleCollapsed: sourceData.length > maxLength,
    title: title,
    icon: icon,
    titleExt: showCheckAll ? /*#__PURE__*/React__default.createElement(Checkbox, {
      indeterminate: value && value.length && value.length < sourceData.length,
      checked: value && value.length && value.length === sourceData.length,
      onChange: checkAllChange
    }, "\u5168\u9009") : titleExt
  }, /*#__PURE__*/React__default.createElement(FromCheckboxGroup, {
    renderExtraTip: renderExtraTip,
    value: value,
    onChange: onChange,
    sourceData: sourceData,
    maxLength: maxLength
  }));
};
function FromCheckboxGroup({
  renderExtraTip,
  value,
  onChange,
  isCollapsed,
  sourceData,
  maxLength
}) {
  return /*#__PURE__*/React__default.createElement(CheckGroup, {
    value: value,
    onChange: onChange
  }, /*#__PURE__*/React__default.createElement(Row, {
    gutter: 8,
    className: "checkbox-row"
  }, sourceData.map((v, i) => {
    return /*#__PURE__*/React__default.createElement(Col, {
      key: v.value,
      style: i > maxLength - 1 && isCollapsed ? {
        display: 'none'
      } : {}
    }, /*#__PURE__*/React__default.createElement(Tooltip, {
      title: v.label
    }, /*#__PURE__*/React__default.createElement(Checkbox, {
      value: v.value,
      disabled: !!v.disabled
    }, renderExtraTip && renderExtraTip(v), /*#__PURE__*/React__default.createElement("span", null, v.label))));
  })));
}

export { CheckboxGroup as default };
//# sourceMappingURL=index.js.map
