import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import React, { useState } from "react";
import ConfigureInterface from "../ConfigureInterface";
import AdvancedOptionsView from "../AdvancedOptionsView";
import { templateMap } from "../StartingPage/templates";
import Box from "@material-ui/core/Box";
import Tabs from "@material-ui/core/Tabs";
import Tab from "@material-ui/core/Tab";
import CategoryIcon from "@material-ui/icons/Category";
import BuildIcon from "@material-ui/icons/Build";
import LiveTvIcon from "@material-ui/icons/LiveTv";
import DeveloperBoardIcon from "@material-ui/icons/DeveloperBoard";
import CodeIcon from "@material-ui/icons/Code";
import BigInterfaceSelect from "../BigInterfaceSelect";
import UniversalSampleEditor from "../UniversalSampleEditor";
import DatasetJSONEditor from "../DatasetJSONEditor";
import useInterface from "../../hooks/use-interface";
import useSample from "../../hooks/use-sample";

var noop = function noop() {};

export default (function (_ref) {
  var onClearLabelData = _ref.onClearLabelData;

  var _useInterface = useInterface(),
      iface = _useInterface.iface,
      updateInterface = _useInterface.updateInterface;

  var _useSample = useSample(0),
      sample = _useSample.sample;

  var _useState = useState((iface === null || iface === void 0 ? void 0 : iface.type) ? "configure" : "datatype"),
      _useState2 = _slicedToArray(_useState, 2),
      currentTab = _useState2[0],
      setTab = _useState2[1];

  return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Box, {
    padding: "16px"
  }, /*#__PURE__*/React.createElement(Tabs, {
    value: currentTab,
    onChange: function onChange(e, newTab) {
      return setTab(newTab);
    }
  }, /*#__PURE__*/React.createElement(Tab, {
    icon: /*#__PURE__*/React.createElement(CategoryIcon, null),
    label: "Data Type",
    value: "datatype"
  }), /*#__PURE__*/React.createElement(Tab, {
    icon: /*#__PURE__*/React.createElement(BuildIcon, null),
    label: "Configure",
    value: "configure"
  }), /*#__PURE__*/React.createElement(Tab, {
    icon: /*#__PURE__*/React.createElement(LiveTvIcon, null),
    label: "Preview",
    value: "preview"
  }), /*#__PURE__*/React.createElement(Tab, {
    icon: /*#__PURE__*/React.createElement(CodeIcon, null),
    label: "JSON",
    value: "json"
  }), /*#__PURE__*/React.createElement(Tab, {
    icon: /*#__PURE__*/React.createElement(DeveloperBoardIcon, null),
    label: "Advanced",
    value: "advanced"
  }))), currentTab === "datatype" && /*#__PURE__*/React.createElement(BigInterfaceSelect, {
    key: "interfaceSelect",
    currentInterfaceType: iface === null || iface === void 0 ? void 0 : iface.type,
    onChange: /*#__PURE__*/function () {
      var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(newInterface) {
        return _regeneratorRuntime.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                _context.next = 2;
                return updateInterface(newInterface);

              case 2:
                setTab("configure");

              case 3:
              case "end":
                return _context.stop();
            }
          }
        }, _callee);
      }));

      return function (_x) {
        return _ref2.apply(this, arguments);
      };
    }()
  }), currentTab === "configure" && /*#__PURE__*/React.createElement(ConfigureInterface, {
    key: "configureInterface",
    interface: iface,
    onChange: updateInterface,
    isNotNested: true
  }), currentTab === "preview" && /*#__PURE__*/React.createElement(UniversalSampleEditor, {
    key: "preview",
    height: 600,
    onExit: noop,
    onModifySample: noop,
    interface: iface,
    sampleIndex: 0,
    sample: sample || templateMap[iface === null || iface === void 0 ? void 0 : iface.type].dataset.samples[0]
  }), currentTab === "advanced" && /*#__PURE__*/React.createElement(AdvancedOptionsView, {
    key: "advancedOptionsView",
    onClearLabelData: onClearLabelData
  }), currentTab === "json" && /*#__PURE__*/React.createElement(DatasetJSONEditor, null));
});