{"size": 905, "ext": "js", "max_stars_repo_path": "app/controllers/publishing.js", "max_stars_repo_name": "garrison/davros", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/controllers/publishing.js", "max_issues_repo_name": "garrison/davros", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/controllers/publishing.js", "max_forks_repo_name": "garrison/davros", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.4594594595, "max_line_length": 73, "alphanum_fraction": 0.6364640884}
import { inject as service } from '@ember/service';
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';

const apexValidation = [
  {
    message: 'Apex domains (without www) will not work as well',
    validate: input => !input.match(/^\w+\.\w?\w?\w?\w?$/)
  }
];

export default class PublishingController extends Controller {
  @service publishing;
  @tracked domain = '';
  @tracked validationError = null;

  get unsavedDomainIsApex() {
    return !!this.domain;
  }

  get domainIsApex() {
    return !!(this.publishing.domain || '').match(/^\w+\.\w?\w?\w?\w?$/);
  }

  @action
  onChange(event) {
    const { value } = event.target;
    if (!apexValidation[0].validate(value)) {
      this.validationError = apexValidation[0].message;
    } else {
      this.validationError = null;
    }
    this.domain = value;
  }
}
