<?php

class Intense_Field_Font_Family extends Intense_Field_Dropdown {
	private function set_default_options() {

	}

	protected function render() {
		$this->set_default_options();		

		$google_fonts = include INTENSE_PLUGIN_FOLDER . '/inc/plugins/ReduxFramework/ReduxCore/inc/fields/typography/googlefonts.php';
		$google_fonts = array_combine( array_keys( $google_fonts ), array_keys( $google_fonts ) );
		$standard_fonts = array(
            "Arial, Helvetica, sans-serif"                         => "Arial, Helvetica, sans-serif",
            "'Arial Black', Gadget, sans-serif"                    => "'Arial Black', Gadget, sans-serif",
            "'Bookman Old Style', serif"                           => "'Bookman Old Style', serif",
            "'Comic Sans MS', cursive"                             => "'Comic Sans MS', cursive",
            "Courier, monospace"                                   => "Courier, monospace",
            "Garamond, serif"                                      => "Garamond, serif",
            "Georgia, serif"                                       => "Georgia, serif",
            "Impact, Charcoal, sans-serif"                         => "Impact, Charcoal, sans-serif",
            "'Lucida Console', Monaco, monospace"                  => "'Lucida Console', Monaco, monospace",
            "'Lucida Sans Unicode', 'Lucida Grande', sans-serif"   => "'Lucida Sans Unicode', 'Lucida Grande', sans-serif",
            "'MS Sans Serif', Geneva, sans-serif"                  => "'MS Sans Serif', Geneva, sans-serif",
            "'MS Serif', 'New York', sans-serif"                   => "'MS Serif', 'New York', sans-serif",
            "'Palatino Linotype', 'Book Antiqua', Palatino, serif" => "'Palatino Linotype', 'Book Antiqua', Palatino, serif",
            "Tahoma,Geneva, sans-serif"                            => "Tahoma, Geneva, sans-serif",
            "'Times New Roman', Times,serif"                       => "'Times New Roman', Times, serif",
            "'Trebuchet MS', Helvetica, sans-serif"                => "'Trebuchet MS', Helvetica, sans-serif",
            "Verdana, Geneva, sans-serif"                          => "Verdana, Geneva, sans-serif",
        );

		$fonts = array(
			'Standard' => $standard_fonts,
			'Google' => $google_fonts
		);

		$output = '<select class="selectize font_family" name="' . $this->id . '" id="' . $this->id . '">';
		$output .= '<option></option>';

		foreach ( $fonts as $key => $value ) {
			$output .= '<optgroup label="' . $key . '">';

			foreach ( $value as $font => $description) {
				$output .= '<option value="google|' . esc_attr( $font ) . '">' . esc_html( $description ) . '</option>';
			}

			$output .= '</optgroup>';
		}

		$output .= '</select>';

		$output .= $this->description;

		return $output;
	}

	public function render_init_script() {
		return "$('.selectize.font_family').not('.repeater-item-model .selectize.font_family').selectize({
    				sortField: 'text',
    				create: true,
    				onChange: function(value) {
						intenseRefreshPreview();
					}
				});";
	}

	public function map_visual_composer() {
		// $this->set_default_options();

		// return parent::map_visual_composer();
		return null;
	}
}
