var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { MapToComponentField, MapToComponentMethod, VegaSlimmer } from 'vega-slimmer/core';
/**
 * VegaBackdrop visible controller
 */
export class VegaBackdropVisibleController extends VegaSlimmer {
  /**
   * During the loading process of the component, the background style is updated.
   */
  componentDidLoad() {
    this.updateBackdropStyle();
  }
  /**
   * Watching the visible prop.
   */
  watchVisible() {
    this.updateBackdropStyle();
  }
  /**
   * If visible is true, the backdrop will be visible.
   * If visible is false, the backdrop will be hidden and backdrop display will be none after the duration.
   */
  updateBackdropStyle() {
    if (this.visible) {
      this.host.style.display = 'block';
      setTimeout(() => {
        this.host.style.opacity = '1';
      });
    }
    else {
      this.host.style.opacity = '0';
      setTimeout(() => {
        if (!this.visible) {
          this.host.style.display = 'none';
        }
      }, this.duration);
    }
  }
}
__decorate([
  MapToComponentField()
], VegaBackdropVisibleController.prototype, "host", void 0);
__decorate([
  MapToComponentField()
], VegaBackdropVisibleController.prototype, "visible", void 0);
__decorate([
  MapToComponentField()
], VegaBackdropVisibleController.prototype, "duration", void 0);
__decorate([
  MapToComponentMethod('componentDidLoad')
], VegaBackdropVisibleController.prototype, "componentDidLoad", null);
__decorate([
  MapToComponentMethod('watchVisible')
], VegaBackdropVisibleController.prototype, "watchVisible", null);
