@import "variables.scss";

// Style conversion file, bootstrap to tabulator

//Main Theme Variables
$backgroundColor: $table-bg; //background color of tabulator
$borderColor:$table-border-color; //border to tablulator
$textSize:$font-size-base; //table text size

//header themeing
$headerBackgroundColor:#fff; //border to tablulator
$headerSeperatorColor:$table-border-color; //header bottom seperator color

$cellPadding:$table-cell-padding; //padding round header
$cellPaddingCondensed:$table-condensed-cell-padding; //padding round header

//column header arrows
$sortArrowActive: #666;
$sortArrowInactive: #bbb;

//row themeing
$rowBackgroundColor:$backgroundColor; //table row background color
$rowAltBackgroundColor:$table-bg-accent; //table row background color
$rowBorderColor:$table-border-color; //table border color
$rowHoverBackground:$table-bg-hover; //row background color on hover

$rowSelectedBackground: #9ABCEA; //row background color when selected
$rowSelectedBackgroundHover: #769BCC;//row background color when selected and hovered


$editBoxColor:#1D68CD; //border color for edit boxes
$errorColor:#dd0000; //error indication

//footer themeing
$footerBorderColor:$table-border-color; //footer border color
$footerSeperatorColor:$table-border-color; //footer bottom seperator color



//Tabulator Containing Element
.tabulator{
	position: relative;
	background-color: $backgroundColor;
	overflow:hidden;
	font-size:$textSize;
	text-align: left;
	width: 100%;
	max-width: 100%;
	margin-bottom: $line-height-computed;

	-webkit-transform: translatez(0);
	-moz-transform: translatez(0);
	-ms-transform: translatez(0);
	-o-transform: translatez(0);
	transform: translatez(0);

	&[tabulator-layout="fitDataFill"]{
		.tabulator-tableHolder{
			.tabulator-table{
				min-width:100%;
			}
		}
	}

	&.tabulator-block-select{
		user-select: none;
	}

	//column header containing element
	.tabulator-header{
		position:relative;
		box-sizing: border-box;

		width:100%;

		border-bottom:2px solid $headerSeperatorColor;
		background-color: $headerBackgroundColor;
		font-weight:bold;

		white-space: nowrap;
		overflow:hidden;

		-moz-user-select: none;
		-khtml-user-select: none;
		-webkit-user-select: none;
		-o-user-select: none;

		//individual column header element
		.tabulator-col{
			display:inline-block;
			position:relative;
			box-sizing:border-box;
			background-color: $headerBackgroundColor;
			text-align:left;
			vertical-align: bottom;
			overflow: hidden;

			&.tabulator-moving{
				position: absolute;
				border:1px solid  $headerSeperatorColor;
				background:darken($headerBackgroundColor, 10%);
				pointer-events: none;
			}

			//hold content of column header
			.tabulator-col-content{
				position: relative;
				padding:$cellPadding;

				//hold title of column header
				.tabulator-col-title{
					box-sizing:border-box;
					width: 100%;

					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
					vertical-align:bottom;

					//element to hold title editor
					.tabulator-title-editor{
						box-sizing: border-box;
						width: 100%;

						border:1px solid #999;

						padding:1px;

						background: #fff;
					}
				}

				//column sorter arrow
				.tabulator-arrow{
					display: inline-block;
					position: absolute;
					top:14px;
					right:8px;
					width: 0;
					height: 0;
					border-left: 6px solid transparent;
					border-right: 6px solid transparent;
					border-bottom: 6px solid $sortArrowInactive;
				}

			}

			//complex header column group
			&.tabulator-col-group{

				//gelement to hold sub columns in column group
				.tabulator-col-group-cols{
					position:relative;
					display: flex;

					border-top:1px solid $borderColor;
					overflow: hidden;

					.tabulator-col:last-child{
						margin-right:-1px;
					}
				}
			}


			//hide left resize handle on first column
			&:first-child{
				.tabulator-col-resize-handle.prev{
					display: none;
				}
			}

			//placeholder element for sortable columns
			&.ui-sortable-helper{
				position: absolute;
				background-color:darken($headerBackgroundColor, 10%) !important;
				border:1px solid $borderColor;
			}

			//header filter containing element
			.tabulator-header-filter{
				position: relative;
				box-sizing: border-box;
				margin-top:2px;
				width:100%;
				text-align: center;

				//styling adjustment for inbuilt editors
				textarea{
					height:auto !important;
				}

				svg{
					margin-top: 3px;
				}
			}


			//styling child elements for sortable columns
			&.tabulator-sortable{
				.tabulator-col-title{
					padding-right:25px;
				}

				&:hover{
					cursor:pointer;
					background-color:darken($headerBackgroundColor, 10%);
				}

				&[aria-sort="none"]{
					.tabulator-col-content .tabulator-arrow{
						border-top: none;
						border-bottom: 6px solid $sortArrowInactive;
					}
				}

				&[aria-sort="asc"]{
					.tabulator-col-content .tabulator-arrow{
						border-top: none;
						border-bottom: 6px solid $sortArrowActive;
					}
				}

				&[aria-sort="desc"]{
					.tabulator-col-content .tabulator-arrow{
						border-top: 6px solid $sortArrowActive;
						border-bottom: none;
					}
				}
			}

		}

		.tabulator-frozen{
			display: inline-block;
			position: absolute;

			// background-color: inherit;

			z-index: 10;

			&.tabulator-frozen-left{
				border-right:2px solid $rowBorderColor;
			}

			&.tabulator-frozen-right{
				border-left:2px solid $rowBorderColor;
			}
		}

		.tabulator-calcs-holder{
			box-sizing:border-box;
			width:100%;

			background:lighten($headerBackgroundColor, 5%) !important;

			.tabulator-row{
				background:lighten($headerBackgroundColor, 5%) !important;

				.tabulator-col-resize-handle{
					display: none;
				}
			}

			border-top:1px solid $rowBorderColor;
			border-bottom:1px solid $headerSeperatorColor;

			overflow: hidden;
		}
	}



	//scrolling element to hold table
	.tabulator-tableHolder{
		position:relative;
		width:100%;
		white-space: nowrap;
		overflow:auto;
		-webkit-overflow-scrolling: touch;

		&:focus{
			outline: none;
		}

		//default placeholder element
		.tabulator-placeholder{
			position: absolute;
			box-sizing:border-box;
			display: flex;
			align-items:center;

			top:0;
			left:0;
			height:100%;
			width:100%;

			span{
				display: inline-block;

				margin:0 auto;
				padding:10px;

				color:#000;
				font-weight: bold;
				font-size: 20px;
			}
		}

		//element to hold table rows
		.tabulator-table{
			position:relative;
			display:inline-block;
			background-color:$rowBackgroundColor;
			white-space: nowrap;
			overflow:visible;

			.tabulator-row{
				&.tabulator-calcs{
					font-weight: bold;
					background:darken($rowAltBackgroundColor, 5%) !important;

					&.tabulator-calcs-top{
						border-bottom:2px solid $rowBorderColor;
					}

					&.tabulator-calcs-bottom{
						border-top:2px solid $rowBorderColor;
					}
				}
			}
		}
	}

	//row element
	.tabulator-row{
		position: relative;
		box-sizing: border-box;

		min-height:$textSize + ($cellPadding * 2);
		background-color: $rowBackgroundColor;
		border-bottom:1px solid $rowBorderColor;

		&.tabulator-selectable:hover{
			background-color:$rowHoverBackground !important;
			cursor: pointer;
		}

		&.tabulator-selected{
			background-color:$rowSelectedBackground;
		}

		&.tabulator-selected:hover{
			background-color:$rowSelectedBackgroundHover;
			cursor: pointer;
		}

		&.tabulator-moving{
			position: absolute;

			border-top:1px solid  $rowBorderColor;
			border-bottom:1px solid  $rowBorderColor;

			pointer-events: none !important;
			z-index:15;
		}

		.tabulator-frozen{
			display: inline-block;
			position: absolute;

			background-color: inherit;

			z-index: 10;

			&.tabulator-frozen-left{
				border-right:2px solid $rowBorderColor;
			}

			&.tabulator-frozen-right{
				border-left:2px solid $rowBorderColor;
			}
		}

		//cell element
		.tabulator-cell{
			display:inline-block;
			position: relative;
			box-sizing:border-box;
			padding:$cellPadding;
			vertical-align:middle;
			white-space:nowrap;
			overflow:hidden;
			text-overflow:ellipsis;

			&:last-of-type{
				border-right: none;
			}

			&.tabulator-editing{
				border:1px solid  $editBoxColor;
				padding: 0;

				input, select{
					border:1px;
					background:transparent;
				}
			}

			&.tabulator-validation-fail{
				border:1px solid $errorColor;
				input, select{
					border:1px;
					background:transparent;

					color: $errorColor;
				}
			}

			//hide left resize handle on first column
			&:first-child{
				.tabulator-col-resize-handle.prev{
					display: none;
				}
			}

			//movable row handle
			&.tabulator-row-handle{

				display: inline-flex;
				align-items:center;

				-moz-user-select: none;
				-khtml-user-select: none;
				-webkit-user-select: none;
				-o-user-select: none;

				//handle holder
				.tabulator-row-handle-box{
					width:80%;

					//Hamburger element
					.tabulator-row-handle-bar{
						width:100%;
						height:3px;
						margin:2px 10% 0 10%;
						background:#666;
					}
				}
			}
		}
		//row grouping element
		&.tabulator-group{

			box-sizing:border-box;
			border-bottom:1px solid #999;
			border-right:1px solid $rowBorderColor;
			border-top:1px solid #999;
			padding:5px;
			padding-left:10px;
			background:#fafafa;
			font-weight:bold;

			min-width: 100%;

			&:hover{
				cursor:pointer;
				background-color:rgba(0,0,0,.1);
			}

			&.tabulator-group-visible{
				.tabulator-arrow{
					margin-right:10px;
					border-left: 6px solid transparent;
					border-right: 6px solid transparent;
					border-top: 6px solid $sortArrowActive;
					border-bottom: 0;
				}
			}

			&.tabulator-group-level-1{
				.tabulator-arrow{
					margin-left:20px;
				}
			}

			&.tabulator-group-level-2{
				.tabulator-arrow{
					margin-left:40px;
				}
			}

			&.tabulator-group-level-3{
				.tabulator-arrow{
					margin-left:60px;
				}
			}

			&.tabulator-group-level-4{
				.tabulator-arrow{
					margin-left:80px;
				}
			}

			&.tabulator-group-level-5{
				.tabulator-arrow{
					margin-left:1000px;
				}
			}

			//sorting arrow
			.tabulator-arrow{
				display: inline-block;
				width: 0;
				height: 0;
				margin-right:16px;
				border-top: 6px solid transparent;
				border-bottom: 6px solid transparent;
				border-right: 0;
				border-left: 6px solid $sortArrowActive;
				vertical-align:middle;
			}

			span{
				margin-left:10px;
				color:#666;
			}
		}
	}

	//column resize handles
	.tabulator-col-resize-handle{
		position:absolute;
		right:0;
		top:0;
		bottom:0;
		width:5px;

		&.prev{
			left:0;
			right:auto;
		}

		&:hover{
			cursor:ew-resize;
		}
	}


	//footer element
	.tabulator-footer{
		padding:5px 10px;
		border-top:2px solid $footerSeperatorColor;
		text-align:right;
		font-weight:bold;
		white-space:nowrap;
		user-select:none;

		-moz-user-select: none;
		-khtml-user-select: none;
		-webkit-user-select: none;
		-o-user-select: none;

		.tabulator-calcs-holder{
			box-sizing:border-box;
			width:calc("100% + 20px");
			margin:-5px -10px 5px -10px;

			text-align: left;

			background:lighten($backgroundColor, 5%) !important;

			.tabulator-row{
				background:lighten($backgroundColor, 5%) !important;

				.tabulator-col-resize-handle{
					display: none;
				}
			}

			border-bottom:1px solid $rowBorderColor;
			border-top:1px solid $rowBorderColor;

			overflow: hidden;

			&:only-child{
				margin-bottom:-5px;
				border-bottom:none;
			}
		}

		//pagination container element
		.tabulator-pages{
			margin:0 7px;
		}

		//pagination button
		.tabulator-page{
			display:inline-block;
			margin:0 2px;
			border:1px solid $footerBorderColor;
			border-radius:3px;
			padding:2px 5px;
			background:rgba(255,255,255,.2);
			font-family:inherit;
			font-weight:inherit;
			font-size:inherit;


			&.active{
				color:#d00;
			}

			&:disabled{
				opacity:.5;
			}

			&:not(.disabled){
				&:hover{
					cursor:pointer;
					background:rgba(0,0,0,.2);
					color:#fff;
				}
			}
		}
	}

	//holding div that contains loader and covers tabulator element to prevent interaction
	.tablulator-loader{
		position:absolute;
		display: flex;
		align-items:center;

		top:0;
		left:0;
		z-index:100;

		height:100%;
		width:100%;
		background:rgba(0,0,0,.4);
		text-align:center;

		//loading message element
		.tabulator-loader-msg{
			display:inline-block;

			margin:0 auto;
			padding:10px 20px;

			border-radius:10px;

			background:#fff;
			font-weight:bold;
			font-size:16px;

			//loading message
			&.tabulator-loading{
				border:4px solid #333;
				color:#000;
			}

			//error message
			&.tabulator-error{
				border:4px solid #D00;
				color:#590000;
			}
		}
	}



	//Bootstrap theming classes

	&.table-striped{
		.tabulator-row{
			&:nth-child(even){
				background-color: $rowAltBackgroundColor;
			}
		}
	}

	&.table-bordered{
		border:1px solid $borderColor;

		.tabulator-header{
			.tabulator-col{
				border-right:1px solid $borderColor;
			}
		}

		.tabulator-tableHolder{
			.tabulator-table{
				.tabulator-row{
					.tabulator-cell{
						border-right:1px solid $borderColor;
					}
				}
			}
		}

	}

	&.table-condensed{
		.tabulator-header{
			.tabulator-col{
				.tabulator-col-content{
					padding:$cellPaddingCondensed;
				}
			}
		}

		.tabulator-tableHolder{
			.tabulator-table{
				.tabulator-row{
					min-height:$textSize + ($cellPaddingCondensed * 2);

					.tabulator-cell{
						padding:$cellPaddingCondensed;
					}
				}
			}
		}
	}


	//row colors
	.tabulator-tableHolder{
		.tabulator-table{
			.tabulator-row{
				&.active{
					background:$table-bg-active!important;
				}
				&.success{
					background:$state-success-bg!important;
				}
				&.info{
					background: $state-info-bg!important;
				}
				&.warning{
					background:$state-warning-bg!important;
				}
				&.danger{
					background:$state-danger-bg!important;
				}
			}
		}
	}

}

