"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SaveOrCancelButtons = exports.LoadingButton = exports.DestructiveButton = exports.OutlinedButton = exports.TertiaryButton = exports.SecondaryButton = exports.PrimaryButton = exports.Button = void 0;
var react_1 = __importStar(require("react"));
var material_1 = require("@mui/material");
var styles_1 = require("@mui/styles");
var colors_1 = require("../../base/colors");
var Check_1 = __importDefault(require("@mui/icons-material/Check"));
var Flex_1 = require("../Flex");
exports.Button = material_1.Button;
exports.PrimaryButton = react_1.default.forwardRef(function (props, ref) {
    return react_1.default.createElement(material_1.Button, __assign({ color: "primary", ref: ref }, props));
});
exports.SecondaryButton = react_1.default.forwardRef(function (props, ref) {
    return react_1.default.createElement(material_1.Button, __assign({ color: "secondary", ref: ref }, props));
});
exports.TertiaryButton = react_1.default.forwardRef(function (_a, ref) {
    var children = _a.children, props = __rest(_a, ["children"]);
    return (react_1.default.createElement(material_1.Button, __assign({ ref: ref, sx: {
            backgroundColor: colors_1.purple.dark,
            color: "white",
            "&:hover": {
                backgroundColor: colors_1.purple.dark,
                boxShadow: "2px 2px 12px " + colors_1.purple.light,
            },
        } }, props), children));
});
exports.OutlinedButton = react_1.default.forwardRef(function (_a, ref) {
    var children = _a.children, props = __rest(_a, ["children"]);
    return (react_1.default.createElement(material_1.Button, __assign({ color: "primary", variant: "outlined", ref: ref }, props), children));
});
exports.DestructiveButton = styles_1.withStyles({
    root: {
        border: "1px solid rgba(214, 63, 60, 0.3)",
        color: colors_1.red.standard,
        padding: "8px 18px",
        "&:hover": {
            backgroundColor: colors_1.red.subtle,
            borderColor: colors_1.red.standard,
            color: colors_1.red.standard,
        },
        "&:disabled": {
            backgroundColor: colors_1.grey.soft,
            color: "rgba(79, 92, 92, 0.6)",
            border: "none",
        },
    },
})(function (_a) {
    var children = _a.children, props = __rest(_a, ["children"]);
    return (react_1.default.createElement(material_1.Button, __assign({ variant: "outlined" }, props), children));
});
var LoadingButton = function (_a) {
    var _b = _a.ButtonComponent, ButtonComponent = _b === void 0 ? exports.PrimaryButton : _b, _c = _a.isLoading, isLoading = _c === void 0 ? false : _c, _d = _a.isSuccess, isSuccess = _d === void 0 ? false : _d, _e = _a.disabled, disabled = _e === void 0 ? false : _e, children = _a.children, props = __rest(_a, ["ButtonComponent", "isLoading", "isSuccess", "disabled", "children"]);
    react_1.useEffect(function () {
        if (!props.onSubmit) {
            return;
        }
        var listener = function (event) {
            var _a;
            if (event.code === "Enter" || event.code === "NumpadEnter") {
                event.preventDefault();
                (_a = props.onSubmit) === null || _a === void 0 ? void 0 : _a.call(props, event);
            }
        };
        document.addEventListener("keydown", listener);
        return function () {
            document.removeEventListener("keydown", listener);
        };
    }, [props.onSubmit]);
    return (react_1.default.createElement(ButtonComponent, __assign({}, props, { type: props.onSubmit ? "submit" : props.onSubmit, onClick: props.onSubmit || props.onClick, disabled: isLoading || disabled }),
        isLoading && (react_1.default.createElement(material_1.CircularProgress, { size: 18, color: "inherit", style: { position: "fixed" } })),
        isSuccess && react_1.default.createElement(Check_1.default, { color: "primary" }),
        !isSuccess && children));
};
exports.LoadingButton = LoadingButton;
var SaveOrCancelButtons = function (_a) {
    var _b = _a.size, size = _b === void 0 ? "small" : _b, _c = _a.variant, variant = _c === void 0 ? "standard" : _c, onCancel = _a.onCancel, onSave = _a.onSave, _d = _a.cancelDisabled, cancelDisabled = _d === void 0 ? false : _d, saveDisabled = _a.saveDisabled, isSaving = _a.isSaving, _e = _a.saveLabel, saveLabel = _e === void 0 ? "Save" : _e, _f = _a.saveColor, saveColor = _f === void 0 ? "primary" : _f, _g = _a.saveIcon, saveIcon = _g === void 0 ? null : _g;
    return (react_1.default.createElement(Flex_1.Flex, { gap: 1 },
        react_1.default.createElement(exports.Button, { size: size, variant: "outlined", className: "spec-cancel", onClick: onCancel, disabled: cancelDisabled || isSaving }, "Cancel"),
        react_1.default.createElement(exports.LoadingButton, { ButtonComponent: variant == "warning" ? exports.DestructiveButton : exports.PrimaryButton, color: saveColor, startIcon: saveIcon, size: size, isLoading: isSaving, className: "spec-save", disabled: saveDisabled, onClick: onSave }, saveLabel)));
};
exports.SaveOrCancelButtons = SaveOrCancelButtons;
//# sourceMappingURL=Button.js.map