<?php
/**
 * Inline Style generator
 *
 * @package     Wow_Plugin
 * @copyright   Copyright (c) 2018, Dmytro Lobov
 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
 * @since       1.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

$zindex = ! empty( $param['zindex'] ) ? $param['zindex'] : '9';
$margin = ! empty( $param['margin'] ) ? $param['margin'] . 'px' : '0';

$css .= '#side-menu-' . $id . ' {';
$css .= 'z-index:' . $zindex . ';';
$css .= 'margin-top:' . $margin . ';';
$css .= '}';

$height = ! empty( $param['height'] ) ? $param['height'] : '40';

$css .= '#side-menu-' . $id . ' .sm-icon, #side-menu-' . $id . ' .sm-label {';
$css .= 'height:' . $height . 'px;';
$css .= 'line-height:' . $height . 'px;';
$css .= '}';

$iconsize = ! empty( $param['iconsize'] ) ? $param['iconsize'] : '24';

$css .= '#side-menu-' . $id . ' .sm-icon {';
$css .= 'width:' . $height . 'px;';
$css .= 'font-size:' . $iconsize . 'px;';
$css .= '}';

$css .= '#side-menu-' . $id . ' .sm-icon img {';
$css .= 'margin:' . ( $height - $iconsize ) / 2 . 'px;';
$css .= 'height:' . $iconsize . 'px;';
$css .= '}';

$fontsize   = ! empty( $param['fontsize'] ) ? $param['fontsize'] : '24';
$fontstyle  = ! empty( $param['fontstyle'] ) ? $param['fontstyle'] : 'normal';
$fontweight = ! empty( $param['fontweight'] ) ? $param['fontweight'] : 'normal';

$css .= '#side-menu-' . $id . ' .sm-label {';
$css .= 'font-size:' . $fontsize . 'px;';
$css .= 'font-style:' . $fontstyle . ';';
$css .= 'font-weight:' . $fontweight . ';';
$css .= '}';

$bwidth        = ! empty( $param['bwidth'] ) ? $param['bwidth'] . 'px' : '0';
$bradiustop    = ! empty( $param['bradiustop'] ) ? $param['bradiustop'] . 'px' : '0';
$bradiusbottom = ! empty( $param['bradiusbottom'] ) ? $param['bradiusbottom'] . 'px' : '0';
$bcolor        = ! empty( $param['bcolor'] ) ? $param['bcolor'] : 'rgba(0,0,0,0.75)';

if (! empty( $param['connect'] ) ) {
	$css .= '#side-menu-' . $id . '.-right.-list-show .sm-list {';
	$css .= 'right: calc(-100% + ' . $height . 'px);';
	$css .= '}';

	$css .= '#side-menu-' . $id . '.-left.-list-show .sm-list {';
	$css .= 'left: calc(-100% + ' . $height . 'px);';
	$css .= '}';

	$css .= '#side-menu-' . $id . ' .sm-list {';
	$css .= 'border-color: ' . $bcolor . ';';
	$css .= 'border-style: solid;';
	$css .= '}';

	$css .= '#side-menu-' . $id . '.-left .sm-list {';
	$css .= 'border-width: ' . $bwidth . ' ' . $bwidth . ' ' . $bwidth . ' 0;';
	$css .= 'border-radius: 0 ' . $bradiustop . ' ' . $bradiusbottom . ' 0;';
	$css .= '}';

	$css .= '#side-menu-' . $id . '.-left .sm-list .sm-item:first-child a {';
	$css .= 'border-top-right-radius: ' . $bradiustop . ';';
	$css .= '}';

	$css .= '#side-menu-' . $id . '.-left .sm-list .sm-item:last-child a {';
	$css .= 'border-bottom-right-radius: ' . $bradiusbottom . ';';
	$css .= '}';

	$css .= '#side-menu-' . $id . '.-right .sm-list {';
	$css .= 'border-width: ' . $bwidth . ' 0 ' . $bwidth . ' ' . $bwidth . ';';
	$css .= 'border-radius: ' . $bradiustop . ' 0 0 ' . $bradiusbottom . ';';
	$css .= '}';

	$css .= '#side-menu-' . $id . '.-right .sm-list .sm-item:first-child a {';
	$css .= 'border-top-left-radius: ' . $bradiustop . ';';
	$css .= '}';

	$css .= '#side-menu-' . $id . '.-right .sm-list .sm-item:last-child a {';
	$css .= 'border-bottom-left-radius: ' . $bradiusbottom . ';';
	$css .= '}';

}
else {
	$css .= '#side-menu-' . $id . '.-right .sm-item {';
	$css .= 'right: calc(-100% + ' . $height . 'px);';
	$css .= '}';

	$css .= '#side-menu-' . $id . '.-left .sm-item {';
	$css .= 'left: calc(-100% + ' . $height . 'px);';
	$css .= '}';

	$css .= '#side-menu-' . $id . ' .sm-item a {';
	$css .= 'border-color: ' . $bcolor . ';';
	$css .= 'border-style: solid;';
	$css .= '}';

	$css .= '#side-menu-' . $id . '.-left .sm-item a {';
	$css .= 'border-width: ' . $bwidth . ' ' . $bwidth . ' ' . $bwidth . ' 0;';
	$css .= 'border-radius: 0 ' . $bradiustop . ' ' . $bradiusbottom . ' 0;';
	$css .= '}';

	$css .= '#side-menu-' . $id . '.-right .sm-item a {';
	$css .= 'border-width: ' . $bwidth . ' 0 ' . $bwidth . ' ' . $bwidth . ';';
	$css .= 'border-radius: ' . $bradiustop . ' 0 0 ' . $bradiusbottom . ';';
	$css .= '}';
}

$gap = ! empty( $param['gap'] ) ? $param['gap']. 'px' : '0';

$css .= '#side-menu-' . $id . ' .sm-item {';
$css .= 'margin: ' . $gap . ' 0;';
$css .= '}';

$css .= '#side-menu-' . $id . ' .sm-item:first-child {';
$css .= 'margin-top: 0;';
$css .= '}';

$css .= '#side-menu-' . $id . ' .sm-item:last-child {';
$css .= 'margin-bottom: 0;';
$css .= '}';

if ( ! empty( $param['menu_1']['item_type'] ) ) {
	$count_i = count( $param['menu_1']['item_type'] );
} else {
	$count_i = 0;
}
if ( $count_i > 0 ) {

	for ( $i = 1; $i <= $count_i; $i ++ ) {
		$ii  = $i - 1;
		$css .= '#side-menu-' . $id . ' .sm-list .sm-item:nth-child(' . $i . ') a {';
		$css .= 'background:' . $param['menu_1']['bcolor'][ $ii ] . ';';
		$css .= '}';
		$css .= '#side-menu-' . $id . ' .sm-list .sm-item:nth-child(' . $i . ') a .sm-icon {';
		$css .= 'color:' . $param['menu_1']['iconcolor'][ $ii ] . ';';
		$css .= '}';
		$css .= '#side-menu-' . $id . ' .sm-list .sm-item:nth-child(' . $i . ') a .sm-label {';
		$css .= 'color:' . $param['menu_1']['color'][ $ii ] . ';';
		$css .= '}';
		$css .= '#side-menu-' . $id . ' .sm-list .sm-item:nth-child(' . $i . '):hover a {';
		$css .= 'background:' . $param['menu_1']['hbcolor'][ $ii ] . ';';
		$css .= '}';
	}

	if ( ! empty( $param['include_mobile'] ) ) {
		$screen = ! empty( $param['screen'] ) ? $param['screen'] : 480;
		$css    .= '
					@media only screen and (max-width: ' . $screen . 'px){
						#side-menu-' . $id . ' {
							display:none;
						}
					}';
	}

	if ( ! empty( $param['include_more_screen'] ) ) {
		$screen_more = ! empty( $param['screen_more'] ) ? $param['screen_more'] : 1200;
		$css         .= '
					@media only screen and (min-width: ' . $screen_more . 'px){
						#side-menu-' . $id . ' {
							display:none;
						}
					}';
	}

	$css = trim( preg_replace( '~\s+~s', ' ', $css ) );

}