import React from "react";
import { getStore } from "../stores/LauncherStore";
import storeActions from "../stores/StoreActions";
import sortFunctions from "../utils/sort-functions";
export default class SortBy extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            sortBy: storeActions.getSortBy(),
        };
        this.onOptionClick = this.onOptionClick.bind(this);
    }
    onOptionClick(option) {
        this.setState({
            sortBy: option,
        }, async () => {
            var _a;
            await ((_a = getStore()) === null || _a === void 0 ? void 0 : _a.set(["sortBy"], this.state.sortBy));
        });
    }
    renderOptionsList() {
        return Object.keys(sortFunctions).map((option, index) => {
            let classes = "sort-option pointer ";
            if (option === this.state.sortBy)
                classes = `${classes} active`;
            return (React.createElement("span", { key: index, onClick: () => this.onOptionClick(option), className: classes }, option));
        });
    }
    render() {
        return React.createElement("div", { className: "sort" },
            "Sort by: ",
            this.renderOptionsList());
    }
}
//# sourceMappingURL=SortBy.js.map