import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
import React, { useEffect, useState, useContext } from "react";
import classNames from "classnames";
import { DataContext } from "../row/context";
import { ComponentDefaults } from "../../utils/typings";
var defaultProps = _object_spread_props(_object_spread({}, ComponentDefaults), {
    span: '24',
    offset: '0',
    gutter: '0',
    isFirst: false,
    isLast: false
});
export var Col = function(props) {
    var _$_object_spread = _object_spread({}, defaultProps, props), className = _$_object_spread.className, style = _$_object_spread.style, span = _$_object_spread.span, offset = _$_object_spread.offset, children = _$_object_spread.children, isFirst = _$_object_spread.isFirst, isLast = _$_object_spread.isLast, onClick = _$_object_spread.onClick;
    var _useState = _sliced_to_array(useState(''), 2), colName = _useState[0], setColName = _useState[1];
    var _useState1 = _sliced_to_array(useState({}), 2), colStyle = _useState1[0], setColStyle = _useState1[1];
    var gutter = useContext(DataContext).gutter;
    var classs = function() {
        // 定义col的class类
        var prefixCls = 'nut-col';
        return "".concat(prefixCls, " ").concat(prefixCls, "-").concat(span, " ").concat(gutter ? "".concat(prefixCls, "-gutter") : '', " ").concat(prefixCls, "-offset-").concat(offset);
    };
    var getStyle = function() {
        // 定义col的style类
        var style = {};
        if (!isFirst) {
            style.paddingLeft = "".concat(gutter / 2, "px");
        }
        if (!isLast) {
            style.paddingRight = "".concat(gutter / 2, "px");
        }
        return style;
    };
    useEffect(function() {
        setColName(classs);
        setColStyle(getStyle);
    }, [
        span,
        offset,
        gutter
    ]);
    return /*#__PURE__*/ React.createElement("div", {
        className: classNames(colName, className),
        style: _object_spread({}, style, colStyle),
        onClick: function(e) {
            onClick && onClick(e, 'col');
        }
    }, children);
};
Col.displayName = 'NutCol';
