"use strict";
(() => {
var exports = {};
exports.id = 1973;
exports.ids = [1973];
exports.modules = {

/***/ 240:
/***/ ((module, __webpack_exports__, __webpack_require__) => {

__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "Z": () => (/* binding */ SuConsoleContent)
/* harmony export */ });
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(997);
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6689);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var socket_io_client__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(4612);
/* harmony import */ var _xterm__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(920);
/* harmony import */ var ansi_regex__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(8844);
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([socket_io_client__WEBPACK_IMPORTED_MODULE_2__, ansi_regex__WEBPACK_IMPORTED_MODULE_4__]);
([socket_io_client__WEBPACK_IMPORTED_MODULE_2__, ansi_regex__WEBPACK_IMPORTED_MODULE_4__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);
// @ts-check
/**
 * ==============================================================================
 * Imports
 * ==============================================================================
 */ 




//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
let isMouseInLogHistory = false;
/**
 * ==============================================================================
 * Main Component { Functional }
 * ==============================================================================
 * @param {Object} props - Server props
 * @param {string} props.socketDomain
 */ function SuConsoleContent({ socketDomain  }) {
    /**
     * Get Contexts
     *
     * @abstract { React.useContext }
     */ ////////////////////////////////////////////////
    ////////////////////////////////////////////////
    ////////////////////////////////////////////////
    /**
     * Javascript Variables
     *
     * @abstract Non hook variables and functions
     */ ////////////////////////////////////////////////
    ////////////////////////////////////////////////
    ////////////////////////////////////////////////
    /**
     * React Hooks
     *
     * @abstract { useState, useEffect, useRef, etc ... }
     */ /** @type {[ state: Socket, dispatch: React.Dispatch<React.SetStateAction<Socket>> ]} */ // @ts-ignore
    const [socket, setSocket] = react__WEBPACK_IMPORTED_MODULE_1___default().useState(null);
    /** @type {[ state: import("xterm").Terminal, dispatch: React.Dispatch<React.SetStateAction<import("xterm").Terminal>> ]} */ // @ts-ignore
    const [terminal, setTerminal] = react__WEBPACK_IMPORTED_MODULE_1___default().useState(null);
    const [log, setLog] = react__WEBPACK_IMPORTED_MODULE_1___default().useState("");
    react__WEBPACK_IMPORTED_MODULE_1___default().useEffect(()=>{
        const domain = socketDomain;
        console.log("Socket Domain =>", domain);
        if (!domain) return;
        /** @type {Socket} */ const socketIo = (0,socket_io_client__WEBPACK_IMPORTED_MODULE_2__.io)(domain, {
            extraHeaders: {
                "X-Socket-Paradigm": "Console"
            }
        });
        socketIo.on("connect", ()=>{
            setSocket(socketIo);
            console.log("Socket Connected!");
        });
        setInterval(()=>{
            socketIo.emit("get-log");
        }, 1000);
        socketIo.on("console-log", (message)=>{
            console.log("Fetched Log", message);
            setLog(message.replace((0,ansi_regex__WEBPACK_IMPORTED_MODULE_4__["default"])(), ""));
            setTimeout(()=>{
                const wrapper = document.getElementById("logHistoryWrapper");
                if (wrapper && !isMouseInLogHistory) {
                    wrapper.scrollTop = wrapper.scrollHeight;
                }
            }, 200);
        });
    }, []);
    react__WEBPACK_IMPORTED_MODULE_1___default().useEffect(()=>{
        if (!socket) return;
        (0,_xterm__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .Z)({
            socket: socket
        }).then((res)=>{
            setTerminal(res);
        });
        return function cleanup() {
            document.getElementById("terminal")?.childNodes.forEach((child)=>{
                child.parentNode?.removeChild(child);
            });
            document.getElementById("shell")?.childNodes.forEach((child)=>{
                child.parentNode?.removeChild(child);
            });
            terminal?.dispose();
        };
    }, [
        socket
    ]);
    ////////////////////////////////////////////////
    ////////////////////////////////////////////////
    ////////////////////////////////////////////////
    /**
     * Function Return
     *
     * @description Main Function Return
     */ return /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)((react__WEBPACK_IMPORTED_MODULE_1___default().Fragment), {
        children: [
            /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
                className: "w-full justify-between",
                children: [
                    /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("h2", {
                        className: "text-2xl m-0",
                        children: "Console"
                    }),
                    /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("button", {
                        onClick: (e)=>{
                            if (socket) {
                                socket.emit("log", "Logging to the console");
                            }
                        },
                        children: "Log console"
                    })
                ]
            }),
            /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
                className: "grid grid-cols-2 gap-6 w-full items-stretch",
                children: [
                    /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("section", {
                        className: "paper bg-slate-900",
                        id: "terminalWrapper",
                        children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("div", {
                            className: "flex flex-col w-full gap-10 items-start justify-start terminal",
                            children:  true && /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
                                className: "flex flex-col items-start w-full",
                                children: [
                                    /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("h2", {
                                        className: "m-0 text-white text-base",
                                        children: "Shell"
                                    }),
                                    /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("hr", {
                                        className: "opacity-20"
                                    }),
                                    /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("div", {
                                        id: "shell",
                                        className: "relative grow z-50 overflow-hidden w-full h-[340px]"
                                    })
                                ]
                            })
                        })
                    }),
                    /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("section", {
                        className: "paper bg-slate-500",
                        id: "terminalWrapper",
                        children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("div", {
                            className: "flex flex-col w-full gap-10 items-start justify-start terminal",
                            children: /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
                                className: "flex flex-col items-start w-full",
                                children: [
                                    /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("h2", {
                                        className: "m-0 text-white text-base",
                                        children: "Server Log"
                                    }),
                                    /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("hr", {
                                        className: "opacity-20"
                                    }),
                                    /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("div", {
                                        id: "terminal",
                                        className: "relative grow z-50 overflow-hidden w-full" + ( true ? " h-[150px]" : 0)
                                    })
                                ]
                            })
                        })
                    })
                ]
            })
        ]
    });
////////////////////////////////////////////////
////////////////////////////////////////////////
////////////////////////////////////////////////
} //////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////

__webpack_async_result__();
} catch(e) { __webpack_async_result__(e); } });

/***/ }),

/***/ 920:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "Z": () => (/* binding */ xterm)
/* harmony export */ });
// @ts-check
/**
 * # Main Terminal Function
 * @param {object} param0
 * @param {import("socket.io-client").Socket} param0.socket - Websocket using Socket.Io paradigm
 * @returns
 */ async function xterm({ socket  }) {
    const { Terminal  } = __webpack_require__(2803);
    const { FitAddon  } = __webpack_require__(4040);
    const fitAddon = new FitAddon();
    /** @type {HTMLElement} */ // @ts-ignore
    const terminalWrapper = document.getElementById("terminalWrapper");
    /** @type {HTMLElement} */ // @ts-ignore
    const terminalElement = document.getElementById("terminal");
    const terminalWrapperWidth = terminalWrapper.clientWidth;
    const calculatedCols = Math.round(terminalWrapperWidth / 12);
    const terminal = new Terminal({
        cols: calculatedCols,
        rows:  true ? 6 : 0
    });
    terminal.open(terminalElement);
    fitAddon.fit();
    socket.on("console", (message)=>{
        terminal.write(message);
    });
    ////////////////////////////////////
    ////////////////////////////////////
    ////////////////////////////////////
    if (true) {
        const shellFit = new FitAddon();
        /** @type {HTMLElement} */ // @ts-ignore
        const shellElement = document.getElementById("shell");
        const shell = new Terminal({
            cols: calculatedCols,
            rows: 17
        });
        shell.open(shellElement);
        shellFit.fit();
        socket.on("shell", (message)=>{
            shell.write(message);
        });
        shell.onKey((arg1, arg2)=>{
            socket.emit("shell", arg1.key);
        });
    }
    return terminal;
}


/***/ }),

/***/ 5304:
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {

// @ts-check

const { scryptSync , createDecipheriv  } = __webpack_require__(6113);
const { Buffer  } = __webpack_require__(4300);
/**
 * @param {string} encryptedString
 * @returns {string | null}
 */ const decrypt = (encryptedString)=>{
    const algorithm = "aes-192-cbc";
    const password = process.env.DSQL_ENCRYPTION_PASSWORD || "";
    const salt = process.env.DSQL_ENCRYPTION_SALT || "";
    let key = scryptSync(password, salt, 24);
    let iv = Buffer.alloc(16, 0);
    // @ts-ignore
    const decipher = createDecipheriv(algorithm, key, iv);
    try {
        let decrypted = decipher.update(encryptedString, "hex", "utf8");
        decrypted += decipher.final("utf8");
        return decrypted;
    } catch (error) {
        return null;
    }
};
module.exports = decrypt;


/***/ }),

/***/ 9239:
/***/ ((module, __webpack_exports__, __webpack_require__) => {

__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "default": () => (/* binding */ Console),
/* harmony export */   "getServerSideProps": () => (/* binding */ getServerSideProps)
/* harmony export */ });
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(997);
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6689);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(1503);
/* harmony import */ var _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var _layouts_SuAdminLayout__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(8282);
/* harmony import */ var _components_su_SuConsoleContent__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(240);
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_components_su_SuConsoleContent__WEBPACK_IMPORTED_MODULE_4__]);
_components_su_SuConsoleContent__WEBPACK_IMPORTED_MODULE_4__ = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];
// @ts-check
/**
 * ==============================================================================
 * Imports
 * ==============================================================================
 */ 





/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
 * ==============================================================================
 * Main Component { Functional }
 * ==============================================================================
 * @param {Object} props - Server props
 * @param {import("@/package-shared/types").UserType} props.user
 * @param {any} [props.data]
 * @param {string} props.socketDomain
 */ function Console({ user , data , socketDomain  }) {
    /**
     * Get Contexts
     *
     * @abstract { React.useContext }
     */ ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Javascript Variables
     *
     * @abstract Non hook variables and functions
     */ const pageTitle = "Console | Datasquirel";
    const pageDescription = "Databases Console";
    let head = /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.Fragment, {
        children: [
            /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("title", {
                children: pageTitle
            }),
            /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("meta", {
                name: "description",
                content: pageDescription
            })
        ]
    });
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * React Hooks
     *
     * @abstract { useState, useEffect, useRef, etc ... }
     */ ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Function Return
     *
     * @abstract Main Function Return
     */ return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_layouts_SuAdminLayout__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .Z, {
        head: head,
        user: user,
        children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_su_SuConsoleContent__WEBPACK_IMPORTED_MODULE_4__/* ["default"] */ .Z, {
            socketDomain: socketDomain
        })
    });
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
}
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
 * ==============================================================================
 * Server Side Props or Static Props
 * ==============================================================================
 * @type {import("next").GetServerSideProps}
 */ async function getServerSideProps({ req , res , query  }) {
    /**
     * User Auth
     *
     * @description User Auth
     */ const suAdminUser = await _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_2___default()(req);
    if (!suAdminUser?.logged_in_status) {
        return {
            redirect: {
                destination: `/su/login`,
                permanent: false
            }
        };
    }
    const socketDomain = process.env.DSQL_SOCKET_DOMAIN;
    /**
     * Page/Site Data Data Fetching
     *
     * @description Fetch data on the server before returning
     */ ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Server props return
     *
     * @description Return data fetched on the server side
     */ return {
        props: {
            user: suAdminUser,
            socketDomain: socketDomain || ""
        }
    };
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
}

__webpack_async_result__();
} catch(e) { __webpack_async_result__(e); } });

/***/ }),

/***/ 9318:
/***/ ((module) => {

module.exports = require("@mui/icons-material/BackupTwoTone");

/***/ }),

/***/ 386:
/***/ ((module) => {

module.exports = require("@mui/icons-material/CottageTwoTone");

/***/ }),

/***/ 6817:
/***/ ((module) => {

module.exports = require("@mui/icons-material/DocumentScannerTwoTone");

/***/ }),

/***/ 6094:
/***/ ((module) => {

module.exports = require("@mui/icons-material/ErrorTwoTone");

/***/ }),

/***/ 6547:
/***/ ((module) => {

module.exports = require("@mui/icons-material/LockPersonTwoTone");

/***/ }),

/***/ 5557:
/***/ ((module) => {

module.exports = require("@mui/icons-material/MenuBookTwoTone");

/***/ }),

/***/ 8245:
/***/ ((module) => {

module.exports = require("@mui/icons-material/PeopleAltTwoTone");

/***/ }),

/***/ 415:
/***/ ((module) => {

module.exports = require("@mui/icons-material/TerminalTwoTone");

/***/ }),

/***/ 2423:
/***/ ((module) => {

module.exports = require("lucide-react");

/***/ }),

/***/ 968:
/***/ ((module) => {

module.exports = require("next/head");

/***/ }),

/***/ 6689:
/***/ ((module) => {

module.exports = require("react");

/***/ }),

/***/ 997:
/***/ ((module) => {

module.exports = require("react/jsx-runtime");

/***/ }),

/***/ 2803:
/***/ ((module) => {

module.exports = require("xterm");

/***/ }),

/***/ 4040:
/***/ ((module) => {

module.exports = require("xterm-addon-fit");

/***/ }),

/***/ 8844:
/***/ ((module) => {

module.exports = import("ansi-regex");;

/***/ }),

/***/ 4612:
/***/ ((module) => {

module.exports = import("socket.io-client");;

/***/ }),

/***/ 4300:
/***/ ((module) => {

module.exports = require("buffer");

/***/ }),

/***/ 6113:
/***/ ((module) => {

module.exports = require("crypto");

/***/ }),

/***/ 3685:
/***/ ((module) => {

module.exports = require("http");

/***/ })

};
;

// load runtime
var __webpack_require__ = require("../../webpack-runtime.js");
__webpack_require__.C(exports);
var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))
var __webpack_exports__ = __webpack_require__.X(0, [4017,8313,1503,5313], () => (__webpack_exec__(9239)));
module.exports = __webpack_exports__;

})();