"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;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (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 __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importStar(require("react"));
var react_redux_1 = require("react-redux");
var core_1 = require("@material-ui/core");
var Action = __importStar(require("../Store/Action"));
var Box_1 = __importDefault(require("@material-ui/core/Box"));
var icons_1 = require("@material-ui/icons");
var CardContent_1 = __importDefault(require("@material-ui/core/CardContent"));
var Card_1 = __importDefault(require("@material-ui/core/Card"));
var generateNotification = function (persist) {
    if (persist === void 0) { persist = false; }
    var rand = Math.round(Math.random() * 100000);
    var variant = rand % 7 == 0 && 'error'
        || rand % 5 == 0 && 'warning'
        || rand % 3 == 0 && 'success'
        || rand % 2 == 0 && 'info'
        || 'default';
    var id = String(rand);
    var group = variant.match(/(error|warning)/) ? 'important' : 'unimportant';
    var defaultProps = {
        id: id,
        group: group,
        variant: variant,
        notistackOptions: { persist: persist }
    };
    switch (variant) {
        case 'error':
            return __assign(__assign({}, defaultProps), { title: 'ServerError', subtitle: 'Join Room (action.payload.name)', content: (react_1.default.createElement(Box_1.default, { display: 'flex', flexDirection: 'column' },
                    react_1.default.createElement("span", null, "Habitant habitasse, sem etiamnostra etiam. Tristique viverra volutpat mi, ornare non tellus, praesent odio justo platea erat quis. Aliquam est varius, fringilla class, in ad dictumst turpis vivamus eros augue. Nunc fames donec, vehicula phasellus, volutpat sem luctus leo ut. Consequat nulla enim, curae hac, lorem purus cursus feugiat habitant fusce. Ante metus curabitur, litora nec, donec diam bibendum euismod elit placerat neque. Pretium sit, morbi odio iaculis."),
                    react_1.default.createElement(Box_1.default, { display: 'flex', flexDirection: 'row' },
                        react_1.default.createElement(core_1.Button, { color: 'inherit', startIcon: react_1.default.createElement(icons_1.Refresh, null) }, "Try again"),
                        react_1.default.createElement(core_1.Button, { color: 'inherit', startIcon: react_1.default.createElement(icons_1.Block, null) }, "Ignore")))), action: function () { return react_1.default.createElement(core_1.IconButton, { color: 'inherit' },
                    react_1.default.createElement(icons_1.Visibility, null)); } });
        case 'warning':
            return __assign(__assign({}, defaultProps), { title: 'Warning', subtitle: 'Some changes aren\'t saved yet', content: 'The quick brown fox jumps over the lazy dog', action: function () { return react_1.default.createElement(core_1.IconButton, null,
                    react_1.default.createElement(icons_1.Visibility, null)); } });
        case 'success':
            return __assign(__assign({}, defaultProps), { title: 'Changes saved' });
        case 'info':
            return __assign(__assign({}, defaultProps), { content: 'Time for a cup of coffee!', action: function () { return react_1.default.createElement(core_1.Button, { color: 'inherit' }, "Get"); } });
        case 'default':
        default:
            return __assign(__assign({}, defaultProps), { variant: 'default', content: 'content loaded' });
    }
};
var DevelopNotifications = function () {
    var dispatch = (0, react_redux_1.useDispatch)();
    var persistNotificationsInputRef = (0, react_1.useRef)(null);
    var handleOnClickNotification = (0, react_1.useCallback)(function () {
        var _a;
        var persist = (_a = persistNotificationsInputRef === null || persistNotificationsInputRef === void 0 ? void 0 : persistNotificationsInputRef.current) === null || _a === void 0 ? void 0 : _a.checked;
        dispatch(Action.addNotification(generateNotification(persist)));
    }, []);
    var handleOnClickErrorNotification = (0, react_1.useCallback)(function () {
        dispatch(Action.addErrorNotification({
            config: {
                method: 'GET',
                url: '"http://de.master.api.staging-jsc-app.juwelo.local/orderitems?filter=customerId:foobar%3Bstatus:booked,cancelled%3BisInOpenBasket:false%3BexcludeStaffProducts:true&options=sortBy:sortByLikeReturnSlip%3BincludeOrderOffsetCreditBalance:true"'
            },
            toJSON: function () { return ({}); },
            isAxiosError: true,
            name: 'An AxiosError',
            message: 'Error Message',
            request: {},
            response: {
                config: {},
                headers: {},
                status: 23,
                statusText: '23',
                data: {
                    "error": "Jfs\\TestCase\\Exception\\VeryLongNamesProvokesLineBreaksOrOverflowsException",
                    "id": 0,
                    "message": "Error while injecting in AuthorizationService\\Services\\UserPasswordService::userPasswordDAO. SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known",
                    "trace": [
                        "#0 /Users/user/Projects/Juwelo/git/jsc/core/Libraries/Jsc/Service/Client/AbstractClient.php(169): Jsc\\Service\\Client\\AbstractClient->processHttpResponse(Object(Jsc\\Http\\Response))",
                        "#1 /Users/user/Projects/Juwelo/git/jsc/core/Shared/Clients/AuthorizationService/UserPasswordClient.php(57): Jsc\\Service\\Client\\AbstractClient->sendRequest(Object(Jsc\\Service\\Request\\Post), NULL)",
                        "#2 /Users/user/Projects/Juwelo/git/jsc/api/ServiceProxy/Services/Authorization/LoginService.php(172): Clients\\AuthorizationService\\UserPasswordClient->checkPassword('robert.neuner', Object(DTO\\Login\\CredentialsDTO))",
                        "#3 /Users/user/Projects/Juwelo/git/jsc/api/ServiceProxy/Services/Authorization/LoginService.php(87): ServiceProxy\\Services\\Authorization\\LoginService->checkPassword('robert.neuner', 'JuwJawJowJooo')",
                        "#4 /Users/user/Projects/Juwelo/git/jsc/api/ServiceProxy/Controllers/LoginController.php(98): ServiceProxy\\Services\\Authorization\\LoginService->loginFrontend('robert.neuner', 'Robert Neuner', 'JuwJawJowJooo', 'jfs_CustomerImp...')",
                        "#5 [internal function]: ServiceProxy\\Controllers\\LoginController->loginFrontend('jfs_CustomerImp...', Object(DTO\\Login\\CredentialsDTO))",
                        "#6 /Users/user/Projects/Juwelo/git/jsc/core/Libraries/Jsc/Service/Controller/AbstractController.php(78): call_user_func_array(Array, Array)",
                        "#7 /Users/user/Projects/Juwelo/git/jsc/core/Libraries/Jsc/Service/Dispatcher.php(87): Jsc\\Service\\Controller\\AbstractController->execute('loginFrontend', Array)",
                        "#8 /Users/user/Projects/Juwelo/git/jsc/core/Libraries/Jsc/Service/Bootstrap.php(252): Jsc\\Service\\Dispatcher->run()",
                        "#9 /Users/user/Projects/Juwelo/git/jsc/core/Libraries/Jsc/Service/Bootstrap.php(118): Jsc\\Service\\Bootstrap::runApplication('api', Object(Jsc\\Http\\Request), Object(Jsc\\Http\\Response), Object(Jsc\\Routing\\Router), 1651061331.2091)",
                        "#10 /Users/user/Projects/Juwelo/git/jsc/www-root/api.php(59): Jsc\\Service\\Bootstrap::boot('/Users/user/Pro...', 'api', 1651061331.2091)",
                        "#11 {main}"
                    ]
                }
            }
        }));
    }, []);
    var handleRemoveNotificationsByGroup = (0, react_1.useCallback)(function (event) {
        dispatch(Action.removeNotificationGroup(event.target.value));
    }, []);
    var handleOnClickToast = (0, react_1.useCallback)(function () { return dispatch(Action.addToastAction({
        contentMessage: 'Toast Test',
        dismissLabel: 'Dismiss',
        isSuccess: true
    })); }, []);
    return (react_1.default.createElement(Card_1.default, null,
        react_1.default.createElement(CardContent_1.default, null,
            react_1.default.createElement(core_1.Grid, { container: true, spacing: 1, alignItems: 'center' },
                react_1.default.createElement(core_1.Grid, { item: true },
                    react_1.default.createElement(core_1.FormControlLabel, { control: react_1.default.createElement(core_1.Checkbox, { inputRef: persistNotificationsInputRef }), label: 'persist' }),
                    react_1.default.createElement(core_1.Button, { onClick: handleOnClickNotification }, "Add Notification"),
                    react_1.default.createElement(core_1.Button, { onClick: handleOnClickErrorNotification }, "Add Error Notification"),
                    react_1.default.createElement(core_1.NativeSelect, { value: 0, onChange: handleRemoveNotificationsByGroup },
                        react_1.default.createElement("option", { value: 0, disabled: true }, "Remove Notifications by group"),
                        react_1.default.createElement("option", { value: 'important' }, "All Important"),
                        react_1.default.createElement("option", { value: 'unimportant' }, "All Unimportant"))),
                react_1.default.createElement(core_1.Grid, { item: true },
                    react_1.default.createElement(core_1.Button, { onClick: handleOnClickToast }, "Toast"))))));
};
exports.default = react_1.default.memo(DevelopNotifications);
