<?php

class Intense_Field_Icon_Source extends Intense_Field_Dropdown {
	private function set_default_options() {
		if ( empty( $this->args['options'] ) ) {
			$this->args['options'] = array();
			$packs = Intense_Icon::get_icon_sources();

			foreach ($packs as $key => $value) {
				$this->args['options'][ $key ] = $value['title'] . ' (' . $value['count'] . ')';
			}
		}
	}

	public function render_field() {
		$this->class .= ' selectize iconsource';
		return parent::render_field();
	}

	public function render_init_script() {
		return "$('.selectize.iconsource select').not('.repeater-item-model .selectize.iconsource select').selectize({
    				sortField: 'text',    				
				});";
	}

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

		return parent::render();
	}

	public function map_visual_composer() {
		$this->set_default_options();
		
		return parent::map_visual_composer();
	}
}