import Component from '@ember/component'; import copyTextToClipboard from 'ghost-admin/utils/copy-text-to-clipboard'; import {computed} from '@ember/object'; import {inject as service} from '@ember/service'; import {task, timeout} from 'ember-concurrency'; export default Component.extend({ config: service(), store: service(), settings: service(), tagName: '', isLink: true, prices: null, copiedPrice: null, toggleValue: computed('isLink', function () { return this.isLink ? 'Data attributes' : 'Links'; }), sectionHeaderLabel: computed('isLink', function () { return this.isLink ? 'Link' : 'Data attribute'; }), init() { this._super(...arguments); this.siteUrl = this.config.get('blogUrl'); this.getAvailablePrices.perform(); }, actions: { toggleShowLinks() { this.toggleProperty('isLink'); } }, copyStaticLink: task(function* (id) { this.set('copiedPrice', id); let data = ''; if (this.isLink) { data = id ? `#/portal/${id}` : `#/portal/`; } else { data = id ? `data-portal="${id}"` : `data-portal`; } copyTextToClipboard(data); yield timeout(this.isTesting ? 50 : 3000); }), copySignupLink: task(function* (price) { this.set('copiedPrice', price.id); let data = ''; if (this.isLink) { data = `#/portal/signup/${price.id}`; } else { data = `data-portal="signup/${price.id}"`; } copyTextToClipboard(data); yield timeout(this.isTesting ? 50 : 3000); }) });