"use strict";

exports.__esModule = true;
exports.default = exports.ScopeLabel = exports.ScopeIcon = void 0;
var _react = _interopRequireDefault(require("react"));
var _TreeItem = _interopRequireDefault(require("@material-ui/lab/TreeItem"));
var _Icon = _interopRequireDefault(require("./../DataDisplay/Icon"));
var _styles = require("@material-ui/core/styles");
var _styles2 = require("@material-ui/styles");
var _MultipleLinesText = _interopRequireDefault(require("./../DataDisplay/TooltippedElements/MultipleLinesText"));
var _textProps = _interopRequireDefault(require("./../textProps"));
var _classnames = _interopRequireDefault(require("classnames"));
var _constants = require("./../../../constants");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();
(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};
var useStyles = (0, _styles.makeStyles)(function (theme) {
  return {
    group: {
      marginLeft: function marginLeft(props) {
        return props.isRootScope ? theme.spacing(1.2) : theme.spacing(3.2);
      }
      // to hide unnecessary border part
      // "& > div > div > :last-child": {
      //   "&:after": {
      //     content: "''",
      //     backgroundColor: theme.palette.grey.light,
      //     position: "absolute",
      //     top: theme.spacing(1.2),
      //     left: theme.spacing(-2.1),
      //     height: "100%",
      //     bottom: 0,
      //     width: "1px",
      //   },
      // }
    },
    rootIconContainer: {
      marginRight: 0,
      display: "none"
    },
    scopeLabel: {
      position: "relative",
      display: "flex",
      alignItems: "center"
    },
    scopeLabelInactive: {
      color: theme.palette.secondary.light
    },
    scopeIcon: {
      marginRight: theme.spacing(0.7),
      height: theme.spacing(2.4),
      width: theme.spacing(2.4)
    },
    horizontalLine: {
      position: "absolute",
      left: function left(props) {
        return props.hasChildren ? theme.spacing(-4.1) : theme.spacing(-3);
      },
      width: function width(props) {
        return props.hasChildren ? theme.spacing(1.5) : theme.spacing(2.5);
      },
      height: "1px",
      backgroundColor: theme.palette.grey.icon
    },
    regularScopeName: {
      fontSize: theme.typography.htmlFontSize,
      fontFamily: theme.typography.fontFamily,
      fontWeight: theme.typography.fontWeightSemiBold
    },
    virtualScopeName: {
      fontWeight: theme.typography.fontWeightRegular
    },
    virtualScopeContent: {
      "& > .MuiTreeItem-label": {
        cursor: "auto",
        "&:hover,&:focus": {
          backgroundColor: "transparent"
        }
      }
    },
    virtualScopeSelected: {
      "& > .MuiTreeItem-content .MuiTreeItem-label": {
        border: "none",
        backgroundColor: "transparent !important"
      }
    }
  };
});
var ScopeIcon = exports.ScopeIcon = function ScopeIcon(_ref) {
  var type = _ref.type;
  var classes = useStyles();
  var theme = (0, _styles2.useTheme)();
  var globalIcon = /*#__PURE__*/_react.default.createElement(_Icon.default, {
    className: classes.scopeIcon,
    color: "primary",
    fontSize: "medium",
    id: "global-scope"
  });
  var virtualIcon = /*#__PURE__*/_react.default.createElement(_Icon.default, {
    className: classes.scopeIcon,
    themeColor: theme.palette.grey.dark,
    fontSize: "medium",
    id: "virtual-scope"
  });
  var salesIcon = /*#__PURE__*/_react.default.createElement(_Icon.default, {
    className: classes.scopeIcon,
    color: "primary",
    fontSize: "medium",
    id: "sales-scope"
  });
  var dependentIcon = /*#__PURE__*/_react.default.createElement(_Icon.default, {
    className: classes.scopeIcon,
    themeColor: theme.palette.success.main,
    fontSize: "medium",
    id: "dependent-scope"
  });
  switch (type) {
    case _constants.scopeTypes.global:
      return globalIcon;
    case _constants.scopeTypes.virtual:
      return virtualIcon;
    case _constants.scopeTypes.sale:
      return salesIcon;
    case _constants.scopeTypes.dependant:
      return dependentIcon;
    default:
      return null;
  }
};
__signature__(ScopeIcon, "useStyles{classes}\nuseTheme{theme}", function () {
  return [useStyles, _styles2.useTheme];
});
__signature__(ScopeIcon, "useStyles{classes}\nuseTheme{theme}", function () {
  return [useStyles, _styles2.useTheme];
});
var ScopeLabel = exports.ScopeLabel = function ScopeLabel(_ref2) {
  var name = _ref2.name,
    type = _ref2.type,
    isRootScope = _ref2.isRootScope,
    hasChildren = _ref2.hasChildren,
    isVirtualScope = _ref2.isVirtualScope,
    _ref2$isActive = _ref2.isActive,
    isActive = _ref2$isActive === void 0 ? true : _ref2$isActive;
  var classes = useStyles({
    hasChildren: hasChildren
  });
  var icon = /*#__PURE__*/_react.default.createElement(ScopeIcon, {
    type: type
  });
  var multipleLinesTextProps = new _textProps.default();
  multipleLinesTextProps.set(_textProps.default.propNames.lineCount, 3);
  multipleLinesTextProps.set(_textProps.default.propNames.classes, (0, _classnames.default)(classes.regularScopeName, _defineProperty({}, classes.virtualScopeName, isVirtualScope)));
  // 16.8 height of 1 lines of text

  var label = /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _classnames.default)(classes.scopeLabel, isActive === false ? classes.scopeLabelInactive : "")
  }, icon, /*#__PURE__*/_react.default.createElement(_MultipleLinesText.default, {
    textProps: multipleLinesTextProps,
    children: name
  }));
  return label;
};
__signature__(ScopeLabel, "useStyles{classes}", function () {
  return [useStyles];
});
__signature__(ScopeLabel, "useStyles{classes}", function () {
  return [useStyles];
});
var TreeItem = function TreeItem(_ref3) {
  var scope = _ref3.scope,
    rootId = _ref3.rootId,
    onScopeSelect = _ref3.onScopeSelect,
    isScopeSelectable = _ref3.isScopeSelectable,
    children = _ref3.children;
  var isRootScope = scope.id === rootId;
  var isVirtualScope = scope.type === _constants.scopeTypes.virtual;
  var hasChildren = scope.children.length > 0;
  var isSelectable = !isVirtualScope && (!isScopeSelectable || isScopeSelectable(scope.id));
  var classes = useStyles({
    isRootScope: isRootScope
  });
  var expandIcon = /*#__PURE__*/_react.default.createElement(_Icon.default, {
    id: "dropdown-chevron-down"
  });
  var collapseIcon = /*#__PURE__*/_react.default.createElement(_Icon.default, {
    id: "dropdown-chevron-up"
  });
  var onLabelClickHandler = function onLabelClickHandler(event) {
    event.preventDefault();
    if (isSelectable) {
      onScopeSelect(event, scope.id);
    }
  };
  return /*#__PURE__*/_react.default.createElement(_TreeItem.default, {
    nodeId: scope.id,
    label: /*#__PURE__*/_react.default.createElement(ScopeLabel, {
      name: scope.name,
      type: scope.type,
      isRootScope: isRootScope,
      isVirtualScope: isVirtualScope,
      hasChildren: hasChildren,
      isActive: scope.isActive
    }),
    expandIcon: isRootScope ? null : expandIcon,
    collapseIcon: isRootScope ? null : collapseIcon,
    onLabelClick: function onLabelClick(e) {
      return onLabelClickHandler(e);
    },
    classes: {
      group: classes.group,
      iconContainer: (0, _classnames.default)(_defineProperty({}, classes.rootIconContainer, isRootScope)),
      content: (0, _classnames.default)(_defineProperty({}, classes.virtualScopeContent, !isSelectable)),
      selected: (0, _classnames.default)(_defineProperty({}, classes.virtualScopeSelected, !isSelectable))
    }
  }, hasChildren ? children : null);
};
__signature__(TreeItem, "useStyles{classes}", function () {
  return [useStyles];
});
__signature__(TreeItem, "useStyles{classes}", function () {
  return [useStyles];
});
var _default = TreeItem;
var _default2 = _default;
var _default3 = exports.default = _default2;
;
(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
  if (!reactHotLoader) {
    return;
  }
  reactHotLoader.register(useStyles, "useStyles", "/home/vsts/work/1/s/src/components/MaterialUI/ScopeSelector/TreeItem.js");
  reactHotLoader.register(ScopeIcon, "ScopeIcon", "/home/vsts/work/1/s/src/components/MaterialUI/ScopeSelector/TreeItem.js");
  reactHotLoader.register(ScopeLabel, "ScopeLabel", "/home/vsts/work/1/s/src/components/MaterialUI/ScopeSelector/TreeItem.js");
  reactHotLoader.register(TreeItem, "TreeItem", "/home/vsts/work/1/s/src/components/MaterialUI/ScopeSelector/TreeItem.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/components/MaterialUI/ScopeSelector/TreeItem.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();
;
(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
  if (!reactHotLoader) {
    return;
  }
  reactHotLoader.register(useStyles, "useStyles", "/home/vsts/work/1/s/src/components/MaterialUI/ScopeSelector/TreeItem.js");
  reactHotLoader.register(ScopeIcon, "ScopeIcon", "/home/vsts/work/1/s/src/components/MaterialUI/ScopeSelector/TreeItem.js");
  reactHotLoader.register(ScopeLabel, "ScopeLabel", "/home/vsts/work/1/s/src/components/MaterialUI/ScopeSelector/TreeItem.js");
  reactHotLoader.register(TreeItem, "TreeItem", "/home/vsts/work/1/s/src/components/MaterialUI/ScopeSelector/TreeItem.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/components/MaterialUI/ScopeSelector/TreeItem.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();