/*---------------------------------------------------------------------------------------------
 * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
 * See LICENSE.md in the project root for license terms and full copyright notice.
 *--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Timeline
 */
import { Cartographic, ColorByName, ColorDef, SolarShadowSettings, } from "@itwin/core-common";
import { BaseSolarDataProvider } from "@itwin/imodel-components-react";
// the interface and class are in alpha state - it may change after usability testing - test coverage not complete
/** Default Solar Data Provider interface for getting and setting solar position from iModels view definitions.
 * @alpha
 */
export class SolarTimelineDataProvider extends BaseSolarDataProvider {
    get _displayStyle3d() {
        return undefined !== this._viewport && this._viewport.view.is3d()
            ? this._viewport.view.displayStyle
            : undefined;
    }
    /** constructor that takes an optional viewport and optional position on globe that is used if the imodel is not "GeoLocated"  */
    constructor(viewState, viewport, longitude, latitude) {
        super(viewport, longitude, latitude);
        this.onTimeChanged = (time) => {
            if (this._viewport && this._viewport.view.is3d()) {
                this._viewport.view.displayStyle.setSunTime(time.getTime());
            }
        };
        this._viewState = viewState;
        if (viewState.is3d()) {
            this.supportsTimelineAnimation = true;
            this._cartographicCenter = this.getCartographicCenter(viewState.iModel);
        }
        else {
            this._cartographicCenter = Cartographic.fromDegrees({
                longitude: this.longitude,
                latitude: this.latitude,
                height: 0.0,
            });
        }
        this._projectTimeZoneOffset = this.getZone(this._cartographicCenter);
        this.initializeData(this._projectTimeZoneOffset);
        this.onTimeChanged(this.timeOfDay);
    }
    get shouldShowTimeline() {
        const style = this._displayStyle3d;
        return undefined !== style && style.viewFlags.shadows;
    }
    get shadowColor() {
        const style = this._displayStyle3d;
        return style
            ? style.settings.solarShadows.color.toColorDef()
            : ColorDef.create(ColorByName.gray);
    }
    set shadowColor(color) {
        const displayStyle = this._displayStyle3d;
        if (!displayStyle)
            return;
        const prevColor = displayStyle.settings.solarShadows.color;
        const newColor = color.colors;
        if (prevColor.r === newColor.r &&
            prevColor.g === newColor.g &&
            prevColor.b === newColor.b)
            return;
        const newSettings = displayStyle.settings.solarShadows.toJSON() ?? {};
        newSettings.color = color.tbgr;
        displayStyle.settings.solarShadows =
            SolarShadowSettings.fromJSON(newSettings);
    }
}
//# sourceMappingURL=SolarTimelineDataProvider.js.map