import Component from "@glimmer/component"; import { fn } from "@ember/helper"; import { on } from "@ember/modifier"; import { action } from "@ember/object"; import { service } from "@ember/service"; import { htmlSafe } from "@ember/template"; import concatClass from "discourse/helpers/concat-class"; import routeAction from "discourse/helpers/route-action"; import icon from "discourse-common/helpers/d-icon"; import I18n from "discourse-i18n"; import PollOptionRankedChoice from "./poll-option-ranked-choice"; export default class PollOptionsComponent extends Component { @service currentUser; isChosen = (option) => { return this.args.votes.includes(option.id); }; @action sendClick(option) { this.args.sendOptionSelect(option); } @action sendRank(option, rank = 0) { this.args.sendOptionSelect(option, rank); } get rankedChoiceDropdownContent() { let rankedChoiceDropdownContent = []; rankedChoiceDropdownContent.push({ id: 0, name: I18n.t("poll.options.ranked_choice.abstain"), }); this.args.options.forEach((option, i) => { option.rank = 0; let priority = ""; if (i === 0) { priority = ` ${I18n.t("poll.options.ranked_choice.highest_priority")}`; } if (i === this.args.options.length - 1) { priority = ` ${I18n.t("poll.options.ranked_choice.lowest_priority")}`; } rankedChoiceDropdownContent.push({ id: i + 1, name: (i + 1).toString() + priority, }); }); return rankedChoiceDropdownContent; } }