"use strict";
/*---------------------------------------------------------------------------------------------
 * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
 * See LICENSE.md in the project root for license terms and full copyright notice.
 *--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module StatusBar
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.ViewAttributesStatusField = void 0;
require("./ViewAttributes.scss");
const React = require("react");
const core_common_1 = require("@itwin/core-common");
const core_frontend_1 = require("@itwin/core-frontend");
const itwinui_react_1 = require("@itwin/itwinui-react");
const UiFramework_1 = require("../UiFramework");
const LabelIndicator_1 = require("../statusbar/LabelIndicator");
const Dialog_1 = require("../statusbar/dialog/Dialog");
const itwinui_icons_react_1 = require("@itwin/itwinui-icons-react");
/** Widget for showing Checkboxes for View Attributes
 * @beta
 */
class ViewAttributesStatusField extends React.Component {
    constructor(props) {
        super(props);
        this._title = UiFramework_1.UiFramework.translate("listTools.viewAttributes");
        // istanbul ignore next
        this._handleViewFlagClick = (flagName) => {
            if (core_frontend_1.IModelApp.viewManager.selectedView) {
                const props = core_frontend_1.IModelApp.viewManager.selectedView.viewFlags.toJSON();
                props[flagName] =
                    props[flagName] === undefined
                        ? true
                        : !props[flagName];
                const viewFlags = core_common_1.ViewFlags.fromJSON(props);
                core_frontend_1.IModelApp.viewManager.selectedView.viewFlags = viewFlags;
                this.updateState();
            }
        };
        this._handleToggleCamera = async () => {
            await core_frontend_1.IModelApp.tools.run("View.ToggleCamera", core_frontend_1.IModelApp.viewManager.selectedView);
            this.updateState();
        };
        this.state = {
            cameraOn: false,
            viewFlags: {},
            target: null,
        };
    }
    componentDidMount() {
        this.updateState();
    }
    // istanbul ignore next
    updateState() {
        if (core_frontend_1.IModelApp.viewManager.selectedView) {
            const viewFlags = {
                ...core_frontend_1.IModelApp.viewManager.selectedView.view.viewFlags.toJSON(),
            };
            const cameraOn = core_frontend_1.IModelApp.viewManager.selectedView.isCameraOn;
            this.setState({
                viewFlags,
                cameraOn,
            });
        }
    }
    // istanbul ignore next
    stylizeName(name) {
        name = name.charAt(0).toUpperCase() + name.slice(1);
        name = name.replace(/([A-Z])/g, " $1").trim();
        return name;
    }
    getViewFlagItem(flagName, value, labelKey) {
        return (React.createElement(itwinui_react_1.Checkbox, { key: flagName, label: labelKey
                ? core_frontend_1.IModelApp.localization.getLocalizedString(labelKey)
                : /* istanbul ignore next */ this.stylizeName(flagName), onClick: () => this._handleViewFlagClick(flagName), defaultChecked: value }));
    }
    getFlagState(flagName) {
        return this.state.viewFlags.hasOwnProperty(flagName)
            ? /* istanbul ignore next */ this.state.viewFlags[flagName]
            : false;
    }
    getToggleCameraItem() {
        return (React.createElement(itwinui_react_1.Checkbox, { key: "toggleCamera", label: core_frontend_1.IModelApp.localization.getLocalizedString("UiFramework:listTools.camera"), onClick: this._handleToggleCamera, defaultChecked: this.state.cameraOn }));
    }
    getViewFlags() {
        const items = [];
        items.push(this.getViewFlagItem("acs", this.getFlagState("acs"), "UiFramework:listTools.acs"));
        items.push(this.getToggleCameraItem());
        items.push(this.getViewFlagItem("noConstruct", !this.getFlagState("noConstruct"), "UiFramework:listTools.constructions"));
        items.push(this.getViewFlagItem("hidEdges", this.getFlagState("hidEdges"), "UiFramework:listTools.hidEdges"));
        items.push(this.getViewFlagItem("monochrome", this.getFlagState("monochrome"), "UiFramework:listTools.monochrome"));
        items.push(this.getViewFlagItem("visEdges", this.getFlagState("visEdges"), "UiFramework:listTools.visEdges"));
        items.push(this.getViewFlagItem("ambientOcclusion", this.getFlagState("ambientOcclusion"), "UiFramework:listTools.ambientOcclusion"));
        items.push(this.getViewFlagItem("shadows", this.getFlagState("shadows"), "UiFramework:listTools.shadows"));
        items.push(this.getViewFlagItem("backgroundMap", this.getFlagState("backgroundMap"), "UiFramework:listTools.backgroundMap"));
        return React.createElement("div", { className: "uifw-view-attributes-contents" }, items);
    }
    render() {
        return (React.createElement(LabelIndicator_1.StatusBarLabelIndicator, { iconSpec: React.createElement(itwinui_icons_react_1.SvgWindowSettings, null), title: this._title, popup: React.createElement(Dialog_1.StatusBarDialog, { titleBar: React.createElement(Dialog_1.StatusBarDialog.TitleBar, { title: this._title }) }, this.getViewFlags()) }));
    }
}
exports.ViewAttributesStatusField = ViewAttributesStatusField;
//# sourceMappingURL=ViewAttributes.js.map