<?php

/**
* Custom Controls WordPress Customizer
*
* Toggle Control
*
*
* @author Stefano Fattori
* @version 1.0
*
*/

add_action( 'customize_register', 'luxuryconceptfree_wp_customize_toggle_control' );

function luxuryconceptfree_wp_customize_toggle_control($wp_customize) {


class luxuryconceptfree_Customizer_Toggle_Control extends WP_Customize_Control {

	/**
	 * Enqueue scripts/styles.
	 */
	public function enqueue() {
		wp_enqueue_style( 'luxuryconceptfree-customize-control', $this->abs_path_to_url( dirname( __FILE__ ) . '/css/customizer.css' ), array(), rand() );
	}

	/**
	 * Render the control's content.
	 */
	 
	public function render_content() {
		$input_id         = '_customize-input-' . $this->id;
		$description_id   = '_customize-description-' . $this->id;
		$describedby_attr = ( ! empty( $this->description ) ) ? ' aria-describedby="' . esc_attr( $description_id ) . '" ' : '';		
		?>

		<div class="toggle-switch">
				<input id="<?php echo esc_attr( $input_id ); ?>" <?php echo esc_attr( $describedby_attr ); ?> type="checkbox" value="<?php echo esc_attr( $this->value() ); ?>"
											<?php
											$this->link();
											checked( $this->value() );
											?>
				 />					
				<label for=<?php echo esc_attr( $input_id ); ?>"><?php echo esc_html( $this->label ); ?></label>
				<?php if ( ! empty( $this->description ) ) : ?>
				<span id="<?php echo esc_attr( $description_id ); ?> class="description customize-control-description"><?php echo esc_html( $this->description ); ?></span>
				<?php endif; ?>	
	   </div>
		<?php
	}

	/**
	 * Plugin / theme agnostic path to URL
	 *
	 * @see https://wordpress.stackexchange.com/a/264870/14546
	 * @param string $path  file path
	 * @return string       URL
	 */
	private function abs_path_to_url( $path = '' ) {
		$url = str_replace(
			wp_normalize_path( untrailingslashit( ABSPATH ) ),
			esc_url( home_url( '/' ) ), //site_url(),
			wp_normalize_path( $path )
		);
		return esc_url_raw( $url );
	}
}
}