import _extends from '@babel/runtime/helpers/extends';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import 'core-js/modules/es.symbol.js';
import 'core-js/modules/es.symbol.description.js';
import 'core-js/modules/es.array.concat.js';
import 'core-js/modules/es.array.filter.js';
import 'core-js/modules/es.array.map.js';
import 'core-js/modules/es.object.get-own-property-descriptor.js';
import 'core-js/modules/es.object.get-own-property-descriptors.js';
import 'core-js/modules/es.object.keys.js';
import 'core-js/modules/es.object.to-string.js';
import 'core-js/modules/web.dom-collections.for-each.js';
import React__default from 'react';
import PropTypes from 'prop-types';
import { Tag } from '@carbon/react';
import { settings } from '../../../constants/Settings.js';
import { OverridePropTypes } from '../../../constants/SharedPropTypes.js';
import List from '../../List/List.js';
import Button from '../../Button/Button.js';
import { SimplePaginationPropTypes } from '../../SimplePagination/SimplePagination.js';
import deprecate from '../../../internal/deprecate.js';
import { ViewsPropType } from './SharedTableManageViewsModalPropTypes.js';
import { Edit, TrashCan } from '@carbon/icons-react';

var _excluded = ["listTitle", "privateLabelText", "publicLabelText"],
  _excluded2 = ["defaultViewId", "i18n", "isLoading", "overrides", "pagination", "rowActionsRenderer", "rowDescriptionInterpolation", "rowTagsRenderer", "rowTitleInterpolation", "testID", "testId", "views"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var iotPrefix = settings.iotPrefix;
var renderButton = function renderButton(id, _onClick, icon, key, iconText) {
  return /*#__PURE__*/React__default.createElement(Button, {
    key: key,
    testId: key,
    hasIconOnly: true,
    iconDescription: iconText,
    kind: "ghost",
    onClick: function onClick() {
      _onClick(id);
    },
    renderIcon: icon,
    size: "sm",
    tooltipAlignment: "center",
    tooltipPosition: "left"
  });
};
var getRowActions = function getRowActions(_ref, _ref2) {
  var id = _ref.id,
    isEditable = _ref.isEditable,
    isDeleteable = _ref.isDeleteable;
  var onEdit = _ref2.onEdit,
    onDelete = _ref2.onDelete,
    _ref2$i18n = _ref2.i18n,
    editIconText = _ref2$i18n.editIconText,
    deleteIconText = _ref2$i18n.deleteIconText,
    testID = _ref2.testID;
  var rowActions = [];
  if (isEditable) {
    var editItemKey = "".concat(testID, "-row-action-").concat(id, "-edit");
    var editButton = renderButton(id, onEdit, Edit, editItemKey, editIconText);
    rowActions.push(editButton);
  }
  if (isDeleteable) {
    var deleteItemKey = "".concat(testID, "-row-action-").concat(id, "-delete");
    var deleteButton = renderButton(id, onDelete, TrashCan, deleteItemKey, deleteIconText);
    rowActions.push(deleteButton);
  }
  return rowActions;
};
var getRowDescription = function getRowDescription(_ref3) {
  var description = _ref3.description;
  return description;
};
var getRowTags = function getRowTags(_ref4, _ref5) {
  var id = _ref4.id;
  var defaultViewId = _ref5.defaultViewId,
    defaultLabelText = _ref5.i18n.defaultLabelText;
  return id === defaultViewId ? [/*#__PURE__*/React__default.createElement(Tag, {
    type: "blue",
    key: "defaultTag"
  }, defaultLabelText)] : undefined;
};
var getRowTitle = function getRowTitle(_ref6, publicLabelText, privateLabelText) {
  var title = _ref6.title,
    isPublic = _ref6.isPublic;
  return "".concat(title, " (").concat(isPublic ? publicLabelText : privateLabelText, ")");
};
var propTypes = {
  /** The ID of the view that should be marked as default */
  defaultViewId: PropTypes.string,
  /** Internationalisation strings */
  i18n: PropTypes.shape({
    listTitle: PropTypes.string,
    privateLabelText: PropTypes.string,
    publicLabelText: PropTypes.string
  }).isRequired,
  /** optional skeleton to be rendered while loading data */
  isLoading: PropTypes.bool,
  /** Used to overide the internal components and props for advanced customisation */
  overrides: PropTypes.shape({
    list: OverridePropTypes
  }),
  /** SimplePagination at the bottom of list */
  pagination: PropTypes.shape(SimplePaginationPropTypes),
  /** Render prop that takes a view and the props obj and returns the rendered actions in an array */
  rowActionsRenderer: PropTypes.func,
  /** Render prop that takes a view and props obj and returns the rendered tags in an array */
  rowTagsRenderer: PropTypes.func,
  /** Function prop that takes a view, public label and private label and returns the title as a string */
  rowTitleInterpolation: PropTypes.func,
  /** Function prop that takes a view and returns the description as a string */
  rowDescriptionInterpolation: PropTypes.func,
  // TODO: remove deprecated 'testID' in v3
  // eslint-disable-next-line react/require-default-props
  testID: deprecate(PropTypes.string, "The 'testID' prop has been deprecated. Please use 'testId' instead."),
  /** Id that can be used for testing */
  testId: PropTypes.string,
  /** The views to currently be displayed */
  views: ViewsPropType.isRequired
};
var defaultProps = {
  defaultViewId: undefined,
  isLoading: false,
  overrides: undefined,
  pagination: undefined,
  rowActionsRenderer: undefined,
  rowDescriptionInterpolation: undefined,
  rowTagsRenderer: undefined,
  rowTitleInterpolation: undefined,
  testId: 'TableManageViewsList'
};
var TableManageViewsList = function TableManageViewsList(_ref7) {
  var _overrides$list, _overrides$list2;
  var defaultViewId = _ref7.defaultViewId,
    _ref7$i18n = _ref7.i18n,
    listTitle = _ref7$i18n.listTitle,
    privateLabelText = _ref7$i18n.privateLabelText,
    publicLabelText = _ref7$i18n.publicLabelText,
    i18n = _objectWithoutProperties(_ref7$i18n, _excluded),
    isLoading = _ref7.isLoading,
    overrides = _ref7.overrides,
    pagination = _ref7.pagination,
    _ref7$rowActionsRende = _ref7.rowActionsRenderer,
    rowActionsRenderer = _ref7$rowActionsRende === void 0 ? getRowActions : _ref7$rowActionsRende,
    _ref7$rowDescriptionI = _ref7.rowDescriptionInterpolation,
    rowDescriptionInterpolation = _ref7$rowDescriptionI === void 0 ? getRowDescription : _ref7$rowDescriptionI,
    _ref7$rowTagsRenderer = _ref7.rowTagsRenderer,
    rowTagsRenderer = _ref7$rowTagsRenderer === void 0 ? getRowTags : _ref7$rowTagsRenderer,
    _ref7$rowTitleInterpo = _ref7.rowTitleInterpolation,
    rowTitleInterpolation = _ref7$rowTitleInterpo === void 0 ? getRowTitle : _ref7$rowTitleInterpo,
    testID = _ref7.testID,
    testId = _ref7.testId,
    views = _ref7.views,
    props = _objectWithoutProperties(_ref7, _excluded2);
  var MyList = (overrides === null || overrides === void 0 || (_overrides$list = overrides.list) === null || _overrides$list === void 0 ? void 0 : _overrides$list.component) || List;
  var listItems = views.map(function (view) {
    var id = view.id;
    return {
      content: {
        rowActions: function rowActions() {
          return rowActionsRenderer(view, _objectSpread(_objectSpread({}, props), {}, {
            i18n: i18n,
            testID: testID
          }));
        },
        secondaryValue: rowDescriptionInterpolation(view),
        tags: rowTagsRenderer(view, _objectSpread(_objectSpread({}, props), {}, {
          defaultViewId: defaultViewId,
          i18n: i18n
        })),
        value: rowTitleInterpolation(view, publicLabelText, privateLabelText)
      },
      id: id
    };
  });
  return /*#__PURE__*/React__default.createElement(MyList, _extends({
    testID: testID || testId,
    className: "".concat(iotPrefix, "--manage-views-list"),
    isFullHeight: true,
    isLargeRow: true,
    isLoading: isLoading,
    items: listItems,
    title: listTitle,
    pagination: pagination
  }, overrides === null || overrides === void 0 || (_overrides$list2 = overrides.list) === null || _overrides$list2 === void 0 ? void 0 : _overrides$list2.props));
};
TableManageViewsList.propTypes = propTypes;
TableManageViewsList.defaultProps = defaultProps;
TableManageViewsList.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "TableManageViewsList",
  "props": {
    "rowActionsRenderer": {
      "defaultValue": {
        "value": "undefined",
        "computed": true
      },
      "description": "Render prop that takes a view and the props obj and returns the rendered actions in an array",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "rowDescriptionInterpolation": {
      "defaultValue": {
        "value": "undefined",
        "computed": true
      },
      "description": "Function prop that takes a view and returns the description as a string",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "rowTagsRenderer": {
      "defaultValue": {
        "value": "undefined",
        "computed": true
      },
      "description": "Render prop that takes a view and props obj and returns the rendered tags in an array",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "rowTitleInterpolation": {
      "defaultValue": {
        "value": "undefined",
        "computed": true
      },
      "description": "Function prop that takes a view, public label and private label and returns the title as a string",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "defaultViewId": {
      "defaultValue": {
        "value": "undefined",
        "computed": true
      },
      "description": "The ID of the view that should be marked as default",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "isLoading": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "optional skeleton to be rendered while loading data",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "overrides": {
      "defaultValue": {
        "value": "undefined",
        "computed": true
      },
      "description": "Used to overide the internal components and props for advanced customisation",
      "type": {
        "name": "shape",
        "value": {
          "list": {
            "name": "custom",
            "raw": "OverridePropTypes",
            "required": false
          }
        }
      },
      "required": false
    },
    "pagination": {
      "defaultValue": {
        "value": "undefined",
        "computed": true
      },
      "description": "SimplePagination at the bottom of list",
      "type": {
        "name": "shape",
        "value": "import { SimplePaginationPropTypes } from '../../SimplePagination/SimplePagination';",
        "computed": true
      },
      "required": false
    },
    "testId": {
      "defaultValue": {
        "value": "'TableManageViewsList'",
        "computed": false
      },
      "description": "Id that can be used for testing",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "i18n": {
      "description": "Internationalisation strings",
      "type": {
        "name": "shape",
        "value": {
          "listTitle": {
            "name": "string",
            "required": false
          },
          "privateLabelText": {
            "name": "string",
            "required": false
          },
          "publicLabelText": {
            "name": "string",
            "required": false
          }
        }
      },
      "required": true
    },
    "testID": {
      "description": "",
      "type": {
        "name": "custom",
        "raw": "deprecate(\n  PropTypes.string,\n  `The 'testID' prop has been deprecated. Please use 'testId' instead.`\n)"
      },
      "required": false
    },
    "views": {
      "description": "The views to currently be displayed",
      "type": {
        "name": "custom",
        "raw": "ViewsPropType.isRequired"
      },
      "required": false
    }
  }
};
var TableManageViewsList$1 = TableManageViewsList;

export { TableManageViewsList$1 as default };
