<template>
  <div class="row">
    <div class="row">
      <div class="colonne4">
        <label for="ocr_server_url">
          {{ messages.get("ocr", "admin_ocr_config_server_url") }}
          <span :aria-label="messages.get('common', 'required_message')">
            {{ messages.get("common", "required_symbol") }}
          </span>
        </label>
      </div>
      <div class="colonne8">
        <input type="text" class="saisie-80em" name="ocr_server_url" id="ocr_server_url" required="" v-model.trim="values.url" />
      </div>
    </div>
    <div class="row">
      <div class="colonne4">
        <label for="ocr_server_salt">
          {{ messages.get("ocr", "admin_ocr_config_server_salt") }}
          <span :aria-label="messages.get('common', 'required_message')">
            {{ messages.get("common", "required_symbol") }}
          </span>
        </label>
      </div>
      <div class="colonne8">
        <input type="password" class="saisie-80em" name="ocr_server_salt" id="ocr_server_salt" required="" v-model.trim="values.salt" autocomplete="off" />
        <span class="fa fa-eye" onclick="toggle_password(this, 'ocr_server_salt');"></span>
      </div>
    </div>
    <div class="row">
      <div class="colonne4">
        <label for="ocr_server_token">
          {{ messages.get("ocr", "admin_ocr_config_server_token") }}
          <span :aria-label="messages.get('common', 'required_message')">
            {{ messages.get("common", "required_symbol") }}
          </span>
        </label>
      </div>
      <div class="colonne8">
        <input type="password" class="saisie-80em" name="ocr_server_token" id="ocr_server_token" required="" v-model.trim="values.token" autocomplete="off" />
        <span class="fa fa-eye" onclick="toggle_password(this, 'ocr_server_token');"></span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    config: {
      type: Object,
      default: () => ({}),
    },
  },
  data: function() {
    return {
      values: {
        url: "",
        salt: "",
        token: "",
      },
    };
  },
  mounted() {
    let update = false;
    if (this.config.url) {
      this.values.url = this.config.url;
    } else {
      update = true;
    }
    if (this.config.salt) {
      this.values.salt = this.config.salt;
    } else {
      update = true;
    }
    if (this.config.token) {
      this.values.token = this.config.token;
    } else {
      update = true;
    }

    if (update) {
      this.$emit("update:config", this.values);
    }
  },
  watch: {
    values: function (_, newConfig) {
      this.$emit("update:config", newConfig);
    }
  },
};
</script>
