import macro from 'vtk.js/Sources/macro';

// ----------------------------------------------------------------------------
// vtkTexture methods
// ----------------------------------------------------------------------------

function vtkTexture(publicAPI, model) {
  // Set our className
  model.classHierarchy.push('vtkTexture');

  publicAPI.imageLoaded = () => {
    model.image.removeEventListener('load', publicAPI.imageLoaded);
    model.imageLoaded = true;
    publicAPI.modified();
  };

  publicAPI.setImage = (image) => {
    if (model.image === image) {
      return;
    }

    if (image !== null) {
      publicAPI.setInputData(null);
      publicAPI.setInputConnection(null);
    }

    model.image = image;
    model.imageLoaded = false;

    if (image.complete) {
      publicAPI.imageLoaded();
    } else {
      image.addEventListener('load', publicAPI.imageLoaded);
    }

    publicAPI.modified();
  };

  publicAPI.getViewSpecificProperties = (() => model.viewSpecificProperties);
}

// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------

const DEFAULT_VALUES = {
  repeat: false,
  interpolate: false,
  edgeClamp: false,
  image: null,
  imageLoaded: false,
  viewSpecificProperties: null,
};

// ----------------------------------------------------------------------------

export function extend(publicAPI, model, initialValues = {}) {
  Object.assign(model, DEFAULT_VALUES, initialValues);

  // Build VTK API
  macro.obj(publicAPI, model);
  macro.algo(publicAPI, model, 1, 0);

  macro.get(publicAPI, model, [
    'imageLoaded',
  ]);

  macro.setGet(publicAPI, model, [
    'repeat',
    'edgeClamp',
    'interpolate',
    'image',
  ]);

  model.viewSpecificProperties = {};

  vtkTexture(publicAPI, model);
}

// ----------------------------------------------------------------------------

export const newInstance = macro.newInstance(extend, 'vtkTexture');

// ----------------------------------------------------------------------------

export default { newInstance, extend };

@@ -920,87 +920,8 @@
   %7D;
-%0A%0A  publicAPI.getViewSpecificProperties = (() =%3E model.viewSpecificProperties);
 %0A%7D%0A%0A
@@ -1703,21 +1703,92 @@
 age',%0A  
-%5D);%0A%0A
+  'viewSpecificProperties',%0A  %5D);%0A%0A  if (!model.viewSpecificProperties) %7B%0A  
   model.
@@ -1815,16 +1815,20 @@
 es = %7B%7D;
+%0A  %7D
 %0A%0A  vtkT

Clean code: use getter and setter macro and check viewSpecificProperties into constr