<?php

class MW_section_download extends WP_Widget {

	function __construct(){
		parent::__construct( 
			'oginer_hompage_download', 
			esc_html__('Oginer: Button Link Icon', 'oginer' ), 
			array(
				'classname' => 'mw_widget_homepage_download',
				'description' => esc_html__( 'Display Downloads Buttons.', 'oginer')
			)
		);

	}

	function widget( $args, $instance ){
		extract( $args );

		echo $args['before_widget'];
		?>

			<div class="download-links mw-animation" data-os-animation="lightSpeedIn">
			<?php
				
				$download_btn_icon = $instance[ 'oginer_download_icon' ];
				$download_btn_url = $instance[ 'oginer_download_url' ];
				$download_btn_title = $instance[ 'oginer_download_title' ];
				
					if ( $download_btn_url != '' ) { ?>
						<a class="btn btn-icon" href="<?php echo esc_url( $download_btn_url ); ?>"><i class="fa <?php echo esc_attr( $download_btn_icon ); ?>"></i>
							<h3><?php echo esc_html( $download_btn_title ); ?></h3>
						</a>
						<?php 
					}
				
			?>
			</div>
		<?php 
		echo $args['after_widget'];
	}
	
	function update( $new_instance, $old_instance ) {

		$instance['oginer_download_icon'] = sanitize_text_field( $new_instance['oginer_download_icon'] );
		$instance['oginer_download_title'] = sanitize_text_field( $new_instance['oginer_download_title'] );
		$instance['oginer_download_url'] = esc_url_raw( $new_instance['oginer_download_url'] );

		
		return $instance;			
	}
	
	function form( $instance ) {
		?>
			<p>
				<label for="<?php echo $this->get_field_id( 'oginer_download_icon' ); ?>"><?php _e( 'Download Icon', 'oginer');?></label>
				<input class="widefat" id="<?php echo $this->get_field_id( 'oginer_download_icon' ); ?>" name="<?php echo $this->get_field_name( 'oginer_download_icon' ); ?>" type="text" value="<?php echo $instance['oginer_download_icon' ]; ?>" />
				<small><?php echo sprintf( __( 'Use font awesome icon: Eg: %1$s. %2$s See more here %3$s', 'oginer' ), 'fa-apple, fa-android, fa-windows','<a href="'.esc_url( 'https://fontawesome.com/v4.7.0/icons/' ).'" target="_blank">','</a>' ); ?></small>
			</p>
			<p>
				<label for="<?php echo $this->get_field_id( 'oginer_download_title' ); ?>"><?php _e( 'Download Title', 'oginer' );?></label>
				<input class="widefat" id="<?php echo $this->get_field_id( 'oginer_download_title' ); ?>" name="<?php echo $this->get_field_name( 'oginer_download_title' ); ?>" type="text" value="<?php echo $instance[ 'oginer_download_title' ]; ?>" />		
			</p>
			<p>
				<label for="<?php echo $this->get_field_id( 'oginer_download_url' ); ?>"><?php _e( 'Download Url', 'oginer' );?></label>
				<input class="widefat" id="<?php echo $this->get_field_id( 'oginer_download_url' ); ?>" name="<?php echo $this->get_field_name( 'oginer_download_url' ); ?>" type="text" value="<?php echo $instance[ 'oginer_download_url' ]; ?>" />		
			</p>
		<?php
	}
}

function mw_section_download(){
	register_widget( 'MW_section_download' );
}
add_action( 'widgets_init', 'mw_section_download' );