import Component from "@glimmer/component"; import { tracked } from "@glimmer/tracking"; import { fn } from "@ember/helper"; import { on } from "@ember/modifier"; import { action } from "@ember/object"; import { htmlSafe } from "@ember/template"; import DButton from "discourse/components/d-button"; import DToggleSwitch from "discourse/components/d-toggle-switch"; import DropdownMenu from "discourse/components/dropdown-menu"; import { ajax } from "discourse/lib/ajax"; import { popupAjaxError } from "discourse/lib/ajax-error"; import { SYSTEM_FLAG_IDS } from "discourse/lib/constants"; import i18n from "discourse-common/helpers/i18n"; import DMenu from "float-kit/components/d-menu"; export default class AdminFlagItem extends Component { @tracked enabled = this.args.flag.enabled; get canMove() { return this.args.flag.id !== SYSTEM_FLAG_IDS.notify_user; } @action toggleFlagEnabled(flag) { this.enabled = !this.enabled; return ajax(`/admin/config/flags/${flag.id}/toggle`, { type: "PUT", }).catch((error) => { this.enabled = !this.enabled; return popupAjaxError(error); }); } @action onRegisterApi(api) { this.dMenu = api; } @action moveUp() { this.args.moveFlagCallback(this.args.flag, "up"); this.dMenu.close(); } @action moveDown() { this.args.moveFlagCallback(this.args.flag, "down"); this.dMenu.close(); } }