<commit_before>// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

import { createAnnoucement } from 'chat/chat-api';
import UserJson from 'interfaces/user-json';
import { route } from 'laroute';
import { debounce } from 'lodash';
import { action, computed, makeObservable, observable, runInAction } from 'mobx';
import core from 'osu-core-singleton';

export const inputKeys = ['description', 'message', 'name', 'users'] as const;
type InputKey = typeof inputKeys[number];
type Inputs = { [key in InputKey]: string };

export function isInputKey(key: string): key is InputKey {
  return (inputKeys as Readonly<string[]>).includes(key);
}

export default class CreateAnnouncement {
  @observable busy = {
    create: false,
    lookupUsers: false,
  };

  debouncedLookupUsers = debounce(action(() => this.lookupUsers()), 1000);

  @observable inputs: Inputs = {
    description: '',
    message: '',
    name: '',
    users: '',
  };
  @observable validUsers = new Map<number, UserJson>();

  private uuid = osu.uuid();
  private xhrLookupUsers?: JQuery.jqXHR<{ users: UserJson[] }>;

  @computed
  get errors() {
    return {
      description: !osu.present(this.inputs.description),
      message: !osu.present(this.inputs.message),
      name: !osu.present(this.inputs.name),
      users: this.validUsers.size === 0
        || osu.present(this.inputs.users.trim()), // implies invalid ids left
    };
  }

  @computed
  get isValid() {
    return !Object.values(this.errors).some(Boolean);
  }

  constructor() {
    makeObservable(this);
  }<commit_msg>don't need extra action for actual function call<commit_after>// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

import { createAnnoucement } from 'chat/chat-api';
import UserJson from 'interfaces/user-json';
import { route } from 'laroute';
import { debounce } from 'lodash';
import { action, computed, makeObservable, observable, runInAction } from 'mobx';
import core from 'osu-core-singleton';

export const inputKeys = ['description', 'message', 'name', 'users'] as const;
type InputKey = typeof inputKeys[number];
type Inputs = { [key in InputKey]: string };

export function isInputKey(key: string): key is InputKey {
  return (inputKeys as Readonly<string[]>).includes(key);
}

export default class CreateAnnouncement {
  @observable busy = {
    create: false,
    lookupUsers: false,
  };

  debouncedLookupUsers = debounce(() => this.lookupUsers(), 1000);

  @observable inputs: Inputs = {
    description: '',
    message: '',
    name: '',
    users: '',
  };
  @observable validUsers = new Map<number, UserJson>();

  private uuid = osu.uuid();
  private xhrLookupUsers?: JQuery.jqXHR<{ users: UserJson[] }>;

  @computed
  get errors() {
    return {
      description: !osu.present(this.inputs.description),
      message: !osu.present(this.inputs.message),
      name: !osu.present(this.inputs.name),
      users: this.validUsers.size === 0
        || osu.present(this.inputs.users.trim()), // implies invalid ids left
    };
  }

  @computed
  get isValid() {
    return !Object.values(this.errors).some(Boolean);
  }

  constructor() {
    makeObservable(this);
  }
{'fraction_non_alphanumeric': 0.13998224326723882, 'fraction_numerical': 0.004143237644273453, 'mean_word_length': 3.898550724637681, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, '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': '5040779', 'n_tokens_mistral': 1060, 'n_tokens_neox': 1027, 'n_words': 297}