var Wick = Wick || {};

Wick.fileLoader = function(id) {
  const textNoFileChoose = 'No file chosen'
  const errorFileClass = 'file-loader--error';
  const elements = {
    inputFile: $(`#${id}`),
    parentInputFile: $(`label[for="${id}"]`),
    labelFile: $(`label[for="${id}"] .file-loader__label`),
    errorLabel: $(`label[for="${id}"] + .file-loader__error`),
  }

  return {
    getElementInput() {
      return elements.inputFile
    },
    getElementLabel() {
      return elements.labelFile
    },
    clearFileLoader() {
      this.hideError();
      this.setLabelText(textNoFileChoose);
      elements.inputFile.val(null);
    },
    setLabelText(text) {
      elements.labelFile.text(text)
    },
    showError(text) {
      elements.parentInputFile.addClass(errorFileClass)
      elements.errorLabel.text(text)
    },
    hideError() {
      elements.parentInputFile.removeClass(errorFileClass)
    }
  }
}