@import '@financial-times/o3-foundation/css/core.css';
@import "@financial-times/o-grid/main";
@import '@financial-times/o-loading/main';
@import "./progressBar.scss";

.cp-clip {
  --o-loading-size: 64px;
  @import "../components/caption";
  @import "../components/clip-tag";
  @import "../components/video-info-box";
  @import "../components/video-description";
  @import "../components/credit";

	@include oLoading($opts: (
		'themes': ('light'),
		'sizes': ('large')
	));
  --o-loading-size: 44px;

  &[data-o-component='cp-clip'] {
    flex: none;
  }
  position: relative;
  // Fits to the content, which is the video
  width: 100%;
  // Grid is needed only for Video info
  display: grid;
  grid-template-columns: 1fr;

  @mixin fade-out-animation() {
		animation: fade-out 0.5s 1;
		animation-fill-mode: forwards;
	}

	.cp-clip__video-controls {
		width: 100%;
		height: 100%;
		max-width: 100%;
		max-height: 80vh;
		box-sizing: border-box;
		position: absolute;
		top: 0;
	}

	// now this is darker for contrast accessibility, do not have it over the top of a playing video
	&:not(.cp-clip--playing) .cp-clip__video-controls {
		background-color: rgba(0, 0, 0, 0.25);
	}

	.cp-clip__video-controls-bottom-bar {
		display: flex;
		width: 100%;
		height: 35%;
		bottom: 0px;
		position: absolute;
		justify-content: space-between;
		align-items: flex-end;
		padding: var(--o3-spacing-5xs) var(--o3-spacing-4xs) var(--o3-spacing-s) var(--o3-spacing-4xs);
		box-sizing: border-box;
		background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, rgba(0, 0, 0, 0.75) 100%);
		&--fade-out:not(:has(button:focus)) {
			@include fade-out-animation();
		}
	}

	@mixin cp-clip__icon-container {
		text-align: center;
		margin: auto auto;
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%,-50%);
		color: var(--o3-color-palette-white);
		font-family: MetricWeb;
		line-height: 1;
	}

	@mixin cp-clip__control-circle() {
		background-color: rgba(0, 0, 0, 0.75);
		border: 2px solid transparent;
		border-radius: 50%;
		margin: auto;
		display: flex;
		justify-content: center;
		align-items: center;
		width: 72px;
		height: 72px;
		margin-bottom: var(--o3-spacing-4xs);
	}

	@mixin cp-clip__control-icon($icon){
		&:hover, &:focus {
			border-color: var(--o3-color-palette-white);
		}

		&::after {
			content: "";
			mask-image: var($icon);
			height: 44px;
			width: 44px;
	
			background-color: var(--o3-color-palette-white);
			}
	}


	.cp-clip__play-icon-container {
		@include cp-clip__icon-container;
	}

	.cp-clip__play-icon {
		@include cp-clip__control-circle();
		@include cp-clip__control-icon(--o3-icon-play);
	}

	.cp-clip__loading-text,
	.cp-clip__play-text {
		padding: 0 var(--o3-spacing-5xs);
		background-color: rgba(0, 0, 0, 0.75);
		display: block;
	}

	.cp-clip__replay-icon {
		@include cp-clip__control-circle();
		@include cp-clip__control-icon(--o3-icon-refresh);
	}

	// fade out the bottom controls only when they are not focussed
	&.cp-clip--ready .cp-clip__video-controls-bottom-bar:not(:has(button:focus)),
	&.cp-clip--paused .cp-clip__video-controls-bottom-bar:not(:has(button:focus)) {
		@include fade-out-animation();
	}

	// do not show the large play button when any of these are true:
		// if the video is playing
		// if the video is loading
		// if the bottom bar area has a focussed button
	&.cp-clip--playing .cp-clip__play-icon-container,
	&.cp-clip--loading .cp-clip__play-icon-container,
	.cp-clip__video-controls:has(.cp-clip__video-controls-bottom-bar button:focus) .cp-clip__play-icon-container {
		display: none;
	}

	&.cp-clip--playing .cp-clip__video-controls-bottom-bar {
		display: flex;
	}

	&.cp-clip--loading .cp-clip__loading-icon-container {
		display: block;
	}

	.cp-clip__playpause-icon-pause {
		position: relative;
		display: inline-block;
		width: var(--o3-spacing-m);
		height: var(--o3-spacing-m);
		background-color: transparent;
		
		&::after {
			content: "";
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 100%;
			background-color: var(--o3-color-palette-white);
			mask-image: var(--o3-icon-pause);
			mask-repeat: no-repeat;
			mask-size: contain;
		}
	}

	.cp-clip__playpause-icon-play {
		position: relative;
		display: inline-block;
		width: var(--o3-spacing-m);
		height: var(--o3-spacing-m);
		background-color: transparent;
		
		&::after {
			content: "";
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 100%;
			background-color: var(--o3-color-palette-white);
			mask-image: var(--o3-icon-play);
			mask-repeat: no-repeat;
			mask-size: contain;
		}
	}

	.cp-clip__playpause-icon {
		margin-left: var(--o3-spacing-3xs);
		border: none;
	}

	.cp-clip__playpause-icon-autoplay {
		border-radius: 50%;
		border: 2px solid var(--o3-color-palette-ft-grey);
		padding:0px;
		margin-left:var(--o3-spacing-4xs);
	}

	.cp-clip__playpause-icon-autoplay-progress {
		width: 100%;
		height: 100%;
		border-radius: 50%;
		border: solid 2px var(--o3-color-palette-white);
		display: inline-block;
		margin: -2px;
		box-sizing: content-box;
	}

	.cp-clip__mute-icon {
		display: inline-block;
		width: 32px;
		height: 32px;
		margin-right: var(--o3-spacing-2xs);
		border: none;
		position: relative;
		background-color: transparent;
    
		&::after {
			content: "";
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 100%;
			background-color: var(--o3-color-palette-white);
			mask-image: var(--o3-icon-volume);
			mask-repeat: no-repeat;
			mask-size: contain;
			mask-position: center;
		}
		
		&[data-mute="true"]::after {
			mask-image: var(--o3-icon-volume-mute);
		}
	}

	.cp-clip__no-audio {
		position: absolute;
		display: inline-block;
		width: 32px;
		height: 32px;
		background-color: transparent;
		right: var(--o3-spacing-xs);
		border: none;
		
		&::after {
			content: "";
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 100%;
			background-color: #999999 /* mix: black, white, 40*/;
			mask-image: var(--o3-icon-volume-mute);
			mask-repeat: no-repeat;
			mask-size: contain;
			mask-position: center;
		}
	}
// test

	.cp-clip__closed-caption {
		position: absolute;
		display: inline-block;
		width: 32px;
		height: 32px;
		background-color: transparent;
		right: 70px;
		border: none;
		
		&::after {
			content: "";
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 100%;
			background-color: var(--o3-color-palette-white);
			mask-image: var(--o3-icon-closed-captions-off);
			mask-repeat: no-repeat;
			mask-size: contain;
		}
	}

	.cp-clip__closed-caption:hover::after {
		mask-image: var(--o3-icon-closed-captions-on);
	}

	.cp-clip__closed-caption[data-display-closed-captions]::after {
		mask-image: var(--o3-icon-closed-captions-on);
	}

	@keyframes fade-out {
		from {opacity :1;}
		to {opacity :0;}
	}

	.cp-clip__loading-icon-container {
		@include cp-clip__icon-container;
		display: none;
	}

	.cp-clip__loading-icon-bg {
		@include cp-clip__control-circle();
	}

	.o-loading {
		width: var(--o-loading-size);
		height:  var(--o-loading-size);
	}
}
