import "core-js/modules/es6.object.assign";
import "core-js/modules/web.dom.iterable";
import "core-js/modules/es6.array.iterator";
import "core-js/modules/es6.object.keys";

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { EuiIcon } from '../icon';
import { LEFT_ALIGNMENT, RIGHT_ALIGNMENT, CENTER_ALIGNMENT } from '../../services';
var ALIGNMENT = [LEFT_ALIGNMENT, RIGHT_ALIGNMENT, CENTER_ALIGNMENT];
export var EuiTableHeaderCell = function EuiTableHeaderCell(_ref) {
  var children = _ref.children,
      align = _ref.align,
      onSort = _ref.onSort,
      isSorted = _ref.isSorted,
      isSortAscending = _ref.isSortAscending,
      className = _ref.className,
      ariaLabel = _ref.ariaLabel,
      scope = _ref.scope,
      isMobileHeader = _ref.isMobileHeader,
      hideForMobile = _ref.hideForMobile,
      rest = _objectWithoutProperties(_ref, ["children", "align", "onSort", "isSorted", "isSortAscending", "className", "ariaLabel", "scope", "isMobileHeader", "hideForMobile"]);

  var classes = classNames('euiTableHeaderCell', className, {
    'euiTableHeaderCell--isMobileHeader': isMobileHeader,
    'euiTableHeaderCell--hideForMobile': hideForMobile
  });
  var contentClasses = classNames('euiTableCellContent', className, {
    'euiTableCellContent--alignRight': align === RIGHT_ALIGNMENT,
    'euiTableCellContent--alignCenter': align === CENTER_ALIGNMENT
  });

  if (onSort) {
    var sortIcon;

    if (isSorted) {
      sortIcon = React.createElement(EuiIcon, {
        className: "euiTableSortIcon",
        type: isSortAscending ? 'sortUp' : 'sortDown',
        size: "m"
      });
    }

    var buttonClasses = classNames('euiTableHeaderButton', {
      'euiTableHeaderButton-isSorted': isSorted
    });
    var columnTitle = ariaLabel ? ariaLabel : children;
    var statefulAriaLabel = "Sort ".concat(columnTitle, " ").concat(isSortAscending ? 'descending' : 'ascending');
    return React.createElement("th", _extends({
      className: classes,
      scope: scope
    }, rest), React.createElement("button", {
      type: "button",
      className: buttonClasses,
      onClick: onSort,
      "aria-label": statefulAriaLabel,
      "data-test-subj": "tableHeaderSortButton"
    }, React.createElement("span", {
      className: contentClasses
    }, React.createElement("span", {
      className: "euiTableCellContent__text"
    }, children), sortIcon)));
  }

  return React.createElement("th", _extends({
    className: classes,
    "aria-label": ariaLabel,
    scope: scope
  }, rest), React.createElement("div", {
    className: contentClasses
  }, React.createElement("span", {
    className: "euiTableCellContent__text"
  }, children)));
};
EuiTableHeaderCell.propTypes = {
  children: PropTypes.node,
  className: PropTypes.string,
  align: PropTypes.oneOf(ALIGNMENT),
  onSort: PropTypes.func,
  isSorted: PropTypes.bool,
  isSortAscending: PropTypes.bool,
  scope: PropTypes.oneOf(['col', 'row', 'colgroup', 'rowgroup']),

  /**
   * Indicates if the column was created to be the row's heading in mobile view
   * (this column will be hidden at larger screens)
   */
  isMobileHeader: PropTypes.bool,

  /**
   * Indicates if the column should not show for mobile users
   * (typically hidden because a custom mobile header utilizes the column's contents)
   */
  hideForMobile: PropTypes.bool
};
EuiTableHeaderCell.defaultProps = {
  align: LEFT_ALIGNMENT,
  scope: 'col'
};
EuiTableHeaderCell.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "EuiTableHeaderCell",
  "props": {
    "align": {
      "defaultValue": {
        "value": "LEFT_ALIGNMENT",
        "computed": true
      },
      "type": {
        "name": "enum",
        "value": [{
          "value": "import {\n  LEFT_ALIGNMENT,\n  RIGHT_ALIGNMENT,\n  CENTER_ALIGNMENT\n} from '../../services';",
          "computed": true
        }, {
          "value": "import {\n  LEFT_ALIGNMENT,\n  RIGHT_ALIGNMENT,\n  CENTER_ALIGNMENT\n} from '../../services';",
          "computed": true
        }, {
          "value": "import {\n  LEFT_ALIGNMENT,\n  RIGHT_ALIGNMENT,\n  CENTER_ALIGNMENT\n} from '../../services';",
          "computed": true
        }]
      },
      "required": false,
      "description": ""
    },
    "scope": {
      "defaultValue": {
        "value": "'col'",
        "computed": false
      },
      "type": {
        "name": "enum",
        "value": [{
          "value": "'col'",
          "computed": false
        }, {
          "value": "'row'",
          "computed": false
        }, {
          "value": "'colgroup'",
          "computed": false
        }, {
          "value": "'rowgroup'",
          "computed": false
        }]
      },
      "required": false,
      "description": ""
    },
    "children": {
      "type": {
        "name": "node"
      },
      "required": false,
      "description": ""
    },
    "className": {
      "type": {
        "name": "string"
      },
      "required": false,
      "description": ""
    },
    "onSort": {
      "type": {
        "name": "func"
      },
      "required": false,
      "description": ""
    },
    "isSorted": {
      "type": {
        "name": "bool"
      },
      "required": false,
      "description": ""
    },
    "isSortAscending": {
      "type": {
        "name": "bool"
      },
      "required": false,
      "description": ""
    },
    "isMobileHeader": {
      "type": {
        "name": "bool"
      },
      "required": false,
      "description": "Indicates if the column was created to be the row's heading in mobile view\n(this column will be hidden at larger screens)"
    },
    "hideForMobile": {
      "type": {
        "name": "bool"
      },
      "required": false,
      "description": "Indicates if the column should not show for mobile users\n(typically hidden because a custom mobile header utilizes the column's contents)"
    }
  }
};