"use strict";
(() => {
var exports = {};
exports.id = 6618;
exports.ids = [6618,133,4135];
exports.modules = {

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

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

// EXPORTS
__webpack_require__.d(__webpack_exports__, {
  "TablesContext": () => (/* binding */ TablesContext),
  "default": () => (/* binding */ Tables),
  "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: ./functions/backend/userAuth.js
var userAuth = __webpack_require__(370);
var userAuth_default = /*#__PURE__*/__webpack_require__.n(userAuth);
// EXTERNAL MODULE: ./layouts/AdminLayout.jsx + 2 modules
var AdminLayout = __webpack_require__(4858);
// EXTERNAL MODULE: ./components/admin/databases/DeleteDatabaseConfirmationPopup.jsx
var DeleteDatabaseConfirmationPopup = __webpack_require__(5012);
// 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/CopySlug.jsx
var CopySlug = __webpack_require__(9230);
// EXTERNAL MODULE: ./components/admin/databases/DatabasesTablesList.jsx
var DatabasesTablesList = __webpack_require__(8264);
// EXTERNAL MODULE: ./components/admin/databases/TablesList.jsx + 3 modules
var TablesList = __webpack_require__(6734);
// EXTERNAL MODULE: ./components/general/ui/ButtonGroup.jsx
var ButtonGroup = __webpack_require__(5449);
// EXTERNAL MODULE: ./components/general/ActiveCloneDbBanner.jsx
var ActiveCloneDbBanner = __webpack_require__(4986);
;// CONCATENATED MODULE: ./components/admin/databases/TablesContent.jsx
// @ts-check
/**
 * ==============================================================================
 * Imports
 * ==============================================================================
 */ 









/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
 * ==============================================================================
 * Main Component { Functional }
 * ==============================================================================
 * @param {Object} props - Server props
 */ function TablesContent(props) {
    /**
     * Get Contexts
     *
     * @abstract { React.useContext }
     */ const { tables , setTargetTable , database , query , confirmedDelegetedUser , user ,  } = external_react_default().useContext(TablesContext);
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Javascript Variables
     *
     * @abstract Non hook variables and functions
     */ const isDelegated = confirmedDelegetedUser?.delegated;
    const isTableEditable = confirmedDelegetedUser?.priviledges?.match(/Edit Tables/i);
    const isTableDeletable = confirmedDelegetedUser?.priviledges?.match(/Delete Tables/i);
    const isTableCreatable = confirmedDelegetedUser?.priviledges?.match(/Create Tables/i);
    const { active_clone , active_clone_parent_db , remote_connected  } = database;
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * 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-2 w-full",
                children: [
                    /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                        className: "w-full justify-between flex-wrap gap-6",
                        children: [
                            /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                                className: "flex-wrap",
                                children: [
                                    /*#__PURE__*/ jsx_runtime_.jsx(BackButton/* default */.Z, {}),
                                    /*#__PURE__*/ (0,jsx_runtime_.jsxs)("h1", {
                                        className: "text-3xl m-0 flex flex-wrap gap-2",
                                        children: [
                                            /*#__PURE__*/ jsx_runtime_.jsx("span", {
                                                className: "inline",
                                                children: "All Tables in"
                                            }),
                                            /*#__PURE__*/ jsx_runtime_.jsx("span", {
                                                className: "inline relative",
                                                children: /*#__PURE__*/ (0,jsx_runtime_.jsxs)("a", {
                                                    href: `/admin/${user?.id}/databases/${database.db_slug}`,
                                                    className: "p-2 bg-white dark:bg-slate-800 rounded border border-solid border-slate-200 dark:border-slate-600 text-primary hover:text-primary_dark relative inline",
                                                    onClick: (e)=>{
                                                        /** @type {HTMLAnchorElement} */ // @ts-ignore
                                                        const linkEl = e.target;
                                                        if (linkEl.closest(".copy-slug-span")) {
                                                            e.preventDefault();
                                                        }
                                                    },
                                                    style: {
                                                        wordBreak: "break-all"
                                                    },
                                                    children: [
                                                        database.db_name,
                                                        /*#__PURE__*/ jsx_runtime_.jsx("div", {
                                                            className: "absolute -top-4 -right-4",
                                                            children: /*#__PURE__*/ jsx_runtime_.jsx(CopySlug/* default */.Z, {
                                                                slugText: database.db_slug,
                                                                justIcon: true
                                                            })
                                                        })
                                                    ]
                                                })
                                            })
                                        ]
                                    })
                                ]
                            }),
                            /*#__PURE__*/ jsx_runtime_.jsx("div", {
                                className: "w-full md:w-auto",
                                children: /*#__PURE__*/ (0,jsx_runtime_.jsxs)(ButtonGroup/* default */.Z, {
                                    children: [
                                        (!isDelegated || isDelegated && isTableCreatable) && !active_clone_parent_db && !remote_connected && /*#__PURE__*/ (0,jsx_runtime_.jsxs)("a", {
                                            href: `/admin/${user?.id}/databases/${database.db_slug}/tables/add-table`,
                                            className: "button flex items-center gap-2 w-full",
                                            children: [
                                                /*#__PURE__*/ jsx_runtime_.jsx("span", {
                                                    className: "symbol",
                                                    children: "+"
                                                }),
                                                /*#__PURE__*/ jsx_runtime_.jsx("span", {
                                                    children: "Add Table"
                                                })
                                            ]
                                        }),
                                        !isDelegated && /*#__PURE__*/ jsx_runtime_.jsx("a", {
                                            href: `/admin/${user?.id}/databases/${database.db_slug}/users`,
                                            className: "button dark",
                                            children: "Users"
                                        })
                                    ]
                                })
                            })
                        ]
                    }),
                    /*#__PURE__*/ jsx_runtime_.jsx(Breadcrumbs/* default */.Z, {
                        confirmedDelegetedUser: query?.delegated,
                        user: user
                    })
                ]
            }),
            database.active_clone ? /*#__PURE__*/ jsx_runtime_.jsx(ActiveCloneDbBanner/* default */.Z, {
                database: database,
                user: user
            }) : /*#__PURE__*/ jsx_runtime_.jsx(jsx_runtime_.Fragment, {}),
            database.remote_connected ? /*#__PURE__*/ jsx_runtime_.jsx(DatabasesTablesList/* ConnectedDatabaseBanner */.w, {
                database: database
            }) : /*#__PURE__*/ jsx_runtime_.jsx(jsx_runtime_.Fragment, {}),
            /*#__PURE__*/ jsx_runtime_.jsx(TablesList/* default */.Z, {
                database: database,
                tables: tables,
                setTargetTable: setTargetTable,
                confirmedDelegetedUser: confirmedDelegetedUser,
                query: query,
                user: user
            })
        ]
    });
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */ 

// EXTERNAL MODULE: ./components/admin/databases/DeleteTableConfirmationPopup.jsx
var DeleteTableConfirmationPopup = __webpack_require__(1674);
// EXTERNAL MODULE: ./components/general/ExtraContentDatabase.jsx
var ExtraContentDatabase = __webpack_require__(4941);
// EXTERNAL MODULE: ./functions/backend/grabDelegatedUserFromCookie.js
var grabDelegatedUserFromCookie = __webpack_require__(5116);
var grabDelegatedUserFromCookie_default = /*#__PURE__*/__webpack_require__.n(grabDelegatedUserFromCookie);
// 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]/databases/[single]/tables/index.jsx
// @ts-check
/**
 * ==============================================================================
 * Imports
 * ==============================================================================
 */ 

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

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







/** ****************************************************************************** */ /** @type {import("@/package-shared/types").TablesContextType} */ // @ts-ignore
const init = {};
const TablesContext = /*#__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").DSQL_MYSQL_user_databases_Type} props.database
 * @param {import("@/package-shared/types").MYSQL_user_database_tables_table_def[]} props.tables
 * @param {any} props.query
 * @param {any} props.confirmedDelegetedUser
 */ function Tables({ user , database , tables , query , confirmedDelegetedUser ,  }) {
    /**
     * Get Contexts
     *
     * @abstract { React.useContext }
     */ ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Javascript Variables
     *
     * @abstract Non hook variables and functions
     */ const pageTitle = `Tables For ${database.db_name} Database | 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 {[ targetTable: import("@/package-shared/types").MYSQL_user_database_tables_table_def | null, setTargetTable: React.Dispatch<React.SetStateAction<import("@/package-shared/types").MYSQL_user_database_tables_table_def | null>> ]} */ // @ts-ignore
    const [targetTable, setTargetTable] = external_react_default().useState(null);
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Function Return
     *
     * @abstract Main Function Return
     */ return /*#__PURE__*/ jsx_runtime_.jsx(AdminLayout/* default */.Z, {
        head: head,
        user: user,
        extraHeaderContent: /*#__PURE__*/ jsx_runtime_.jsx(ExtraContentDatabase/* default */.Z, {
            database: database,
            query: query,
            confirmedDelegetedUser: confirmedDelegetedUser,
            user: user
        }),
        children: /*#__PURE__*/ (0,jsx_runtime_.jsxs)(TablesContext.Provider, {
            value: {
                user,
                database,
                tables,
                targetTable,
                setTargetTable,
                query,
                confirmedDelegetedUser
            },
            children: [
                /*#__PURE__*/ jsx_runtime_.jsx(TablesContent, {}),
                /*#__PURE__*/ jsx_runtime_.jsx(DeleteDatabaseConfirmationPopup/* default */.Z, {
                    targetDatabase: database
                }),
                /*#__PURE__*/ jsx_runtime_.jsx(DeleteTableConfirmationPopup/* default */.Z, {
                    database: database,
                    targetTable: targetTable
                })
            ]
        })
    });
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
}
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
 * ==============================================================================
 * 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: "/login",
                permanent: false
            }
        };
    }
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Check delegated user token
     *
     * @description Check delegated user token
     */ const dbUserData = await grabDelegatedUserFromCookie_default()({
        request: req,
        user: user,
        databaseSlug: query.single?.toString() || "",
        query
    });
    const dbUserDataObj = dbUserData;
    if (!dbUserDataObj) {
        return {
            redirect: {
                destination: `/admin/${user?.id}/databases`,
                permanent: false
            }
        };
    }
    const { dbUserId , rootUserId  } = dbUserDataObj;
    /**
     * Page/Site Data Data Fetching
     *
     * @description Fetch data on the server before returning
     */ const database = await DB_HANDLER_default()(`SELECT * FROM user_databases WHERE user_id='${dbUserId}' AND db_slug='${query.single}'`);
    if (!database || !database[0]) {
        return {
            redirect: {
                destination: `/admin/${user?.id}/databases`,
                permanent: false
            }
        };
    }
    const tables = rootUserId ? await DB_HANDLER_default()(`
            SELECT 
            delegated_user_tables.database,delegated_user_tables.table,user_database_tables.*
            FROM 
            delegated_user_tables INNER JOIN user_database_tables ON delegated_user_tables.root_user_id=user_database_tables.user_id AND delegated_user_tables.table=user_database_tables.table_slug AND delegated_user_tables.database=user_database_tables.db_slug
            WHERE 
            delegated_user_tables.delegated_user_id='${user.id}' AND delegated_user_tables.root_user_id='${rootUserId}' AND delegated_user_tables.database='${database[0].db_slug}'
        `) : await DB_HANDLER_default()(`SELECT * FROM user_database_tables WHERE user_id='${user.id}' AND db_id='${database[0].id}'`);
    if (!tables || !tables[0]) {
        return {
            redirect: {
                destination: `/admin/${user?.id}/databases/${database[0].db_slug}`,
                permanent: false
            }
        };
    }
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Confirm delegated User
     *
     * @description Confirm delegated User
     */ let confirmedDelegetedUser = dbUserData;
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Server props return
     *
     * @description Return data fetched on the server side
     */ return {
        props: {
            user: user,
            database: database[0],
            tables: tables,
            query,
            confirmedDelegetedUser
        }
    };
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
}


/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

/***/ 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,4941,5116,8345,4986,8264,1500,1674], () => (__webpack_exec__(6522)));
module.exports = __webpack_exports__;

})();