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

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

// @ts-check

const fs = __webpack_require__(7147);
const path = __webpack_require__(1017);
/**
 * Imports: Handle imports
 */ /**
 * Grab Paths Function
 * ==============================================================================
 * @description Description
 *
 * @param {object} params - An object containing the function parameters.
 * @param {boolean} [params.isPrivate] - Is this file private or not?
 * @param {any} params.user - User object
 * @param {string} [params.folder] - Folder, if available
 * @param {boolean} [params.video] - Video, if available
 * @param {boolean} [params.pathOnly] - Just generate the directories' paths
 *
 * @returns {{ fileRootPath: string, urlRootPath: string, relativePath: string } | null}
 */ module.exports = function grabPaths({ isPrivate , user , folder , video , pathOnly ,  }) {
    /**
     * Initialize variables
     */ const isProduction = "production".match(/production/);
    const userId = user?.id || user?.user_id;
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Handle function logic
     */ const STATIC_ROOT = process.env.DSQL_STATIC_SERVER_DIR;
    if (!STATIC_ROOT) {
        console.log("Static File ENV not Found!");
        return null;
    }
    const relativePath = isPrivate ? `@/${video ? "videos" : "media"}/${folder ? folder + "/" : ""}` : video ? `/videos/user-videos/user-${userId}/${folder ? folder + "/" : ""}` : `/images/user-images/user-${userId}/${folder ? folder + "/" : ""}`;
    const fileRootPath = isPrivate ? `${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${userId}/media/${folder ? folder + "/" : ""}` : path.join(STATIC_ROOT, relativePath);
    if (!fs.existsSync(fileRootPath) && !pathOnly) {
        fs.mkdirSync(fileRootPath, {
            recursive: true
        });
    }
    const urlRootPath = isPrivate ? `@/media/${folder ? folder + "/" : ""}` : `${process.env.DSQL_STATIC_HOST}${relativePath}`;
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Return statement
     */ return {
        fileRootPath: fileRootPath,
        urlRootPath: urlRootPath,
        relativePath
    };
};


/***/ }),

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

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

// EXPORTS
__webpack_require__.d(__webpack_exports__, {
  "MediaContext": () => (/* binding */ MediaContext),
  "default": () => (/* binding */ Dashboard),
  "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/UploadImageComponent.jsx
var UploadImageComponent = __webpack_require__(3770);
// EXTERNAL MODULE: ./components/admin/media/NewMediaPopup.jsx + 3 modules
var NewMediaPopup = __webpack_require__(4891);
// EXTERNAL MODULE: ./components/admin/media/TargetMediaPreviewPopup.jsx
var TargetMediaPreviewPopup = __webpack_require__(3428);
// EXTERNAL MODULE: ./components/admin/media/NewFolderPopup.jsx
var NewFolderPopup = __webpack_require__(1597);
// EXTERNAL MODULE: ./components/general/BackButton.jsx
var BackButton = __webpack_require__(1781);
// EXTERNAL MODULE: ./components/general/Breadcrumbs.jsx
var Breadcrumbs = __webpack_require__(424);
// EXTERNAL MODULE: ./components/general/GeneralPopup.jsx
var GeneralPopup = __webpack_require__(5472);
// EXTERNAL MODULE: ./components/general/VerificationBanner.jsx
var VerificationBanner = __webpack_require__(7946);
// EXTERNAL MODULE: ./components/admin/media/MediaList.jsx + 5 modules
var MediaList = __webpack_require__(7604);
// EXTERNAL MODULE: ./components/general/ui/ButtonGroup.jsx
var ButtonGroup = __webpack_require__(5449);
// EXTERNAL MODULE: external "@mui/icons-material/FolderCopyTwoTone"
var FolderCopyTwoTone_ = __webpack_require__(8398);
var FolderCopyTwoTone_default = /*#__PURE__*/__webpack_require__.n(FolderCopyTwoTone_);
;// CONCATENATED MODULE: ./components/admin/media/MediaFolderContent.jsx
// @ts-check
/**
 * ==============================================================================
 * Imports
 * ==============================================================================
 */ 









/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
 * ==============================================================================
 * Main Component { Functional }
 * ==============================================================================
 * @param {Object} props - Server props
 */ function MediaFolderContent(props) {
    /**
     * Get Contexts
     *
     * @abstract { React.useContext }
     */ const { media , setTargetMedia , user , folders , query , staticHost , folder  } = external_react_default().useContext(MediaContext);
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Javascript Variables
     *
     * @abstract Non hook variables and functions
     */ ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * React Hooks
     *
     * @abstract { useState, useEffect, useRef, etc ... }
     */ ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * 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__*/ jsx_runtime_.jsx((FolderCopyTwoTone_default()), {
                                        className: "opacity-40"
                                    }),
                                    /*#__PURE__*/ jsx_runtime_.jsx("h1", {
                                        className: "text-3xl m-0",
                                        children: query.folder[query.folder.length - 1]
                                    })
                                ]
                            }),
                            /*#__PURE__*/ (0,jsx_runtime_.jsxs)(ButtonGroup/* default */.Z, {
                                children: [
                                    /*#__PURE__*/ (0,jsx_runtime_.jsxs)("button", {
                                        className: "flex items-center gap-2",
                                        onClick: (e)=>{
                                            (0,GeneralPopup/* openPopup */.Mw)("choose-media-type-popoup");
                                        },
                                        children: [
                                            /*#__PURE__*/ jsx_runtime_.jsx("span", {
                                                className: "symbol",
                                                children: "+"
                                            }),
                                            /*#__PURE__*/ jsx_runtime_.jsx("span", {
                                                children: "Add Media"
                                            })
                                        ]
                                    }),
                                    /*#__PURE__*/ (0,jsx_runtime_.jsxs)("button", {
                                        className: "flex items-center gap-2 outlined gray",
                                        onClick: (e)=>{
                                            (0,GeneralPopup/* openPopup */.Mw)("add-folder-popoup", (popupElement)=>{
                                                popupElement?.querySelector("input")?.focus();
                                            });
                                        },
                                        children: [
                                            /*#__PURE__*/ jsx_runtime_.jsx("span", {
                                                className: "symbol",
                                                children: "+"
                                            }),
                                            /*#__PURE__*/ jsx_runtime_.jsx("span", {
                                                children: "Add Folder"
                                            })
                                        ]
                                    })
                                ]
                            })
                        ]
                    }),
                    /*#__PURE__*/ jsx_runtime_.jsx(Breadcrumbs/* default */.Z, {
                        user: user
                    })
                ]
            }),
            user?.verification_status?.toString().match(/1/) ? /*#__PURE__*/ (0,jsx_runtime_.jsxs)((external_react_default()).Fragment, {
                children: [
                    /*#__PURE__*/ jsx_runtime_.jsx(MediaList/* default */.Z, {
                        media: media,
                        setTargetMedia: setTargetMedia,
                        folders: folders,
                        folder: folder,
                        staticHost: staticHost,
                        user: user
                    }),
                    media && media[0] && /*#__PURE__*/ (0,jsx_runtime_.jsxs)("a", {
                        className: "border-dotted border-slate-400 border-2 px-4 py-3 w-full rounded flex items-center hover:border-primary/50 gap-2 cursor-pointer justify-center",
                        onClick: (e)=>{
                            (0,GeneralPopup/* openPopup */.Mw)("choose-media-type-popoup");
                        },
                        children: [
                            /*#__PURE__*/ jsx_runtime_.jsx("span", {
                                className: "symbol",
                                children: "+"
                            }),
                            /*#__PURE__*/ jsx_runtime_.jsx("span", {
                                className: "",
                                children: "Add Media"
                            })
                        ]
                    })
                ]
            }) : /*#__PURE__*/ jsx_runtime_.jsx(VerificationBanner/* default */.Z, {})
        ]
    });
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */ 

// EXTERNAL MODULE: ./components/general/UploadFileComponent.jsx
var UploadFileComponent = __webpack_require__(8916);
// EXTERNAL MODULE: ./components/admin/media/ChooseMediaTypePopup.jsx
var ChooseMediaTypePopup = __webpack_require__(9201);
// EXTERNAL MODULE: ./components/general/LoadingBlock.jsx
var LoadingBlock = __webpack_require__(5264);
// 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);
// EXTERNAL MODULE: external "path"
var external_path_ = __webpack_require__(1017);
var external_path_default = /*#__PURE__*/__webpack_require__.n(external_path_);
// EXTERNAL MODULE: ./components/general/UploadVideoComponent.jsx
var UploadVideoComponent = __webpack_require__(7525);
// EXTERNAL MODULE: ./functions/backend/grabPaths.js
var grabPaths = __webpack_require__(3345);
var grabPaths_default = /*#__PURE__*/__webpack_require__.n(grabPaths);
;// CONCATENATED MODULE: ./pages/admin/[user_id]/media/[...folder].jsx
// @ts-check
/**
 * ==============================================================================
 * Imports
 * ==============================================================================
 */ 

const fs = __webpack_require__(7147);
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////














/** ****************************************************************************** */ /** @type {import("@/package-shared/types").MediaFolderPageContextType} */ // @ts-ignore
const init = {};
const MediaContext = /*#__PURE__*/ external_react_default().createContext(init);
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
 * ==============================================================================
 * Main Component { Functional }
 * ==============================================================================
 * @param {Object} props - Server props
 * @param {import("@/package-shared/types").UserType} props.user
 * @param {any[]} props.media
 * @param {any[]} props.folders
 * @param {any} props.query
 * @param {string} props.staticHost
 * @param {string} props.folderNameFull
 */ function Dashboard({ user , media , folders , query , staticHost , folderNameFull ,  }) {
    /**
     * Get Contexts
     *
     * @abstract { React.useContext }
     */ ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Javascript Variables
     *
     * @abstract Non hook variables and functions
     */ const pageTitle = "User Dashboard | 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 ... }
     */ /** @type {[ newMedia: any, setNewMedia: React.Dispatch<React.SetStateAction<any>> ]} */ // @ts-ignore
    const [newMedia, setNewMedia] = external_react_default().useState(null);
    /** @type {[ newFile: any, setNewFile: React.Dispatch<React.SetStateAction<any>> ]} */ // @ts-ignore
    const [newFile, setNewFile] = external_react_default().useState(null);
    /** @type {[ newFile: any, setNewFile: React.Dispatch<React.SetStateAction<any>> ]} */ // @ts-ignore
    const [newVideo, setNewVideo] = external_react_default().useState(null);
    const [loading, setLoading] = external_react_default().useState(false);
    /** @type {[ targetMedia: import("@/package-shared/types").MYSQL_user_media_table_def | null, setTargetMedia: React.Dispatch<React.SetStateAction<import("@/package-shared/types").MYSQL_user_media_table_def | null>> ]} */ // @ts-ignore
    const [targetMedia, setTargetMedia] = external_react_default().useState(null);
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Function Return
     *
     * @abstract Main Function Return
     */ return /*#__PURE__*/ jsx_runtime_.jsx(AdminLayout/* default */.Z, {
        head: head,
        user: user,
        children: /*#__PURE__*/ (0,jsx_runtime_.jsxs)(MediaContext.Provider, {
            value: {
                user,
                media,
                targetMedia,
                setTargetMedia,
                folders,
                query,
                staticHost,
                folder: folderNameFull
            },
            children: [
                loading && /*#__PURE__*/ jsx_runtime_.jsx(LoadingBlock/* default */.Z, {
                    screen: true,
                    title: "Processing Files ..."
                }),
                /*#__PURE__*/ jsx_runtime_.jsx(MediaFolderContent, {}),
                /*#__PURE__*/ jsx_runtime_.jsx(UploadImageComponent/* default */.Z, {
                    setNewMedia: setNewMedia,
                    setLoading: setLoading
                }),
                /*#__PURE__*/ jsx_runtime_.jsx(UploadFileComponent/* default */.Z, {
                    setNewFile: setNewFile,
                    setLoading: setLoading
                }),
                /*#__PURE__*/ jsx_runtime_.jsx(UploadVideoComponent/* default */.Z, {
                    setNewVideo: setNewVideo,
                    setLoading: setLoading
                }),
                /*#__PURE__*/ jsx_runtime_.jsx(NewMediaPopup/* default */.Z, {
                    newMedia: newMedia,
                    setNewMedia: setNewMedia,
                    newFile: newFile,
                    setNewFile: setNewFile,
                    folder: folderNameFull,
                    newVideo: newVideo,
                    setNewVideo: setNewVideo
                }),
                /*#__PURE__*/ jsx_runtime_.jsx(TargetMediaPreviewPopup/* default */.Z, {
                    targetMedia: targetMedia,
                    staticHost: staticHost,
                    setTargetMedia: setTargetMedia,
                    media: media
                }),
                /*#__PURE__*/ jsx_runtime_.jsx(NewFolderPopup/* default */.Z, {
                    folder: folderNameFull
                }),
                /*#__PURE__*/ jsx_runtime_.jsx(ChooseMediaTypePopup/* default */.Z, {
                    user: user
                })
            ]
        })
    });
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
}
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
 * ==============================================================================
 * Server Side Props or Static Props
 * ==============================================================================
 * @type {import("next").GetServerSideProps}
 */ async function getServerSideProps({ req , res , query  }) {
    try {
        /**
         * User Auth
         *
         * @description User Auth
         */ const user = await userAuth_default()(req, res);
        if (!user?.logged_in_status) {
            return {
                redirect: {
                    destination: "/login",
                    permanent: false
                }
            };
        }
        /**
         * Page/Site Data Data Fetching
         *
         * @description Fetch data on the server before returning
         */ /** @type {string[]} */ // @ts-ignore
        const queryFoldersArray = query.folder;
        const folderName = queryFoldersArray.join("/");
        const media = await DB_HANDLER_default()(`SELECT * FROM user_media WHERE user_id='${user.id}' AND folder='${folderName}'`);
        const paths = grabPaths_default()({
            isPrivate: false,
            user,
            folder: folderName,
            video: false,
            pathOnly: true
        });
        if (!paths) {
            console.log("Static File ENV not Found!");
            return {
                redirect: {
                    destination: "/",
                    permanent: false
                }
            };
        }
        const folderPath = paths.fileRootPath;
        const folders = fs.readdirSync(folderPath).filter((name)=>!fs.statSync(external_path_default().normalize(`${folderPath}/${name}`)).isFile());
        ////////////////////////////////////////
        ////////////////////////////////////////
        ////////////////////////////////////////
        /**
         * Server props return
         *
         * @description Return data fetched on the server side
         */ return {
            props: {
                user: user,
                media: media,
                folders: folders,
                query: query,
                staticHost: process.env.DSQL_STATIC_HOST || "",
                folderNameFull: folderName
            }
        };
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    } catch (/** @type {*} */ error) {
        return {
            redirect: {
                destination: `/admin`,
                permanent: false
            }
        };
    }
}


/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

/***/ }),

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

module.exports = require("path");

/***/ })

};
;

// 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,8345,6718,7946,6390], () => (__webpack_exec__(3947)));
module.exports = __webpack_exports__;

})();