"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.UIToolbar = void 0;
const React = __importStar(require("react"));
const react_1 = require("@fluentui/react");
require("./UIToolbar.scss");
/**
 * UIToolbar component.
 *
 * @exports
 * @class {UIToolbar}
 * @extends {React.Component<UIToolbarProps, UIToolbarState>}
 */
class UIToolbar extends React.Component {
    /**
     * Initializes component properties.
     *
     * @param props
     */
    constructor(props) {
        super(props);
        this.onResize = () => {
            const toolbarWidth = this.toolbarRef.current?.clientWidth;
            const breakPointLarge = this.props.breakPointLarge ?? 800;
            const breakPointMedium = this.props.breakPointMedium ?? 660;
            const breakPointSmall = this.props.breakPointSmall ?? 420;
            if (!toolbarWidth) {
                return;
            }
            const breakpoints = [
                { min: breakPointLarge + 1, max: Infinity, className: 'column-wide', name: 'wide' },
                { min: breakPointMedium + 1, max: breakPointLarge, className: 'column-large', name: 'large' },
                { min: breakPointSmall, max: breakPointMedium, className: 'column-medium', name: 'medium' },
                { min: 0, max: breakPointSmall - 1, className: 'column-small', name: 'small' }
            ];
            const match = breakpoints.find((bp) => toolbarWidth >= bp.min && toolbarWidth <= bp.max);
            if (match) {
                this.setState({ toolbarWidthClassName: match.className });
                this.props.onResize?.(toolbarWidth, match.name);
            }
        };
        this.state = {
            toolbarWidthClassName: 'column-large'
        };
        this.toolbarRef = React.createRef();
        this.resizeObserver = new ResizeObserver(this.onResize);
    }
    componentDidMount() {
        this.resizeObserver.observe(this.toolbarRef.current);
        this.onResize();
    }
    /**
     * @returns {React.ReactNode}
     */
    render() {
        const divProps = (0, react_1.getNativeProps)(this.props, react_1.divProperties, [
            'className',
            'children'
        ]);
        return (React.createElement("div", { ...divProps, tabIndex: -1, ref: this.toolbarRef, className: `ui-toolbar ${this.state.toolbarWidthClassName} ${this.props.className ? this.props.className : ''}`, role: "toolbar" },
            React.createElement("div", { className: "ui-toolbar__container" },
                React.createElement("div", { className: "ui-toolbar__content" }, this.props.children))));
    }
}
exports.UIToolbar = UIToolbar;
//# sourceMappingURL=UIToolbar.js.map