<commit_before>import EmberObject, {action} from '@ember/object';
import ModalBase from 'ghost-admin/components/modal-base';
import ProductBenefitItem from '../models/product-benefit-item';
import classic from 'ember-classic-decorator';
import {currencies, getCurrencyOptions, getSymbol} from 'ghost-admin/utils/currency';
import {A as emberA} from '@ember/array';
import {isEmpty} from '@ember/utils';
import {inject as service} from '@ember/service';
import {task} from 'ember-concurrency-decorators';
import {tracked} from '@glimmer/tracking';

const CURRENCIES = currencies.map((currency) => {
    return {
        value: currency.isoCode.toLowerCase(),
        label: `${currency.isoCode} - ${currency.name}`,
        isoCode: currency.isoCode
    };
});

// TODO: update modals to work fully with Glimmer components
@classic
export default class ModalProductPrice extends ModalBase {
    @service settings;
    @tracked model;
    @tracked product;
    @tracked periodVal;
    @tracked stripeMonthlyAmount = 5;
    @tracked stripeYearlyAmount = 50;
    @tracked currency = 'usd';
    @tracked errors = EmberObject.create();
    @tracked stripePlanError = '';
    @tracked benefits = emberA([]);
    @tracked newBenefit = null;

    confirm() {}

    get isFreeProduct() {
        return this.product.type === 'free';
    }

    get allCurrencies() {
        return getCurrencyOptions();
    }

    get productCurrency() {
        if (this.isFreeProduct) {
            const firstPaidProduct = this.model.products?.find((product) => {
                return product.type === 'paid';
            });
            return firstPaidProduct?.monthlyPrice?.currency || 'usd';
        } else {
            return this.product?.monthlyPrice?.currency;
        }
    }

    get selectedCurrency() {
        return CURRENCIES.findBy('value', this.currency);
    }

    init() {
        super.init(...arguments);
        this.product = this.model.product;
        const monthlyPrice = this.product.get('monthlyPrice');
        const yearlyPrice = this.product.get('yearlyPrice');
        if (monthlyPrice) {
            this.stripeMonthlyAmount = (monthlyPrice.amount / 100);
        }
        if (yearlyPrice) {
            this.stripeYearlyAmount = (yearlyPrice.amount / 100);
        }
        this.currency = this.productCurrency;
        this.benefits = this.product.get('benefits') || emberA([]);
        this.newBenefit = ProductBenefitItem.create({
            isNew: true,
            name: ''
        });
    }

    get title() {
        if (this.isExistingProduct) {
            if (this.isFreeProduct) {
                return `Edit free membership`;
            }
            return `Edit tier`;
        }
        return 'New tier';
    }<commit_msg>Fixed default currency for new tier creation<commit_after>import EmberObject, {action} from '@ember/object';
import ModalBase from 'ghost-admin/components/modal-base';
import ProductBenefitItem from '../models/product-benefit-item';
import classic from 'ember-classic-decorator';
import {currencies, getCurrencyOptions, getSymbol} from 'ghost-admin/utils/currency';
import {A as emberA} from '@ember/array';
import {isEmpty} from '@ember/utils';
import {inject as service} from '@ember/service';
import {task} from 'ember-concurrency-decorators';
import {tracked} from '@glimmer/tracking';

const CURRENCIES = currencies.map((currency) => {
    return {
        value: currency.isoCode.toLowerCase(),
        label: `${currency.isoCode} - ${currency.name}`,
        isoCode: currency.isoCode
    };
});

// TODO: update modals to work fully with Glimmer components
@classic
export default class ModalProductPrice extends ModalBase {
    @service settings;
    @tracked model;
    @tracked product;
    @tracked periodVal;
    @tracked stripeMonthlyAmount = 5;
    @tracked stripeYearlyAmount = 50;
    @tracked currency = 'usd';
    @tracked errors = EmberObject.create();
    @tracked stripePlanError = '';
    @tracked benefits = emberA([]);
    @tracked newBenefit = null;

    confirm() {}

    get isFreeProduct() {
        return this.product.type === 'free';
    }

    get allCurrencies() {
        return getCurrencyOptions();
    }

    get productCurrency() {
        if (this.isFreeProduct) {
            const firstPaidProduct = this.model.products?.find((product) => {
                return product.type === 'paid';
            });
            return firstPaidProduct?.monthlyPrice?.currency || 'usd';
        } else {
            return this.product?.monthlyPrice?.currency;
        }
    }

    get selectedCurrency() {
        return CURRENCIES.findBy('value', this.currency);
    }

    init() {
        super.init(...arguments);
        this.product = this.model.product;
        const monthlyPrice = this.product.get('monthlyPrice');
        const yearlyPrice = this.product.get('yearlyPrice');
        if (monthlyPrice) {
            this.stripeMonthlyAmount = (monthlyPrice.amount / 100);
        }
        if (yearlyPrice) {
            this.stripeYearlyAmount = (yearlyPrice.amount / 100);
        }
        this.currency = this.productCurrency || 'usd';
        this.benefits = this.product.get('benefits') || emberA([]);
        this.newBenefit = ProductBenefitItem.create({
            isNew: true,
            name: ''
        });
    }

    get title() {
        if (this.isExistingProduct) {
            if (this.isFreeProduct) {
                return `Edit free membership`;
            }
            return `Edit tier`;
        }
        return 'New tier';
    }
{'fraction_non_alphanumeric': 0.1260806916426513, 'fraction_numerical': 0.0032420749279538905, 'mean_word_length': 2.5346912794398473, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7578659', 'n_tokens_mistral': 1647, 'n_tokens_neox': 1597, 'n_words': 365}