<?php

class WosmPL_GeoCat_Widget extends WP_Widget {

    function __construct() {
        $widget_ops = array( 
           'description' => 'Displays geo cat.',
        );
        // Instantiate the parent object
        parent::__construct( false, 'WosmPL Geocat.',  $widget_ops);
    }

    
    function widget( $args, $instance ) {
                // Widget output
        echo $args['before_widget'];
        if ( ! empty( $instance['title'] ) ) {
            echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title'];
        }
        $with_map_link = TRUE;
        echo wosmpl_get_categories_ul('widget-list',$with_map_link);
        
        
        echo $args['after_widget'];
    }

    function update( $new_instance, $old_instance ) {
        // Save widget options
        $instance = array();
        $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
            
        
        return $instance;
    }

    function form( $instance ) {
        // Output admin widget options form
        $title = ! empty( $instance['title'] ) ? $instance['title'] : esc_html__( 'Title', 'wosmpl' );
        ?>
        <p>
        <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
        <?php esc_attr_e( 'Title:', 'wosmpl' ); ?>
        </label> 
        
        <input 
            class="widefat" 
            id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" 
            name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" 
            type="text" 
            value="<?php echo esc_attr( $title ); ?>">
        </p>
        <?php
    }
}
