/**
 * RecordBoard 列显示隐藏设置（仅控制表格列展示，不控制 filter/sort）。
 * 参考 table Actions ColumnsSetting，仅保留显隐切换，无拖拽排序。
 */

import React, { useMemo } from 'react';
import { Popover } from 'antd';
import { EyeOutlined } from '@ant-design/icons';
import { useRecordBoardContext } from "../../hooks/useRecordBoardContext";
import { getRecordBoardColumnKey } from "../../utils/recordBoardColumns";
import ColumnSettingPopover from "./ColumnSettingPopover";
import "./index.less";
var RecordBoardColumnSetting = function RecordBoardColumnSetting() {
  var _ctx$childComponentPr, _ctx$childComponentPr2, _ctx$columnVisibility, _ctx$columnOrder;
  var ctx = useRecordBoardContext();
  var compactToolbar = ((_ctx$childComponentPr = ctx.childComponentProps) === null || _ctx$childComponentPr === void 0 || (_ctx$childComponentPr = _ctx$childComponentPr.toolBar) === null || _ctx$childComponentPr === void 0 ? void 0 : _ctx$childComponentPr.toolbarDensity) === 'compact';
  var gridColumns = (_ctx$childComponentPr2 = ctx.childComponentProps) === null || _ctx$childComponentPr2 === void 0 || (_ctx$childComponentPr2 = _ctx$childComponentPr2.grid) === null || _ctx$childComponentPr2 === void 0 ? void 0 : _ctx$childComponentPr2.columns;
  var columnVisibility = (_ctx$columnVisibility = ctx.columnVisibility) !== null && _ctx$columnVisibility !== void 0 ? _ctx$columnVisibility : {};
  var onColumnVisibilityChange = ctx.onColumnVisibilityChange;
  var columnOrder = (_ctx$columnOrder = ctx.columnOrder) !== null && _ctx$columnOrder !== void 0 ? _ctx$columnOrder : null;
  var onColumnOrderChange = ctx.onColumnOrderChange;
  var content = useMemo(function () {
    if (!Array.isArray(gridColumns) || gridColumns.length === 0 || typeof onColumnVisibilityChange !== 'function') {
      return null;
    }
    return /*#__PURE__*/React.createElement(ColumnSettingPopover, {
      columns: gridColumns,
      columnVisibility: columnVisibility,
      onColumnVisibilityChange: onColumnVisibilityChange,
      columnOrder: columnOrder,
      onColumnOrderChange: onColumnOrderChange
    });
  }, [gridColumns, columnVisibility, onColumnVisibilityChange, columnOrder, onColumnOrderChange]);
  var hasHiddenColumns = useMemo(function () {
    if (!Array.isArray(gridColumns)) return false;
    return gridColumns.some(function (col) {
      return columnVisibility[getRecordBoardColumnKey(col)] === false;
    });
  }, [gridColumns, columnVisibility]);
  if (!content) return null;
  return /*#__PURE__*/React.createElement(Popover, {
    content: content,
    arrow: false,
    placement: "bottomRight",
    trigger: "click"
  }, /*#__PURE__*/React.createElement("span", {
    className: "record-board-toolbar-column-setting-btn",
    style: {
      display: 'inline-flex',
      alignItems: 'center',
      justifyContent: 'center',
      width: compactToolbar ? 28 : 32,
      height: compactToolbar ? 28 : 32,
      cursor: 'pointer',
      borderRadius: 6,
      color: hasHiddenColumns ? 'var(--color-primary, #1890ff)' : undefined
    }
  }, /*#__PURE__*/React.createElement(EyeOutlined, {
    style: {
      fontSize: compactToolbar ? 15 : 18
    }
  })));
};
RecordBoardColumnSetting.displayName = 'RecordBoard.ColumnSetting';
export default RecordBoardColumnSetting;