/*---------------------------------------------------------------------------------------------
* 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
 */
import "./ViewAttributes.scss";
import * as React from "react";
import { ViewFlags } from "@itwin/core-common";
import { IModelApp } from "@itwin/core-frontend";
import { Checkbox } from "@itwin/itwinui-react";
import { UiFramework } from "../UiFramework";
import { Indicator } from "./Indicator";
import { StatusBarDialog } from "../statusbar/dialog/Dialog";
/** Widget for showing Checkboxes for View Attributes
 * @beta
 */
export class ViewAttributesStatusField extends React.Component {
    constructor(props) {
        super(props);
        this._title = UiFramework.translate("listTools.viewAttributes");
        // istanbul ignore next
        this._handleViewFlagClick = (flagName) => {
            if (IModelApp.viewManager.selectedView) {
                const props = IModelApp.viewManager.selectedView.viewFlags.toJSON();
                props[flagName] = props[flagName] === undefined ? true : !props[flagName];
                const viewFlags = ViewFlags.fromJSON(props);
                IModelApp.viewManager.selectedView.viewFlags = viewFlags;
                this.updateState();
            }
        };
        this._handleToggleCamera = async () => {
            await IModelApp.tools.run("View.ToggleCamera", IModelApp.viewManager.selectedView);
            this.updateState();
        };
        this.state = {
            cameraOn: false,
            viewFlags: {},
            target: null,
        };
        this._className = this.constructor.name;
    }
    componentDidMount() {
        this.updateState();
    }
    // istanbul ignore next
    updateState() {
        if (IModelApp.viewManager.selectedView) {
            const viewFlags = { ...IModelApp.viewManager.selectedView.view.viewFlags.toJSON() };
            const cameraOn = 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(Checkbox, { key: flagName, label: labelKey ? 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(Checkbox, { key: "toggleCamera", label: 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() {
        var _a;
        // eslint-disable-next-line deprecation/deprecation
        const isOpen = this.props.openWidget === this._className;
        return (React.createElement(React.Fragment, null,
            React.createElement(Indicator // eslint-disable-line deprecation/deprecation
            , { iconName: "icon-window-settings", opened: isOpen, toolTip: this._title, dialog: React.createElement(StatusBarDialog, { titleBar: React.createElement(StatusBarDialog.TitleBar, { title: this._title }) }, this.getViewFlags()), 
                // eslint-disable-next-line deprecation/deprecation
                isInFooterMode: (_a = this.props.isInFooterMode) !== null && _a !== void 0 ? _a : true })));
    }
}
//# sourceMappingURL=ViewAttributes.js.map