/*---------------------------------------------------------------------------------------------
 * 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, IconButton } from "@itwin/itwinui-react";
import { UiFramework } from "../UiFramework";
import { StatusBarDialog } from "../statusbar/dialog/Dialog";
import { SvgWindowSettings } from "@itwin/itwinui-icons-react";
import { StatusBarPopover } from "../statusbar/popup/StatusBarPopover";
/** Widget for showing Checkboxes for View Attributes
 * @beta
 */
export class ViewAttributesStatusField extends React.Component {
    // eslint-disable-next-line deprecation/deprecation
    constructor(props) {
        super(props);
        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,
        };
    }
    componentDidMount() {
        this.updateState();
    }
    updateState() {
        if (IModelApp.viewManager.selectedView) {
            const viewFlags = {
                ...IModelApp.viewManager.selectedView.view.viewFlags.toJSON(),
            };
            const cameraOn = IModelApp.viewManager.selectedView.isCameraOn;
            this.setState({
                viewFlags,
                cameraOn,
            });
        }
    }
    getViewFlagItem(flagName, value, labelKey) {
        return (React.createElement(Checkbox, { key: flagName, label: UiFramework.translate(labelKey), onClick: () => this._handleViewFlagClick(flagName), defaultChecked: value }));
    }
    getFlagState(flagName) {
        return this.state.viewFlags.hasOwnProperty(flagName)
            ? this.state.viewFlags[flagName]
            : false;
    }
    getToggleCameraItem() {
        return (React.createElement(Checkbox, { key: "toggleCamera", label: UiFramework.translate("listTools.camera"), onClick: this._handleToggleCamera, defaultChecked: this.state.cameraOn }));
    }
    getViewFlags() {
        const items = [];
        items.push(this.getViewFlagItem("acs", this.getFlagState("acs"), "listTools.acs"));
        items.push(this.getToggleCameraItem());
        items.push(this.getViewFlagItem("noConstruct", !this.getFlagState("noConstruct"), "listTools.constructions"));
        items.push(this.getViewFlagItem("hidEdges", this.getFlagState("hidEdges"), "listTools.hidEdges"));
        items.push(this.getViewFlagItem("monochrome", this.getFlagState("monochrome"), "listTools.monochrome"));
        items.push(this.getViewFlagItem("visEdges", this.getFlagState("visEdges"), "listTools.visEdges"));
        items.push(this.getViewFlagItem("ambientOcclusion", this.getFlagState("ambientOcclusion"), "listTools.ambientOcclusion"));
        items.push(this.getViewFlagItem("shadows", this.getFlagState("shadows"), "listTools.shadows"));
        items.push(this.getViewFlagItem("backgroundMap", this.getFlagState("backgroundMap"), "listTools.backgroundMap"));
        return React.createElement("div", { className: "uifw-view-attributes-contents" }, items);
    }
    render() {
        const title = UiFramework.translate("listTools.viewAttributes");
        return (React.createElement(StatusBarPopover, { content: React.createElement(StatusBarDialog, { titleBar: React.createElement(StatusBarDialog.TitleBar, { title: title }) }, this.getViewFlags()) },
            React.createElement(IconButton, { styleType: "borderless", label: title },
                React.createElement(SvgWindowSettings, null),
                React.createElement(StatusBarPopover.ExpandIndicator, null))));
    }
}
//# sourceMappingURL=ViewAttributes.js.map