/**
     * Output the metabox
     */
    public static function output($post)
    {
        $post_id = $post->ID;
        $home_club = get_post_meta($post_id, 'wpcm_home_club', true);
        $away_club = get_post_meta($post_id, 'wpcm_away_club', true);
        $separator = get_option('wpcm_match_clubs_separator');
        ?>
		
		<p>
			<label><?php 
        _e('Home', 'wp-club-manager');
        ?>
</label>
			<?php 
        wpcm_dropdown_posts(array('name' => 'wpcm_home_club', 'id' => 'wpcm_home_club', 'post_type' => 'wpcm_club', 'limit' => -1, 'show_option_none' => __('Choose club', 'wp-club-manager'), 'class' => 'chosen_select', 'echo' => false, 'selected' => $home_club));
        ?>
		</p>

		<p>
			<label><?php 
        _e('Away', 'wp-club-manager');
        ?>
</label>
			<?php 
        wpcm_dropdown_posts(array('name' => 'wpcm_away_club', 'id' => 'wpcm_away_club', 'post_type' => 'wpcm_club', 'limit' => -1, 'show_option_none' => __('Choose club', 'wp-club-manager'), 'class' => 'chosen_select', 'echo' => false, 'selected' => $away_club));
        ?>
		</p>
		<input type="hidden" name="post_title" value="" />
	<?php 
    }
    /**
     * form function.
     *
     * @see WP_Widget->form
     * @access public
     * @param array $instance
     * @return void
     */
    function form($instance)
    {
        if (!$this->settings) {
            return;
        }
        foreach ($this->settings as $key => $setting) {
            $value = isset($instance[$key]) ? $instance[$key] : $setting['std'];
            switch ($setting['type']) {
                case "text":
                    ?>
					<p>
						<label for="<?php 
                    echo $this->get_field_id($key);
                    ?>
"><?php 
                    echo $setting['label'];
                    ?>
</label>
						<input class="widefat" id="<?php 
                    echo esc_attr($this->get_field_id($key));
                    ?>
" name="<?php 
                    echo $this->get_field_name($key);
                    ?>
" type="text" value="<?php 
                    echo esc_attr($value);
                    ?>
" />
					</p>
					<?php 
                    break;
                case "number":
                    ?>
					<p>
						<label for="<?php 
                    echo $this->get_field_id($key);
                    ?>
"><?php 
                    echo $setting['label'];
                    ?>
</label>
						<input class="widefat" id="<?php 
                    echo esc_attr($this->get_field_id($key));
                    ?>
" name="<?php 
                    echo $this->get_field_name($key);
                    ?>
" type="number" step="<?php 
                    echo esc_attr($setting['step']);
                    ?>
" min="<?php 
                    echo esc_attr($setting['min']);
                    ?>
" max="<?php 
                    echo esc_attr($setting['max']);
                    ?>
" value="<?php 
                    echo esc_attr($value);
                    ?>
" />
					</p>
					<?php 
                    break;
                case "select":
                    ?>
					<p>
						<label for="<?php 
                    echo $this->get_field_id($key);
                    ?>
"><?php 
                    echo $setting['label'];
                    ?>
</label>
						<select class="widefat" id="<?php 
                    echo esc_attr($this->get_field_id($key));
                    ?>
" name="<?php 
                    echo $this->get_field_name($key);
                    ?>
">
							<?php 
                    foreach ($setting['options'] as $option_key => $option_value) {
                        ?>
								<option value="<?php 
                        echo esc_attr($option_key);
                        ?>
" <?php 
                        selected($option_key, $value);
                        ?>
><?php 
                        echo esc_html($option_value);
                        ?>
</option>
							<?php 
                    }
                    ?>
						</select>
					</p>
					<?php 
                    break;
                case "tax_select":
                    ?>
					<p><label for="<?php 
                    echo $this->get_field_id($key);
                    ?>
"><?php 
                    echo $setting['label'];
                    ?>
</label>
						<?php 
                    $args = array('show_option_none' => __('All', 'wp-club-manager'), 'hide_empty' => 0, 'orderby' => 'title', 'taxonomy' => $setting['taxonomy'], 'selected' => $value, 'name' => $this->get_field_name($key), 'id' => $this->get_field_id($key));
                    wp_dropdown_categories($args);
                    ?>
					</p>
					<?php 
                    break;
                case "pages_select":
                    ?>
					<p><label for="<?php 
                    echo $this->get_field_id($key);
                    ?>
"><?php 
                    echo $setting['label'];
                    ?>
</label>
						<?php 
                    $args = array('show_option_none' => __('None', 'wp-club-manager'), 'selected' => $value, 'name' => $this->get_field_name($key), 'id' => $this->get_field_id($key));
                    wp_dropdown_pages($args);
                    ?>
					</p>
					<?php 
                    break;
                case "posts_select":
                    ?>
					<p><label for="<?php 
                    echo $this->get_field_id($key);
                    ?>
"><?php 
                    echo $setting['label'];
                    ?>
</label>
						<?php 
                    $args = array('show_option_none' => __('None', 'wp-club-manager'), 'selected' => $value, 'name' => $this->get_field_name($key), 'id' => $this->get_field_id($key), 'post_type' => $setting['post_type'], 'orderby' => $setting['orderby'], 'order' => $setting['order'], 'limit' => $setting['limit']);
                    wpcm_dropdown_posts($args);
                    ?>
					</p>
					<?php 
                    break;
                case "checkbox":
                    ?>
					<p>
						<input id="<?php 
                    echo esc_attr($this->get_field_id($key));
                    ?>
" name="<?php 
                    echo esc_attr($this->get_field_name($key));
                    ?>
" type="checkbox" value="1" <?php 
                    checked($value, 1);
                    ?>
 />
						<label for="<?php 
                    echo $this->get_field_id($key);
                    ?>
"><?php 
                    echo $setting['label'];
                    ?>
</label>
					</p>
					<?php 
                    break;
                case "section_heading":
                    ?>
					<h4><?php 
                    echo $setting['label'];
                    ?>
</h4>
					<?php 
                    break;
            }
        }
    }
        /**
         * Output admin fields.
         *
         * Loops though the wpclubmanager options array and outputs each field.
         *
         * @access public
         * @param array $options Opens array to output
         */
        public static function output_fields($options)
        {
            foreach ($options as $value) {
                if (!isset($value['type'])) {
                    continue;
                }
                if (!isset($value['id'])) {
                    $value['id'] = '';
                }
                if (!isset($value['title'])) {
                    $value['title'] = isset($value['name']) ? $value['name'] : '';
                }
                if (!isset($value['class'])) {
                    $value['class'] = '';
                }
                if (!isset($value['css'])) {
                    $value['css'] = '';
                }
                if (!isset($value['default'])) {
                    $value['default'] = '';
                }
                if (!isset($value['desc'])) {
                    $value['desc'] = '';
                }
                if (!isset($value['desc_tip'])) {
                    $value['desc_tip'] = false;
                }
                if (!isset($value['options'])) {
                    $value['options'] = '';
                }
                // Custom attribute handling
                $custom_attributes = array();
                if (!empty($value['custom_attributes']) && is_array($value['custom_attributes'])) {
                    foreach ($value['custom_attributes'] as $attribute => $attribute_value) {
                        $custom_attributes[] = esc_attr($attribute) . '="' . esc_attr($attribute_value) . '"';
                    }
                }
                // Description handling
                if ($value['desc_tip'] === true) {
                    $description = '';
                    $tip = $value['desc'];
                } elseif (!empty($value['desc_tip'])) {
                    $description = $value['desc'];
                    $tip = $value['desc_tip'];
                } elseif (!empty($value['desc'])) {
                    $description = $value['desc'];
                    $tip = '';
                } else {
                    $description = $tip = '';
                }
                if ($description && in_array($value['type'], array('textarea', 'radio'))) {
                    $description = '<p style="margin-top:0">' . wp_kses_post($description) . '</p>';
                } elseif ($description && in_array($value['type'], array('checkbox'))) {
                    $description = wp_kses_post($description);
                } elseif ($description) {
                    $description = '<span class="description">' . wp_kses_post($description) . '</span>';
                }
                if ($tip && in_array($value['type'], array('checkbox'))) {
                    $tip = '<p class="description">' . $tip . '</p>';
                } elseif ($tip) {
                    $tip = '<img class="help_tip" data-tip="' . esc_attr($tip) . '" src="' . WPCM()->plugin_url() . '/assets/images/help.png" height="16" width="16" />';
                }
                // Switch based on type
                switch ($value['type']) {
                    // Section Titles
                    case 'title':
                        if (!empty($value['title'])) {
                            echo '<div class="stuffbox"><h3>' . esc_html($value['title']) . '</h3><div class="inside">';
                        }
                        if (!empty($value['desc'])) {
                            echo wpautop(wptexturize(wp_kses_post($value['desc'])));
                        }
                        echo '<table class="form-table">' . "\n\n";
                        if (!empty($value['id'])) {
                            do_action('wpclubmanager_settings_' . sanitize_title($value['id']));
                        }
                        break;
                        // Section Ends
                    // Section Ends
                    case 'sectionend':
                        if (!empty($value['id'])) {
                            do_action('wpclubmanager_settings_' . sanitize_title($value['id']) . '_end');
                        }
                        echo '</table></div></div>';
                        if (!empty($value['id'])) {
                            do_action('wpclubmanager_settings_' . sanitize_title($value['id']) . '_after');
                        }
                        break;
                        // Standard text inputs and subtypes like 'number'
                    // Standard text inputs and subtypes like 'number'
                    case 'text':
                    case 'email':
                    case 'number':
                    case 'color':
                    case 'password':
                        $type = $value['type'];
                        $class = '';
                        $option_value = self::get_option($value['id'], $value['default']);
                        ?>

	            	<tr>
						<th scope="row" class="titledesc">
							<label for="<?php 
                        echo esc_attr($value['id']);
                        ?>
"><?php 
                        echo esc_html($value['title']);
                        ?>
</label>
							<?php 
                        echo $tip;
                        ?>
						</th>
	                    <td class="forminp forminp-<?php 
                        echo sanitize_title($value['type']);
                        ?>
">
	                    	<input
	                    		name="<?php 
                        echo esc_attr($value['id']);
                        ?>
"
	                    		id="<?php 
                        echo esc_attr($value['id']);
                        ?>
"
	                    		type="<?php 
                        echo esc_attr($type);
                        ?>
"
	                    		style="<?php 
                        echo esc_attr($value['css']);
                        ?>
"
	                    		value="<?php 
                        echo esc_attr($option_value);
                        ?>
"
	                    		class="<?php 
                        echo esc_attr($value['class']);
                        ?>
"
	                    		<?php 
                        echo implode(' ', $custom_attributes);
                        ?>
	                    		/> <?php 
                        echo $description;
                        ?>
	                    </td>
	                </tr><?php 
                        break;
                        // Textarea
                    // Textarea
                    case 'textarea':
                        $option_value = self::get_option($value['id'], $value['default']);
                        ?>
<tr>
						<th scope="row" class="titledesc">
							<label for="<?php 
                        echo esc_attr($value['id']);
                        ?>
"><?php 
                        echo esc_html($value['title']);
                        ?>
</label>
							<?php 
                        echo $tip;
                        ?>
						</th>
	                    <td class="forminp forminp-<?php 
                        echo sanitize_title($value['type']);
                        ?>
">
	                    	<?php 
                        echo $description;
                        ?>

	                        <textarea
	                        	name="<?php 
                        echo esc_attr($value['id']);
                        ?>
"
	                        	id="<?php 
                        echo esc_attr($value['id']);
                        ?>
"
	                        	style="<?php 
                        echo esc_attr($value['css']);
                        ?>
"
	                        	class="<?php 
                        echo esc_attr($value['class']);
                        ?>
"
	                        	<?php 
                        echo implode(' ', $custom_attributes);
                        ?>
	                        	><?php 
                        echo esc_textarea($option_value);
                        ?>
</textarea>
	                    </td>
	                </tr><?php 
                        break;
                        // Select boxes
                    // Select boxes
                    case 'select':
                    case 'multiselect':
                        $option_value = self::get_option($value['id'], $value['default']);
                        ?>
<tr>
						<th scope="row" class="titledesc">
							<label for="<?php 
                        echo esc_attr($value['id']);
                        ?>
"><?php 
                        echo esc_html($value['title']);
                        ?>
 <?php 
                        echo $tip;
                        ?>
</label>
							
						</th>
	                    <td class="forminp forminp-<?php 
                        echo sanitize_title($value['type']);
                        ?>
">
	                    	<select
	                    		name="<?php 
                        echo esc_attr($value['id']);
                        if ($value['type'] == 'multiselect') {
                            echo '[]';
                        }
                        ?>
"
	                    		id="<?php 
                        echo esc_attr($value['id']);
                        ?>
"
	                    		style="<?php 
                        echo esc_attr($value['css']);
                        ?>
"
	                    		class="<?php 
                        echo esc_attr($value['class']);
                        ?>
"
	                    		<?php 
                        echo implode(' ', $custom_attributes);
                        ?>
	                    		<?php 
                        if ($value['type'] == 'multiselect') {
                            echo 'multiple="multiple"';
                        }
                        ?>
	                    		>
		                    	<?php 
                        foreach ($value['options'] as $key => $val) {
                            ?>
			                        	<option value="<?php 
                            echo esc_attr($key);
                            ?>
" <?php 
                            if (is_array($option_value)) {
                                selected(in_array($key, $option_value), true);
                            } else {
                                selected($option_value, $key);
                            }
                            ?>
><?php 
                            echo $val;
                            ?>
</option>
			                        	<?php 
                        }
                        ?>
	                       </select> <?php 
                        echo $description;
                        ?>
	                    </td>
	                </tr><?php 
                        break;
                        // Radio inputs
                    // Radio inputs
                    case 'radio':
                        $option_value = self::get_option($value['id'], $value['default']);
                        ?>
<tr>
						<th scope="row" class="titledesc">
							<label for="<?php 
                        echo esc_attr($value['id']);
                        ?>
"><?php 
                        echo esc_html($value['title']);
                        ?>
</label>
							<?php 
                        echo $tip;
                        ?>
						</th>
	                    <td class="forminp forminp-<?php 
                        echo sanitize_title($value['type']);
                        ?>
">
	                    	<fieldset>
	                    		<?php 
                        echo $description;
                        ?>
	                    		<ul>
	                    		<?php 
                        foreach ($value['options'] as $key => $val) {
                            ?>
			                        	<li>
			                        		<label><input
				                        		name="<?php 
                            echo esc_attr($value['id']);
                            ?>
"
				                        		value="<?php 
                            echo $key;
                            ?>
"
				                        		type="radio"
					                    		style="<?php 
                            echo esc_attr($value['css']);
                            ?>
"
					                    		class="<?php 
                            echo esc_attr($value['class']);
                            ?>
"
					                    		<?php 
                            echo implode(' ', $custom_attributes);
                            ?>
					                    		<?php 
                            checked($key, $option_value);
                            ?>
				                        		/> <?php 
                            echo $val;
                            ?>
</label>
			                        	</li>
			                        	<?php 
                        }
                        ?>
	                    		</ul>
	                    	</fieldset>
	                    </td>
	                </tr>
	                <?php 
                        break;
                        // Checkbox input
                    // Checkbox input
                    case 'checkbox':
                        $option_value = self::get_option($value['id'], $value['default']);
                        $visbility_class = array();
                        if (!isset($value['hide_if_checked'])) {
                            $value['hide_if_checked'] = false;
                        }
                        if (!isset($value['show_if_checked'])) {
                            $value['show_if_checked'] = false;
                        }
                        if ($value['hide_if_checked'] == 'yes' || $value['show_if_checked'] == 'yes') {
                            $visbility_class[] = 'hidden_option';
                        }
                        if ($value['hide_if_checked'] == 'option') {
                            $visbility_class[] = 'hide_options_if_checked';
                        }
                        if ($value['show_if_checked'] == 'option') {
                            $visbility_class[] = 'show_options_if_checked';
                        }
                        if (!isset($value['checkboxgroup']) || 'start' == $value['checkboxgroup']) {
                            ?>
		            		<tr class="<?php 
                            echo esc_attr(implode(' ', $visbility_class));
                            ?>
">
								<th scope="row" class="titledesc"><?php 
                            echo esc_html($value['title']);
                            ?>
</th>
								<td class="forminp forminp-checkbox">
									<fieldset>
						<?php 
                        } else {
                            ?>
		            		<fieldset class="<?php 
                            echo esc_attr(implode(' ', $visbility_class));
                            ?>
">
	            		<?php 
                        }
                        if (!empty($value['title'])) {
                            ?>
	            			<legend class="screen-reader-text"><span><?php 
                            echo esc_html($value['title']);
                            ?>
</span></legend>
	            		<?php 
                        }
                        ?>
						<label for="<?php 
                        echo $value['id'];
                        ?>
">
							<input
								name="<?php 
                        echo esc_attr($value['id']);
                        ?>
"
								id="<?php 
                        echo esc_attr($value['id']);
                        ?>
"
								type="checkbox"
								value="1"
								<?php 
                        checked($option_value, 'yes');
                        ?>
								<?php 
                        echo implode(' ', $custom_attributes);
                        ?>
							/> <?php 
                        echo $description;
                        ?>
						</label> <?php 
                        echo $tip;
                        ?>
					<?php 
                        if (!isset($value['checkboxgroup']) || 'end' == $value['checkboxgroup']) {
                            ?>
									</fieldset>
								</td>
							</tr>
						<?php 
                        } else {
                            ?>
							</fieldset>
						<?php 
                        }
                        break;
                        // Image width settings
                    // Image width settings
                    case 'image_width':
                        $width = self::get_option($value['id'] . '[width]', $value['default']['width']);
                        $height = self::get_option($value['id'] . '[height]', $value['default']['height']);
                        $crop = checked(1, self::get_option($value['id'] . '[crop]', $value['default']['crop']), false);
                        ?>
<tr>
						<th scope="row" class="titledesc"><?php 
                        echo esc_html($value['title']);
                        ?>
 <?php 
                        echo $tip;
                        ?>
</th>
	                    <td class="forminp image_width_settings">

	                    	<input name="<?php 
                        echo esc_attr($value['id']);
                        ?>
[width]" id="<?php 
                        echo esc_attr($value['id']);
                        ?>
-width" type="text" size="3" value="<?php 
                        echo $width;
                        ?>
" /> &times; <input name="<?php 
                        echo esc_attr($value['id']);
                        ?>
[height]" id="<?php 
                        echo esc_attr($value['id']);
                        ?>
-height" type="text" size="3" value="<?php 
                        echo $height;
                        ?>
" />px

	                    	<label><input name="<?php 
                        echo esc_attr($value['id']);
                        ?>
[crop]" id="<?php 
                        echo esc_attr($value['id']);
                        ?>
-crop" type="checkbox" <?php 
                        echo $crop;
                        ?>
 /> <?php 
                        _e('Hard Crop?', 'wp-club-manager');
                        ?>
</label>

	                    	</td>
	                </tr><?php 
                        break;
                        // Single page selects
                    // Single page selects
                    case 'default_club':
                        $args = array('name' => $value['id'], 'id' => $value['id'], 'post_type' => 'wpcm_club', 'limit' => -1, 'show_option_none' => __('None'), 'class' => $value['class'], 'echo' => false, 'selected' => absint(self::get_option($value['id'])));
                        if (isset($value['args'])) {
                            $args = wp_parse_args($value['args'], $args);
                        }
                        ?>
<tr>
	                    <th scope="row" class="titledesc"><label for="<?php 
                        echo esc_attr($value['id']);
                        ?>
"><?php 
                        echo esc_html($value['title']);
                        ?>
 <?php 
                        echo $tip;
                        ?>
</label></th>
	                    <td class="forminp">
				        	<?php 
                        wpcm_dropdown_posts($args);
                        ?>
 <?php 
                        echo $description;
                        ?>
				        </td>
	               	</tr><?php 
                        break;
                        // Single page selects
                    // Single page selects
                    case 'single_select_page':
                        $args = array('name' => $value['id'], 'id' => $value['id'], 'sort_column' => 'menu_order', 'sort_order' => 'ASC', 'show_option_none' => ' ', 'class' => $value['class'], 'echo' => false, 'selected' => absint(self::get_option($value['id'])));
                        if (isset($value['args'])) {
                            $args = wp_parse_args($value['args'], $args);
                        }
                        ?>
<tr class="single_select_page">
	                    <th scope="row" class="titledesc"><?php 
                        echo esc_html($value['title']);
                        ?>
 <?php 
                        echo $tip;
                        ?>
</th>
	                    <td class="forminp">
				        	<?php 
                        echo str_replace(' id=', " data-placeholder='" . __('Select a page&hellip;', 'wp-club-manager') . "' style='" . $value['css'] . "' class='" . $value['class'] . "' id=", wp_dropdown_pages($args));
                        ?>
 <?php 
                        echo $description;
                        ?>
				        </td>
	               	</tr><?php 
                        break;
                        // Single country selects
                    // Single country selects
                    case 'single_select_country':
                        $country_setting = (string) self::get_option($value['id']);
                        $countries = WPCM()->countries->countries;
                        if (strstr($country_setting, ':')) {
                            $country_setting = explode(':', $country_setting);
                            $country = current($country_setting);
                        } else {
                            $country = $country_setting;
                        }
                        ?>
<tr>
						<th scope="row" class="titledesc">
							<label for="<?php 
                        echo esc_attr($value['id']);
                        ?>
"><?php 
                        echo esc_html($value['title']);
                        ?>
</label>
							<?php 
                        echo $tip;
                        ?>
						</th>
	                    <td class="forminp"><select name="<?php 
                        echo esc_attr($value['id']);
                        ?>
" style="<?php 
                        echo esc_attr($value['css']);
                        ?>
" data-placeholder="<?php 
                        _e('Choose a country&hellip;', 'wp-club-manager');
                        ?>
" title="Country" class="chosen_select">
				        	<?php 
                        WPCM()->countries->country_dropdown_options($country);
                        ?>
				        </select> <?php 
                        echo $description;
                        ?>
	               		</td>
	               	</tr><?php 
                        break;
                    case 'license_key':
                        $option_value = self::get_option($value['id'], $value['default']);
                        ?>

					<div class="wpcm-license-keys">
						<label for="<?php 
                        echo esc_attr($value['id']);
                        ?>
"><?php 
                        echo esc_html($value['title']);
                        ?>
</label>
	                    <input name="<?php 
                        echo esc_attr($value['id']);
                        ?>
" id="<?php 
                        echo esc_attr($value['id']);
                        ?>
" value="<?php 
                        echo esc_attr($option_value);
                        ?>
"
	                    		class="regular-text" />
                    	<?php 
                        if ('valid' == get_option($value['options']['is_valid_license_option'])) {
                            ?>
							<input type="submit" class="button-secondary" name="<?php 
                            echo esc_attr($value['id']);
                            ?>
_deactivate" value="<?php 
                            _e('Deactivate License', 'wp-club-manager');
                            ?>
"/>
						<?php 
                        }
                        ?>
	                </div><?php 
                        wp_nonce_field($value['id'] . '-nonce', $value['id'] . '-nonce');
                        break;
                        // Default: run an action
                    // Default: run an action
                    default:
                        do_action('wpclubmanager_admin_field_' . $value['type'], $value);
                        break;
                }
            }
        }