import Controller from '@ember/controller';
import {action} from '@ember/object';
import {htmlSafe} from '@ember/template';
import {inject as service} from '@ember/service';
import {tracked} from '@glimmer/tracking';

export default class ProductsController extends Controller {
    @service settings;
    @service config;

    @tracked iconStyle = '';
    @tracked showFreeMembershipModal = false;

    constructor() {
        super(...arguments);
        this.iconStyle = this.setIconStyle();
    }

    get products() {
        return this.model.sortBy('name');
    }

    setIconStyle() {
        let icon = this.config.get('icon');
        if (icon) {
            return htmlSafe(`background-image: url(${icon})`);
        }
        icon = 'https://static.ghost.org/v4.0.0/images/ghost-orb-2.png';
        return htmlSafe(`background-image: url(${icon})`);
    }

    @action
    closeFreeMembershipModal() {
        this.showFreeMembershipModal = false;
    }
}
