@use './themes/base.scss';
@import './z-index.scss';

:host {
  display: block;

  // Anchor absolutes to the outermost part of the card.
  position: relative;

  // Different browsers use different colors as their fullscreen background,
  // this ensures the same experience across all browsers.
  background-color: var(--advanced-camera-card-background);

  border-radius: var(--ha-card-border-radius, 4px);
  overflow: auto;

  height: var(--advanced-camera-card-height);
  min-height: 100px;

  // Ensure all clicks at the top level work.
  pointer-events: all;

  // The standard HA header is 56 pixels tall, so that much off the top (header)
  // and bottom (to maintain center), before doing the calculation of
  // max-height. This matters on small mobile devices in landscape orientation.
  --advanced-camera-card-expand-max-height: calc((100vh - (2 * 56px)) * 0.85);
  --advanced-camera-card-expand-max-width: 85vw;
  --advanced-camera-card-expand-width: none;
  --advanced-camera-card-expand-height: none;
  --advanced-camera-card-expand-aspect-ratio: unset;

  --advanced-camera-card-height: auto;
}

// Without hovering over the card, it is "flattened" to avoid z-index weaving
// from other cards. Tip: Best way to test this is with multiple Advanced Camera
// Cards, opening a submenu on the 1st (e.g. media players) and verifying the
// menu of the 2nd card is not visible through the opened submenu on the 1st.
:host(:not(:hover)) {
  z-index: #{$z-index-card-flatten};
}

advanced-camera-card-loading {
  position: absolute;
  inset: 0;
  z-index: #{$z-index-loading};
}

:host([dimmable]:not([interaction])) {
  filter: brightness(75%);
}
:host([panel]:not([casted])) {
  // Card always extends to the full height in panel mode minus the header.
  //
  // If the "Kiosk Mode" (https://github.com/maykar/kiosk-mode) plugin is
  // installed, the --kiosk-header-height variable will be authoritative
  // instead.
  // See: https://github.com/dermotduffy/advanced-camera-card/issues/1762
  height: calc(100vh - var(--kiosk-header-height, var(--header-height)));
}
:host([panel][casted]) {
  // Card always extends to the full height in panel mode when casting (there is
  // no header).
  // See: https://github.com/dermotduffy/advanced-camera-card/issues/1746
  height: 100%;
}

div.main {
  position: relative;

  overflow: auto;

  width: 100%;
  height: 100%;
  margin: auto;
  display: block;

  // Hide scrollbar: Firefox
  scrollbar-width: none;
  // Hide scrollbar: IE and Edge
  -ms-overflow-style: none;
}

/* Hide scrollbar for Chrome, Safari and Opera */
div.main::-webkit-scrollbar {
  display: none;
}

ha-card {
  display: flex;
  flex-direction: column;
  margin: auto;

  border: 0px;

  // Some elements (such as submenus) may need to extend beyond the card boundary.
  overflow: visible;
  width: 100%;
  height: 100%;
  position: static;
  color: var(--secondary-text-color, white);

  // The background color at the outer level has priority.
  background-color: transparent;
}

/************
 * Fullscreen
 *************/

// Browsers will reject invalid whole CSS selectors if one selector is bad, so
// need to use mixin here instead of just comma-separated selectors.
//  - Related: https://stackoverflow.com/questions/16982449/why-isnt-it-possible-to-combine-vendor-specific-pseudo-elements-classes-into-on
@mixin fullscreen-ha-card {
  // Hide corners on Safari fullscreen.
  border-radius: 0px;

  // Theme styles may set these which are not helpful in fullscreen mode, reset
  // them.
  box-shadow: none;
  margin: 0;
}

// Need to use an id selector here to overcome theme styling that may
// incorrectly apply to ha-card style.
:host(:fullscreen) #ha-card {
  @include fullscreen-ha-card;
}
:host(:-webkit-full-screen) #ha-card {
  @include fullscreen-ha-card;
}

@mixin fullscreen-no-rounded-corners {
  // Hide corners on Safari fullscreen.
  border-radius: 0px;
}

:host(:fullscreen) div.main,
:host(:fullscreen) advanced-camera-card-menu {
  @include fullscreen-no-rounded-corners;
}
:host(:-webkit-full-screen) div.main,
:host(:-webkit-full-screen) advanced-camera-card-menu {
  @include fullscreen-no-rounded-corners;
}

/***************
 * Expanded mode
 ***************/

web-dialog {
  --dialog-padding: 0px;
  --dialog-container-padding: 0px;

  --dialog-max-height: var(--advanced-camera-card-expand-max-height);
  --dialog-max-width: var(--advanced-camera-card-expand-max-width);

  --dialog-width: var(--advanced-camera-card-expand-width);
  --dialog-height: var(--advanced-camera-card-expand-height);

  // Allow submenus to flow outside the edge of the dialog.
  --dialog-overflow-x: visible;
  --dialog-overflow-y: visible;

  // Required to ensure the dialog is centered vertically.
  max-height: 100vh;
}

web-dialog::part(dialog) {
  aspect-ratio: var(--advanced-camera-card-expand-aspect-ratio);

  // Fixes to render the dialog correctly in Safari.
  border-radius: 0px;
  background: transparent;
}

/*******************
 * Menu hover styles
 *******************/

advanced-camera-card-menu {
  z-index: #{$z-index-menu};
}

advanced-camera-card-menu[data-style*='hover'] {
  transition: opacity 0.5s ease;
  opacity: 0;
}
advanced-camera-card-menu[data-style*='hover']:hover,
ha-card:hover
  > advanced-camera-card-overlay
  > advanced-camera-card-menu[data-style='hover-card'] {
  opacity: 1;
}

/*************************
 * Status bar hover styles
 *************************/

advanced-camera-card-status-bar {
  z-index: #{$z-index-status-bar};
}

advanced-camera-card-status-bar[data-style*='hover'] {
  transition: opacity 0.5s ease;
  opacity: 0;
}
advanced-camera-card-status-bar[data-style*='hover']:hover,
ha-card:hover
  > advanced-camera-card-overlay
  > advanced-camera-card-status-bar[data-style='hover-card'] {
  opacity: 1;
}
