var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
    if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
    return cooked;
};
import React from 'react';
import PropTypes from 'prop-types';
import './SortableLabel.scss';
import SortOrderType, { SortOrderTypeLabelMap } from '../../Constants/SortOrderType';
import SortOrderIcon from '../Icons/SortOrderIcon';
import styled from 'styled-components';
var toggleSortOrder = function (sortOrder) {
    switch (sortOrder) {
        case SortOrderType.Ascending:
            return SortOrderType.Descending;
        case SortOrderType.Descending:
            return null;
        default:
            return SortOrderType.Ascending;
    }
};
var getSortableLabelTitle = function (_a) {
    var label = _a.label, sortOrder = _a.sortOrder;
    return sortOrder ?
        "Sorting by " + label + " " + SortOrderTypeLabelMap[sortOrder] :
        "Sort by " + label;
};
export var SortableLabel = function (_a) {
    var className = _a.className, label = _a.label, labelHelpText = _a.labelHelpText, onSortChange = _a.onSortChange, sortBy = _a.sortBy, sortByType = _a.sortByType, sortOrder = _a.sortOrder;
    var activeSortOrder = sortBy === sortByType ?
        sortOrder :
        null;
    return (React.createElement("button", { className: [
            className,
            'sortable-label',
        ]
            .filter(Boolean)
            .join(' '), onClick: function () { return onSortChange({
            sortBy: sortByType,
            sortOrder: toggleSortOrder(activeSortOrder),
        }); }, title: getSortableLabelTitle({
            label: labelHelpText || label,
            sortOrder: activeSortOrder,
        }) },
        label,
        React.createElement(SortOrderIcon, { sortOrder: activeSortOrder })));
};
SortableLabel.propTypes = {
    className: PropTypes.string,
    label: PropTypes.node.isRequired,
    labelHelpText: PropTypes.string,
    onSortChange: PropTypes.func.isRequired,
    sortOrder: PropTypes.string,
    sortBy: PropTypes.string,
    sortByType: PropTypes.string.isRequired,
};
SortableLabel.defaultProps = {
    className: '',
};
export default styled(SortableLabel)(templateObject_1 || (templateObject_1 = __makeTemplateObject([""], [""])));
var templateObject_1;
//# sourceMappingURL=SortableLabel.js.map