import { _ as _define_property } from "@swc/helpers/_/_define_property";
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
import React from "react";
import classNames from "classnames";
import { View } from "@tarojs/components";
import { useRtl } from "../configprovider/index";
import { ComponentDefaults } from "../../utils/typings";
import SafeArea from "../safearea/index";
var defaultProps = _object_spread_props(_object_spread({}, ComponentDefaults), {
    left: '',
    right: '',
    back: '',
    fixed: false,
    safeAreaInsetTop: false,
    placeholder: false,
    zIndex: 10
});
export var NavBar = function(props) {
    var _$_object_spread = _object_spread({}, defaultProps, props), right = _$_object_spread.right, left = _$_object_spread.left, title = _$_object_spread.title, className = _$_object_spread.className, style = _$_object_spread.style, back = _$_object_spread.back, fixed = _$_object_spread.fixed, safeAreaInsetTop = _$_object_spread.safeAreaInsetTop, placeholder = _$_object_spread.placeholder, zIndex = _$_object_spread.zIndex, onBackClick = _$_object_spread.onBackClick;
    var classPrefix = 'nut-navbar';
    var rtl = useRtl();
    var children = Array.isArray(props.children) ? props.children : [
        props.children
    ];
    var styles = function() {
        return _object_spread_props(_object_spread({}, style), {
            zIndex: zIndex
        });
    };
    var renderLeft = function() {
        var _obj, _obj1;
        return /*#__PURE__*/ React.createElement(View, {
            className: classNames((_obj = {}, _define_property(_obj, "".concat(classPrefix, "-left"), true), _define_property(_obj, "".concat(classPrefix, "-left-maxwidth"), title), _define_property(_obj, "".concat(classPrefix, "-left-hidden"), !left && !back), _define_property(_obj, "".concat(classPrefix, "-left-rtl"), rtl), _obj))
        }, back ? /*#__PURE__*/ React.createElement(View, {
            className: classNames((_obj1 = {}, _define_property(_obj1, "".concat(classPrefix, "-left-back"), true), _define_property(_obj1, "".concat(classPrefix, "-left-back-children"), left), _define_property(_obj1, "".concat(classPrefix, "-left-back-children-rtl"), left && rtl), _obj1)),
            onClick: function(e) {
                return onBackClick(e);
            }
        }, back) : null, left);
    };
    var renderContent = function() {
        var _obj;
        return /*#__PURE__*/ React.createElement(View, {
            className: classNames((_obj = {}, _define_property(_obj, "".concat(classPrefix, "-title"), true), _define_property(_obj, "".concat(classPrefix, "-title-center"), title), _obj))
        }, title || children);
    };
    var renderRight = function() {
        var _obj;
        return /*#__PURE__*/ React.createElement(View, {
            className: classNames((_obj = {}, _define_property(_obj, "".concat(classPrefix, "-right"), true), _define_property(_obj, "".concat(classPrefix, "-right-maxwidth"), title), _define_property(_obj, "".concat(classPrefix, "-right-rtl"), rtl), _obj))
        }, right);
    };
    var renderWrapper = function() {
        return /*#__PURE__*/ React.createElement(View, {
            className: cls,
            style: styles()
        }, renderLeft(), renderContent(), renderRight());
    };
    var _obj;
    var classes = classNames((_obj = {}, _define_property(_obj, "".concat(classPrefix, "-fixed"), fixed), _define_property(_obj, "".concat(classPrefix, "-safe-area-inset-top"), safeAreaInsetTop), _define_property(_obj, "".concat(classPrefix, "-rtl"), rtl), _obj));
    var cls = classNames(classPrefix, classes, className, _define_property({}, "".concat(classPrefix, "-title-wrapper"), title));
    return /*#__PURE__*/ React.createElement(React.Fragment, null, safeAreaInsetTop && /*#__PURE__*/ React.createElement(SafeArea, {
        position: "top"
    }), fixed && placeholder ? /*#__PURE__*/ React.createElement(View, {
        className: "".concat(classPrefix, "-placeholder")
    }, renderWrapper()) : renderWrapper());
};
NavBar.displayName = 'NutNavBar';
