import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import React, { useMemo } from "react";
import Survey from "material-survey/components/Survey";
var maxClusterPresets = {
  low: 1000,
  medium: 8000,
  high: 64000
};
var maxClusterPresetsRev = Object.entries(maxClusterPresets).reduce(function (acc, curr) {
  acc[curr[1]] = curr[0];
  return acc;
}, {});
var form = {
  questions: [{
    name: "labels",
    title: "Available Labels",
    description: "If you're labeling regions on an image, these are the allowed classifications or tags.",
    type: "matrixdynamic",
    columns: [{
      cellType: "text",
      name: "id",
      title: "id"
    }, {
      cellType: "text",
      name: "description",
      title: "Description (optional)"
    }]
  }, {
    name: "description",
    title: "Sidebar Description",
    description: "Any instructions or notes in markdown.",
    type: "text"
  }, {
    name: "autosegMode",
    type: "dropdown",
    title: "Automatic Segmentation Engine",
    choices: ["simple", "autoseg"]
  }, {
    name: "autosegPreset",
    type: "dropdown",
    visibleIf: "{autosegMode}='autoseg'",
    title: "Super Pixel Quality",
    choices: ["low", "medium", "high", "custom"]
  }, {
    name: "autosegMaxClusters",
    type: "slider",
    visibleIf: "{autosegPreset}='custom'",
    title: "Total Super Pixels",
    min: 10,
    max: 100000,
    step: 10,
    defaultValue: 1000
  }]
};
export default (function (_ref) {
  var iface = _ref.iface,
      onChange = _ref.onChange;
  var defaultAnswers = useMemo(function () {
    var _iface$autoSegmentati, _iface$autoSegmentati2, _iface$autoSegmentati3;

    return {
      description: iface.description,
      labels: (iface.labels || []).map(function (a) {
        return typeof a === "string" ? {
          id: a,
          description: a
        } : a;
      }) || [],
      autosegMode: (_iface$autoSegmentati = iface.autoSegmentationEngine) === null || _iface$autoSegmentati === void 0 ? void 0 : _iface$autoSegmentati.mode,
      autosegPreset: maxClusterPresetsRev[((_iface$autoSegmentati2 = iface.autoSegmentationEngine) === null || _iface$autoSegmentati2 === void 0 ? void 0 : _iface$autoSegmentati2.maxClusters) || 1000] || "custom",
      autosegMaxClusters: ((_iface$autoSegmentati3 = iface.autoSegmentationEngine) === null || _iface$autoSegmentati3 === void 0 ? void 0 : _iface$autoSegmentati3.maxClusters) || 1000
    };
  }, [iface]);
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Survey, {
    noActions: true,
    variant: "flat",
    defaultAnswers: defaultAnswers,
    onQuestionChange: function onQuestionChange(questionId, newValue, answers) {
      onChange(_objectSpread(_objectSpread({}, iface), {}, {
        description: answers.description,
        labels: answers.labels,
        autoSegmentationEngine: {
          mode: answers.autosegMode,
          maxClusters: answers.autosegPreset === "custom" ? answers.autosegMaxClusters : maxClusterPresets[answers.autosegPreset]
        }
      }));
    },
    form: form
  }));
});