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 { MapToComponentMethod, MapToComponentField, VegaSlimmer } from 'vega-slimmer/core';
import { findParent, getDeepActiveElementInShadow } from '../../../../utils/ui';
/** The `VegaImageUploaderActionsVisibilityController` class is responsible for handling the focus and hiding of backdrop and tooltip elements in a Vega Image Uploader component. */
export class VegaImageUploaderActionsVisibilityController extends VegaSlimmer {
  /*
   * The below method is e2e-test covered in
   * @see{module:should-hide-backdrop-and-tooltip-when-change-value}
   */
  /* istanbul ignore next */
  /** trigger a vegaChange event when component value change */
  handleValueChange() {
    if (this.value) {
      this.hideBackDropAndActions();
    }
  }
  /*
   * The below method is e2e-test covered in
   * @see{module:should-hide-backdrop-and-tooltip-when-change-value}
   */
  /* istanbul ignore next */
  /**
   * The function hides the backdrop and actions of a vega-image-uploader component by blurring the active element.
   * The activeElement should be div.image-preview-container and replace button
   */
  hideBackDropAndActions() {
    const activeElement = getDeepActiveElementInShadow();
    if (activeElement && findParent(activeElement, 'vega-image-uploader') === this.host) {
      activeElement.blur();
    }
  }
}
__decorate([
  MapToComponentField()
], VegaImageUploaderActionsVisibilityController.prototype, "host", void 0);
__decorate([
  MapToComponentField()
], VegaImageUploaderActionsVisibilityController.prototype, "value", void 0);
__decorate([
  MapToComponentMethod('watchValue')
], VegaImageUploaderActionsVisibilityController.prototype, "handleValueChange", null);
