"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "Col", {
    enumerable: true,
    get: function() {
        return Col;
    }
});
var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
var _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
var _object_spread = require("@swc/helpers/_/_object_spread");
var _object_spread_props = require("@swc/helpers/_/_object_spread_props");
var _sliced_to_array = require("@swc/helpers/_/_sliced_to_array");
var _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
var _classnames = /*#__PURE__*/ _interop_require_default._(require("classnames"));
var _components = require("@tarojs/components");
var _pxtransform = require("../../utils/taro/px-transform");
var _context = require("../row/context");
var _typings = require("../../utils/typings");
var defaultProps = (0, _object_spread_props._)((0, _object_spread._)({}, _typings.ComponentDefaults), {
    span: '24',
    offset: '0',
    gutter: '0',
    isFirst: false,
    isLast: false
});
var Col = function Col(props) {
    var _$_object_spread = (0, _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 = (0, _react.useContext)(_context.DataContext).gutter;
    var classs = (0, _react.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 = (0, _react.useMemo)(function() {
        var style = {};
        if (!isFirst) {
            style.paddingLeft = (0, _pxtransform.pxTransform)(gutter / 2);
        }
        if (!isLast) {
            style.paddingRight = (0, _pxtransform.pxTransform)(gutter / 2);
        }
        return style;
    }, [
        isFirst,
        isLast,
        gutter
    ]);
    var _useState = (0, _sliced_to_array._)((0, _react.useState)(classs), 2), colName = _useState[0], setColName = _useState[1];
    var _useState1 = (0, _sliced_to_array._)((0, _react.useState)(getStyle), 2), colStyle = _useState1[0], setColStyle = _useState1[1];
    (0, _react.useEffect)(function() {
        setColName(classs);
        setColStyle(getStyle);
    }, [
        classs,
        getStyle
    ]);
    return /*#__PURE__*/ _react.default.createElement(_components.View, {
        className: (0, _classnames.default)(colName, className),
        style: (0, _object_spread._)({}, style, colStyle),
        key: (0, _classnames.default)(colName, className),
        onClick: function onClick1(e) {
            onClick && onClick(e, 'col');
        }
    }, children);
};
Col.displayName = 'NutCol';
