/*!
 * Copyright (C) 2013-2021 Combodo SARL
 *
 * This file is part of iTop.
 *
 * iTop is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * iTop is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 */

/* SCSS variables */
$ibo-panel--spacing-top: 24px !default;

$ibo-panel--header--margin-bottom: 4px !default;

$ibo-panel--icon--size: 48px !default;
$ibo-panel--icon--spacing: 16px !default;
$ibo-panel--icon--size-as-medallion: 72px !default;
$ibo-panel--icon--spacing--as-medallion: 16px !default;
$ibo-panel--icon--bottom--as-medallion: -24px !default;
$ibo-panel--icon--background-color--as-medallion: $ibo-color-grey-100 !default;
$ibo-panel--icon--border--as-medallion: 2px solid $ibo-color-blue-grey-300 !default;
$ibo-panel--icon--border-radius--as-medallion: $ibo-border-radius-full !default;

$ibo-panel--icon-background--size--must-contain: contain !default;
$ibo-panel--icon-background--size--must-cover: cover !default;
$ibo-panel--icon-background--size--must-zoomout: 66.67% !default;

$ibo-panel--title--color: $ibo-color-grey-900 !default;
$ibo-panel--subtitle--color: $ibo-color-grey-800 !default;

$ibo-panel--highlight--width: 100% !default;
$ibo-panel--highlight--height: 8px !default;
$ibo-panel--highlight--border-radius: $ibo-border-radius-400 $ibo-border-radius-400 0 0 !default;
$ibo-panel--highlight--padding-bottom: $ibo-panel--highlight--height !default;

$ibo-panel--body--background-color: $ibo-color-white-100 !default;
$ibo-panel--body--padding-bottom: 24px !default;
$ibo-panel--body--padding-top: $ibo-panel--body--padding-bottom + $ibo-panel--highlight--height !default;
$ibo-panel--body--padding-x: 16px !default;
$ibo-panel--body--border-radius: $ibo-border-radius-500 !default;
$ibo-panel--body--border-size: 1px !default;
$ibo-panel--body--border-color: $ibo-color-grey-400 !default;

$ibo-panel--collapsible-toggler--margin-right: 8px !default;
$ibo-panel--collapsible-toggler--font-size: $ibo-font-size-250 !default;
$ibo-panel--collapsible-toggler--color: $ibo-color-grey-700 !default;

$ibo-panel-colors: (
		'primary': $ibo-color-primary-600,
		'secondary': $ibo-color-secondary-600,
		'neutral': $ibo-color-grey-600,
		'information': $ibo-color-information-600,
		'success': $ibo-color-success-600,
		'failure': $ibo-color-danger-600,
		'warning': $ibo-color-warning-600,
		'danger': $ibo-color-danger-600,
		'grey' : $ibo-color-grey-600,
		'blue-grey': $ibo-color-blue-grey-600,
		'blue': $ibo-color-blue-800,
		'cyan': $ibo-color-cyan-600,
		'green': $ibo-color-green-600,
		'orange' : $ibo-color-orange-600,
		'red': $ibo-color-red-600,
		'pink': $ibo-color-pink-600,
) !default;

@each $sColor, $sColorValue in $ibo-panel-colors {
	.ibo-panel.ibo-is-#{$sColor} > .ibo-panel--body::before {
		position: absolute;
		top: 0;
		left: 0;
		display: block;

		background-color: $sColorValue;
		content: "";

		width: $ibo-panel--highlight--width;
		height: $ibo-panel--highlight--height;
		padding-bottom: $ibo-panel--highlight--padding-bottom;
	}
}

/* Rules */
.ibo-panel + .ibo-panel {
	margin-top: $ibo-panel--spacing-top;
}

.ibo-panel {
  &.ibo-has-icon {
    .ibo-panel--titles {
      padding-left: $ibo-panel--icon--spacing;
    }

    &.ibo-has-medallion-icon {
      .ibo-panel--header-left {
        position: relative;
        z-index: 1;
        margin-left: $ibo-panel--icon--spacing--as-medallion;
      }

      // Note: Direct child selector is mandatory, otherwise a panel within a panel with a medallion icon will have its icon as a medallion too (eg. dashboard in an object)
      > .ibo-panel--header {
        .ibo-panel--header-left {
          .ibo-panel--icon {
            position: absolute;
            bottom: $ibo-panel--icon--bottom--as-medallion;
            left: 0;
            overflow: hidden;
            width: $ibo-panel--icon--size-as-medallion;
            height: $ibo-panel--icon--size-as-medallion;
            min-width: $ibo-panel--icon--size-as-medallion;
            min-height: $ibo-panel--icon--size-as-medallion;
            background-color: $ibo-panel--icon--background-color--as-medallion;
            border: $ibo-panel--icon--border--as-medallion;
            border-radius: $ibo-panel--icon--border-radius--as-medallion;
          }
          .ibo-panel--titles {
            padding-left: calc(#{$ibo-panel--icon--size-as-medallion} + #{$ibo-panel--icon--spacing--as-medallion});
          }
        }
      }
    }
  }
}

.ibo-panel--header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: $ibo-panel--header--margin-bottom;
}

.ibo-panel--header-left {
  @extend %ibo-fully-centered-content;
  justify-content: left;
}

.ibo-panel--icon {
  @extend %ibo-fully-centered-content;
  width: $ibo-panel--icon--size;
  height: $ibo-panel--icon--size;
  min-width: $ibo-panel--icon--size;
  min-height: $ibo-panel--icon--size;
}


.ibo-panel--icon-background {
  width: 100%;
  height: 100%;
  background-position: center;
  background-repeat: no-repeat;
  background-size: $ibo-panel--icon-background--size--must-contain;
}

.ibo-panel--icon-background--must-contain {
  background-size: $ibo-panel--icon-background--size--must-contain;
}

.ibo-panel--icon-background--must-cover {
  background-size: $ibo-panel--icon-background--size--must-cover;
}

.ibo-panel--icon-background--must-zoomout {
  background-size: $ibo-panel--icon-background--size--must-zoomout;
}

.ibo-panel--title {
  display: inline-block;
  color: $ibo-panel--title--color;
  @extend %ibo-font-ral-med-250;
  flex-grow: 1;
}

.ibo-panel--subtitle {
  display: flex;
  @extend %ibo-font-ral-med-250;
  color: $ibo-panel--subtitle--color;
}

.ibo-panel--body {
	position: relative;
	padding: $ibo-panel--body--padding-top $ibo-panel--body--padding-x $ibo-panel--body--padding-bottom $ibo-panel--body--padding-x;
	background-color: $ibo-panel--body--background-color;
	border: solid $ibo-panel--body--border-size $ibo-panel--body--border-color;
	border-radius: $ibo-panel--body--border-radius;
	overflow: hidden; /* To force highlight color to be cropped by the border radius */

	@extend %ibo-font-ral-nor-200;
}

.ibo-panel--collapsible-toggler{
  display: inline-block;
  margin-right: $ibo-panel--collapsible-toggler--margin-right;
  font-size: $ibo-panel--collapsible-toggler--font-size;
  color: $ibo-panel--collapsible-toggler--color;
  cursor: pointer;
}

.ibo-panel--collapsible-toggler--opened{
  display: block;
}

.ibo-panel--collapsible-toggler--closed{
  display: none;
}

.ibo-panel:not(.ibo-is-opened) {
  .ibo-panel--collapsible-toggler--closed{
    display: block;
  }
  .ibo-panel--collapsible-toggler--opened{
    display: none;
  }
  .ibo-panel--body{
    display: none;
  }
}