{"size": 801, "ext": "js", "max_stars_repo_path": "addon/components/input-stars.js", "max_stars_repo_name": "collectiveidea/ember-helpers", "max_stars_repo_stars_event_min_datetime": "2022-01-05T19:15:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T19:15:16.000Z", "max_issues_repo_path": "addon/components/input-stars.js", "max_issues_repo_name": "collectiveidea/ember-helpers", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "addon/components/input-stars.js", "max_forks_repo_name": "collectiveidea/ember-helpers", "max_forks_repo_forks_event_min_datetime": "2020-12-13T11:58:14.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-13T11:58:14.000Z"}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 15.7058823529, "max_line_length": 64, "alphanum_fraction": 0.5892634207}
import Component from '@ember/component';
import { computed } from '@ember/object';
import { typeOf } from '@ember/utils';
import layout from '../templates/components/input-stars';

export default Component.extend({

	layout,

	min: 1,

	max: 5,

	value: 0,

	colour: '#444',

	disabled: false,

	tagName: 'input-stars',

	stars: computed('min', 'max', function() {
		let b = this.get('min');
		let e = this.get('max');
		return Array.apply(null, Array(e-b+1)).map( (_, n) => n + b );
	}),

	actions: {

		toggle(value) {

			if (this.disabled) return;

			if (this.get('value') === value) {
				this.decrementProperty('value');
			} else {
				this.set('value', value);
			}

			let func = this.get('on-change');

			if (typeOf(func) === 'function') {
				func(this.get('value'));
			}

		}

	}

});
