(function (global) {
  global.ARQ = global.ARQ || {};
  var tool = 'lapiz';
  ARQ.tools = {
    color: '#1a1a2e',
    colorMaterialId: null,
    size: 4,
    opacity: 1,
    smooth: 4,
    wandTolerance: 48,
    wandContiguous: true,
    bucketTolerance: 48,
    bucketContiguous: true,
    cropFixedRatio: false,
    currentTool: function () { return tool; },
    setTool: function (t) {
      tool = t;
      ARQ.bus.emit(ARQ.EVENTS.TOOL_CHANGED, t);
    },
    isDrawTool: function () {
      return ['lapiz', 'pluma', 'marcador', 'pincel_suave', 'pincel_duro', 'borrador'].indexOf(tool) >= 0;
    },
    isShapeTool: function () {
      return ['rect', 'circulo', 'linea'].indexOf(tool) >= 0;
    },
    showsToleranceUi: function () {
      return ['wand', 'bote_pintura', 'marquee', 'lasso', 'crop'].indexOf(tool) >= 0;
    },
    syncFromDom: function () {
      var $tol = $('#tool-tolerance');
      if ($tol.length) {
        this.wandTolerance = parseInt($tol.val(), 10) || 0;
        this.bucketTolerance = this.wandTolerance;
      }
      var $c = $('#tool-contiguous');
      if ($c.length) {
        this.wandContiguous = $c.prop('checked');
        this.bucketContiguous = this.wandContiguous;
      }
      var $cr = $('#tool-crop-ratio');
      if ($cr.length) this.cropFixedRatio = $cr.prop('checked');
    },
  };
})(typeof window !== 'undefined' ? window : this);
