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

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

// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);

// EXPORTS
__webpack_require__.d(__webpack_exports__, {
  "SingleDatabaseSingleUserContext": () => (/* binding */ SingleDatabaseSingleUserContext),
  "default": () => (/* binding */ DatabaseSingleUserPage),
  "getServerSideProps": () => (/* binding */ getServerSideProps)
});

// EXTERNAL MODULE: external "react/jsx-runtime"
var jsx_runtime_ = __webpack_require__(997);
// EXTERNAL MODULE: external "react"
var external_react_ = __webpack_require__(6689);
var external_react_default = /*#__PURE__*/__webpack_require__.n(external_react_);
// EXTERNAL MODULE: ./layouts/AdminLayout.jsx + 2 modules
var AdminLayout = __webpack_require__(4858);
// EXTERNAL MODULE: ./functions/backend/userAuth.js
var userAuth = __webpack_require__(370);
var userAuth_default = /*#__PURE__*/__webpack_require__.n(userAuth);
// EXTERNAL MODULE: ./components/general/Breadcrumbs.jsx
var Breadcrumbs = __webpack_require__(424);
// EXTERNAL MODULE: ./components/admin/users/UserListCard.jsx
var UserListCard = __webpack_require__(3863);
// EXTERNAL MODULE: ./components/general/BackButton.jsx
var BackButton = __webpack_require__(1781);
// EXTERNAL MODULE: ./functions/frontend/fetchApi.js
var fetchApi = __webpack_require__(6729);
// EXTERNAL MODULE: ./components/general/LoadingBlock.jsx
var LoadingBlock = __webpack_require__(5264);
// EXTERNAL MODULE: ./components/form/FormSelect.jsx
var FormSelect = __webpack_require__(4114);
// EXTERNAL MODULE: ./components/form/FormCheckboxes.jsx
var FormCheckboxes = __webpack_require__(9486);
// EXTERNAL MODULE: ./components/admin/users/UserImage.jsx
var UserImage = __webpack_require__(2733);
;// CONCATENATED MODULE: ./components/admin/users/SingleDatabaseSingleUserContent.jsx
// @ts-check
/**
 * ==============================================================================
 * Imports
 * ==============================================================================
 */ 










/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
 * ==============================================================================
 * Main Component { Functional }
 * ==============================================================================
 * @param {Object} props - Server props
 */ function SingleDatabaseSingleUserContent(props) {
    /**
     * Get Contexts
     *
     * @abstract { React.useContext }
     */ const { singleUser , user  } = external_react_default().useContext(SingleDatabaseSingleUserContext);
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Javascript Variables
     *
     * @abstract Non hook variables and functions
     */ const userFields = Object.keys(singleUser).filter((key)=>!key.match(/^id$|^date_|^user_id$|^social_|^disk_usage|user_type/));
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * React Hooks
     *
     * @abstract { useState, useEffect, useRef, etc ... }
     */ const [loading, setLoading] = external_react_default().useState(false);
    const [priviledges, setPriviledges] = external_react_default().useState(singleUser.user_type?.match(/invitation/) ? singleUser["user_priviledge"]?.split("|") : [
        "Edit"
    ]);
    /** @type {[ userImage: string | import("@/package-shared/types").ImageObjectType | any, setUserImage: React.Dispatch<React.SetStateAction<string | import("@/package-shared/types").ImageObjectType | any>> ]} */ // @ts-ignore
    const [userImage, setUserImage] = external_react_default().useState(singleUser["image"]);
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Function Return
     *
     * @abstract Main Function Return
     */ return /*#__PURE__*/ (0,jsx_runtime_.jsxs)((external_react_default()).Fragment, {
        children: [
            /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                className: "flex-col items-start gap-0 w-full",
                children: [
                    /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                        className: "w-full justify-between flex-wrap",
                        children: [
                            /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                                children: [
                                    /*#__PURE__*/ jsx_runtime_.jsx(BackButton/* default */.Z, {}),
                                    /*#__PURE__*/ (0,jsx_runtime_.jsxs)("h1", {
                                        className: "text-3xl m-0",
                                        children: [
                                            singleUser.first_name,
                                            " ",
                                            singleUser.last_name
                                        ]
                                    })
                                ]
                            }),
                            /*#__PURE__*/ jsx_runtime_.jsx("button", {
                                className: "bg-red-500",
                                onClick: (e)=>{
                                    setLoading(true);
                                    if (window.confirm("Delete this user?")) {
                                        (0,fetchApi/* default */.Z)("/api/deleteUserUser", {
                                            method: "post",
                                            body: {
                                                ...singleUser
                                            }
                                        }, true).then((res)=>{
                                            if (res.success) window.location.pathname = `/admin/${user?.id}/users/databases/${singleUser.database}`;
                                        });
                                    }
                                },
                                children: "Delete User"
                            })
                        ]
                    }),
                    /*#__PURE__*/ jsx_runtime_.jsx(Breadcrumbs/* default */.Z, {
                        user: user
                    })
                ]
            }),
            /*#__PURE__*/ (0,jsx_runtime_.jsxs)("section", {
                children: [
                    loading && /*#__PURE__*/ jsx_runtime_.jsx(LoadingBlock/* default */.Z, {}),
                    /*#__PURE__*/ jsx_runtime_.jsx("div", {
                        className: "w-full flex-col items-stretch",
                        children: /*#__PURE__*/ (0,jsx_runtime_.jsxs)("form", {
                            className: "flex flex-col items-stretch gap-4",
                            onSubmit: (e)=>{
                                e.preventDefault();
                                setLoading(true);
                                /** @type {HTMLFormElement} */ // @ts-ignore
                                const form = e.target;
                                const formFields = Array.from(form);
                                /** @type {any} */ const formFieldsObject = {};
                                formFields.forEach((/** @type {any} */ field)=>{
                                    if (field?.nodeName?.match(/button/i)) return;
                                    if (!field?.name || !field?.value?.match(/./)) return;
                                    if (field?.name?.match(/username|email/)) return;
                                    formFieldsObject[field.name] = field.value;
                                });
                                const fetchObject = {
                                    ...formFieldsObject,
                                    user_type: singleUser["user_type"],
                                    id: singleUser["id"]
                                };
                                if (singleUser["user_type"]?.match(/invitation/i)) {
                                    // fetchObject["database_access"] =
                                    //     databasesAccess.join("|");
                                    fetchObject["user_priviledge"] = priviledges?.join("|");
                                }
                                (0,fetchApi/* default */.Z)("/api/updateUserUser", {
                                    method: "post",
                                    body: fetchObject
                                }, true).then((res)=>{
                                    if (userImage?.imageBase64) {
                                        userImage["imageName"] = `${singleUser["database"]}-user-${singleUser.id}`;
                                        userImage["mimeType"] = "jpeg";
                                        delete userImage["imageBase64Full"];
                                        (0,fetchApi/* default */.Z)("/api/addUserMedia", {
                                            method: "post",
                                            body: {
                                                media: [
                                                    userImage
                                                ],
                                                folder: singleUser["database"]?.replace(/_/g, "-"),
                                                type: "image"
                                            }
                                        }, true).then((_res)=>{
                                            if (_res && _res.mediaData && _res.mediaData[0]?.media_url) {
                                                (0,fetchApi/* default */.Z)("/api/updateUserUser", {
                                                    method: "post",
                                                    body: {
                                                        id: singleUser.id,
                                                        user_type: singleUser.user_type,
                                                        image: _res.mediaData[0].media_url,
                                                        image_thumbnail: _res.mediaData[0].media_thumbnail_url
                                                    }
                                                }, true).then((__res)=>{
                                                    if (__res.success) window.location.reload();
                                                    setTimeout(()=>{
                                                        setLoading(false);
                                                    }, 500);
                                                });
                                            } else {
                                                window.location.reload();
                                            }
                                        });
                                    } else {
                                        window.location.reload();
                                    }
                                });
                            },
                            children: [
                                userFields.map((field, index)=>{
                                    if (field?.match(/user_priviledge/) && singleUser.user_type?.match(/invitation/)) {
                                        return /*#__PURE__*/ jsx_runtime_.jsx("div", {
                                            className: "flex-col items-start w-full gap-1",
                                            children: /*#__PURE__*/ jsx_runtime_.jsx(FormCheckboxes/* default */.Z, {
                                                // @ts-ignore
                                                checkBoxValues: singleUser[field]?.split("|").map((/** @type {string} */ priv)=>{
                                                    return {
                                                        title: priv,
                                                        name: priv,
                                                        onChangeHandler: (/** @type {any} */ e)=>{
                                                            if (priviledges?.includes("Edit")) {
                                                                let newArray = priviledges.filter((_db)=>_db != "Edit");
                                                                setPriviledges([
                                                                    ...newArray, 
                                                                ]);
                                                            } else {
                                                                setPriviledges((prev)=>prev ? [
                                                                        ...prev,
                                                                        "Edit", 
                                                                    ] : []);
                                                            }
                                                        }
                                                    };
                                                }),
                                                smallText: true,
                                                flexRow: true
                                            })
                                        }, index + 1);
                                    } else if (field?.match(/user_priviledge/) && !singleUser.user_type?.match(/invitation/)) {
                                        return /*#__PURE__*/ jsx_runtime_.jsx((external_react_default()).Fragment, {}, index + 1);
                                    }
                                    if (field?.match(/password|^database|email|username/)) {
                                        return /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                                            className: "flex-col items-start w-full gap-1",
                                            children: [
                                                /*#__PURE__*/ jsx_runtime_.jsx("label", {
                                                    htmlFor: field,
                                                    children: field
                                                }),
                                                /*#__PURE__*/ jsx_runtime_.jsx("input", {
                                                    type: "text",
                                                    name: field,
                                                    id: field,
                                                    value: // @ts-ignore
                                                    singleUser[field],
                                                    placeholder: field,
                                                    className: "opacity-40 pointer-events-none",
                                                    onChange: (e)=>{
                                                        e.preventDefault();
                                                    }
                                                }, index + 1)
                                            ]
                                        }, index + 1);
                                    }
                                    if (field?.match(/more_user_data/)) {
                                        return /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                                            className: "flex-col items-start w-full gap-1",
                                            children: [
                                                /*#__PURE__*/ jsx_runtime_.jsx("label", {
                                                    htmlFor: field,
                                                    children: field
                                                }),
                                                /*#__PURE__*/ jsx_runtime_.jsx("textarea", {
                                                    name: field,
                                                    id: field,
                                                    defaultValue: // @ts-ignore
                                                    singleUser[field] ? singleUser[field] : undefined,
                                                    placeholder: field,
                                                    rows: 6
                                                }, index + 1)
                                            ]
                                        }, index + 1);
                                    }
                                    return /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                                        className: "flex-col items-start w-full gap-1",
                                        children: [
                                            /*#__PURE__*/ jsx_runtime_.jsx("label", {
                                                htmlFor: field,
                                                children: field
                                            }),
                                            /*#__PURE__*/ jsx_runtime_.jsx("input", {
                                                type: "text",
                                                name: field,
                                                id: field,
                                                defaultValue: // @ts-ignore
                                                singleUser[field] ? singleUser[field] : undefined,
                                                placeholder: field
                                            }, index + 1)
                                        ]
                                    }, index + 1);
                                }),
                                /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                                    className: "border border-slate-300 dark:border-slate-600 border-solid bg-slate-100 dark:bg-slate-700 rounded p-6 flex-col items-start w-full",
                                    children: [
                                        /*#__PURE__*/ jsx_runtime_.jsx("h3", {
                                            className: "m-0 text-lg font-semibold mb-1 text-slate-600",
                                            children: "Update Image"
                                        }),
                                        /*#__PURE__*/ jsx_runtime_.jsx(UserImage/* default */.Z, {
                                            userImage: userImage,
                                            setUserImage: setUserImage
                                        })
                                    ]
                                }),
                                /*#__PURE__*/ jsx_runtime_.jsx("button", {
                                    children: "Update User"
                                })
                            ]
                        })
                    })
                ]
            })
        ]
    });
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */ 

// EXTERNAL MODULE: ./package-shared/utils/backend/global-db/DB_HANDLER.js
var DB_HANDLER = __webpack_require__(9395);
var DB_HANDLER_default = /*#__PURE__*/__webpack_require__.n(DB_HANDLER);
;// CONCATENATED MODULE: ./pages/admin/[user_id]/users/databases/[database]/[user].jsx
// @ts-check
/**
 * ==============================================================================
 * Imports
 * ==============================================================================
 */ 

////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////




/** ****************************************************************************** */ /** @type {import("@/package-shared/types").SingleUserUserContextType} */ // @ts-ignore
const init = {};
const SingleDatabaseSingleUserContext = /*#__PURE__*/ external_react_default().createContext(init);
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
 * ==============================================================================
 * Main Component { Functional }
 * ==============================================================================
 * @param {Object} props - Server props
 * @param {import("@/package-shared/types").UserType} props.user
 * @param {import("@/package-shared/types").MYSQL_user_users_table_def} props.singleUser
 */ function DatabaseSingleUserPage({ user , singleUser  }) {
    /**
     * Get Contexts
     *
     * @abstract { React.useContext }
     */ ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Javascript Variables
     *
     * @abstract Non hook variables and functions
     */ const pageTitle = `${singleUser.first_name} ${singleUser.last_name} Users | Datasquirel"`;
    const pageDescription = "Welcome to your data app";
    let head = /*#__PURE__*/ (0,jsx_runtime_.jsxs)(jsx_runtime_.Fragment, {
        children: [
            /*#__PURE__*/ jsx_runtime_.jsx("title", {
                children: pageTitle
            }),
            /*#__PURE__*/ jsx_runtime_.jsx("meta", {
                name: "description",
                content: pageDescription
            })
        ]
    });
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * React Hooks
     *
     * @abstract { useState, useEffect, useRef, etc ... }
     */ ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Function Return
     *
     * @abstract Main Function Return
     */ return /*#__PURE__*/ jsx_runtime_.jsx(AdminLayout/* default */.Z, {
        head: head,
        user: user,
        children: /*#__PURE__*/ jsx_runtime_.jsx(SingleDatabaseSingleUserContext.Provider, {
            value: {
                user,
                singleUser
            },
            children: /*#__PURE__*/ jsx_runtime_.jsx(SingleDatabaseSingleUserContent, {})
        })
    });
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
}
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
 * ==============================================================================
 * Server Side Props or Static Props
 * ==============================================================================
 * @type {import("next").GetServerSideProps}
 */ async function getServerSideProps({ req , res , query  }) {
    /**
     * User Auth
     *
     * @description User Auth
     */ const user = await userAuth_default()(req, res);
    if (!user?.logged_in_status) {
        return {
            redirect: {
                destination: "/logout",
                permanent: false
            }
        };
    }
    /**
     * Page/Site Data Data Fetching
     *
     * @description Fetch data on the server before returning
     */ const singleUser = await DB_HANDLER_default()(`SELECT id,\`database\`,database_access,first_name,last_name,email,phone,user_type,user_priviledge,username,image,image_thumbnail,city,state,country,zip_code,verification_status,more_user_data FROM user_users WHERE user_id='${user.id}' AND \`database\`='${query.database}'  AND id='${query.user}'`);
    if (!singleUser || !singleUser[0]) {
        return {
            redirect: {
                destination: `/admin/${user?.id}/users/databases/${query.database}`,
                permanent: false
            }
        };
    }
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Server props return
     *
     * @description Return data fetched on the server side
     */ return {
        props: {
            user: user,
            singleUser: singleUser[0]
        }
    };
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
}


/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

/***/ 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");

/***/ }),

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

module.exports = require("serverless-mysql");

/***/ }),

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

module.exports = require("buffer");

/***/ }),

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

module.exports = require("crypto");

/***/ }),

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

module.exports = require("fs");

/***/ }),

/***/ 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,5264,6729,5449,913,4480,370,424,4858,5472,1781,4114,6718,9486,2733,3863], () => (__webpack_exec__(5342)));
module.exports = __webpack_exports__;

})();