2021-07-20 12:48:12 +03:00
|
|
|
import Helper from '@ember/component/helper';
|
|
|
|
import {get} from '@ember/object';
|
2021-11-16 15:14:21 +03:00
|
|
|
import {isArray} from '@ember/array';
|
2021-07-20 12:48:12 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
|
|
|
|
export default class CardIsAvailableHelper extends Helper {
|
|
|
|
@service config;
|
|
|
|
@service feature;
|
2021-11-15 19:38:57 +03:00
|
|
|
@service settings;
|
2021-07-20 12:48:12 +03:00
|
|
|
|
2021-09-10 11:24:38 +03:00
|
|
|
compute([card], {postType} = {}) {
|
2021-07-20 12:48:12 +03:00
|
|
|
let cardIsAvailable = true;
|
|
|
|
|
2021-11-15 19:38:57 +03:00
|
|
|
if (typeof card.isAvailable === 'string') {
|
|
|
|
cardIsAvailable = get(this, card.isAvailable);
|
|
|
|
}
|
|
|
|
|
2021-11-16 15:14:21 +03:00
|
|
|
if (isArray(card.isAvailable)) {
|
|
|
|
cardIsAvailable = card.isAvailable.every((key) => {
|
|
|
|
return get(this, key);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-07-20 12:48:12 +03:00
|
|
|
if (card.developerExperiment) {
|
2022-10-07 17:24:03 +03:00
|
|
|
cardIsAvailable = cardIsAvailable && this.config.enableDeveloperExperiments;
|
2021-07-20 12:48:12 +03:00
|
|
|
}
|
|
|
|
|
2021-09-10 11:24:38 +03:00
|
|
|
if (postType && card.postType) {
|
2021-11-15 19:38:57 +03:00
|
|
|
cardIsAvailable = cardIsAvailable && card.postType === postType;
|
2021-09-10 11:24:38 +03:00
|
|
|
}
|
|
|
|
|
2021-07-20 12:48:12 +03:00
|
|
|
return cardIsAvailable;
|
|
|
|
}
|
|
|
|
}
|