import { jsx } from 'react/jsx-runtime';
import classNames from '../../../../_virtual/index.js';
import useSelector from './use-selector.js';
import { getCellDimensions } from './util.js';

const FloatingRect = ({ dimensions, dragging, hidden, variant, }) => {
    const active = useSelector((state) => state.active);
    const autoFill = useSelector((state) => state.autoFill);
    const FixedVal = useSelector((state) => active
        ? getCellDimensions(active, state.rowDimensions, state.columnDimensions)
        : undefined);
    const { width, height, top, left } = dimensions || {};
    let sampleHeight = FixedVal?.height ?? 0;
    let sampleWidth = FixedVal?.width ?? 0;
    let adjustedWidth = width;
    let adjustedHeight = height;
    if (autoFill.open && width && height && FixedVal) {
        if (width - sampleWidth > height - sampleHeight) {
            adjustedWidth = width;
            adjustedHeight = FixedVal.height;
        }
        else {
            adjustedHeight = height;
            adjustedWidth = FixedVal.width;
        }
    }
    return (jsx("div", { className: classNames('ff-spreadsheet-floating-rect', {
            [`ff-spreadsheet-floating-rect--${variant}`]: variant,
            'ff-spreadsheet-floating-rect--dragging': dragging,
            'ff-spreadsheet-floating-rect--hidden': hidden,
        }), style: {
            width: (adjustedWidth ?? 0) + 1,
            height: (adjustedHeight ?? 0) + 1,
            top,
            left,
        } }));
};

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