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, { useContext, useEffect, useState, useMemo } from "react";
import classNames from "classnames";
import { View } from "@tarojs/components";
import { pxTransform } from "../../utils/taro/px-transform";
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 gutter = useContext(DataContext).gutter;
    var classs = useMemo(function() {
        var prefixCls = 'nut-col';
        return "".concat(prefixCls, " ").concat(prefixCls, "-").concat(span, " ").concat(gutter ? "".concat(prefixCls, "-gutter") : '', " ").concat(prefixCls, "-offset-").concat(offset);
    }, [
        offset,
        span,
        gutter
    ]);
    var getStyle = useMemo(function() {
        var style = {};
        if (!isFirst) {
            style.paddingLeft = pxTransform(gutter / 2);
        }
        if (!isLast) {
            style.paddingRight = pxTransform(gutter / 2);
        }
        return style;
    }, [
        isFirst,
        isLast,
        gutter
    ]);
    var _useState = _sliced_to_array(useState(classs), 2), colName = _useState[0], setColName = _useState[1];
    var _useState1 = _sliced_to_array(useState(getStyle), 2), colStyle = _useState1[0], setColStyle = _useState1[1];
    useEffect(function() {
        setColName(classs);
        setColStyle(getStyle);
    }, [
        classs,
        getStyle
    ]);
    return /*#__PURE__*/ React.createElement(View, {
        className: classNames(colName, className),
        style: _object_spread({}, style, colStyle),
        key: classNames(colName, className),
        onClick: function(e) {
            onClick && onClick(e, 'col');
        }
    }, children);
};
Col.displayName = 'NutCol';
