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

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

/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "Z": () => (/* binding */ DeleteTableConfirmationPopup)
/* 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_frontend_fetchApi__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(6729);
/* harmony import */ var _general_Breadcrumbs__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(424);
/* harmony import */ var _general_GeneralPopup__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(5472);
/* harmony import */ var _components_general_LoadingBlock__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(5264);
// @ts-check
/**
 * ==============================================================================
 * Imports
 * ==============================================================================
 */ 





/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
 * ==============================================================================
 * Main Component { Functional }
 * ==============================================================================
 * @param {Object} props - Server props
 * @param {import("@/package-shared/types").DSQL_MYSQL_user_databases_Type} props.database
 * @param {import("@/package-shared/types").MYSQL_user_database_tables_table_def | null} [props.targetTable]
 */ function DeleteTableConfirmationPopup({ targetTable , database ,  }) {
    /**
     * Get Contexts
     *
     * @abstract { React.useContext }
     */ ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Javascript Variables
     *
     * @abstract Non hook variables and functions
     */ ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * React Hooks
     *
     * @abstract { useState, useEffect, useRef, etc ... }
     */ const [loading, setLoading] = react__WEBPACK_IMPORTED_MODULE_1___default().useState(false);
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Function Return
     *
     * @abstract Main Function Return
     */ return /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(_general_GeneralPopup__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .ZP, {
        title: "delete-table-confirmation",
        children: [
            loading && /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_general_LoadingBlock__WEBPACK_IMPORTED_MODULE_4__/* ["default"] */ .Z, {
                width: "20px"
            }),
            /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("h4", {
                className: "m-0",
                children: [
                    "Delete '",
                    targetTable?.table_name ? targetTable.table_name : "This Database",
                    "' Table?"
                ]
            }),
            /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
                children: [
                    /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("button", {
                        className: "outlined" + (loading ? " pointer-events-none opacity-40" : ""),
                        onClick: (e)=>{
                            setLoading(true);
                            (0,_functions_frontend_fetchApi__WEBPACK_IMPORTED_MODULE_5__/* ["default"] */ .Z)("/api/deleteUserTable", {
                                method: "post",
                                body: {
                                    database: database,
                                    table: targetTable
                                }
                            }, true).then((res)=>{
                                if (res.success) {
                                    window.location.reload();
                                }
                            });
                        },
                        children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("span", {
                            children: "Yes"
                        })
                    }),
                    /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("button", {
                        onClick: (e)=>{
                            (0,_general_GeneralPopup__WEBPACK_IMPORTED_MODULE_3__/* .closePopup */ .j4)();
                        },
                        children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("span", {
                            children: "Cancel"
                        })
                    })
                ]
            })
        ]
    });
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */ 


/***/ }),

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

/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "Z": () => (/* binding */ grabTableSchemaData)
/* harmony export */ });
/* harmony import */ var http__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(3685);
/* harmony import */ var http__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(http__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _serverError__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2317);
/* harmony import */ var _serverError__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_serverError__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(9395);
/* harmony import */ var _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var _grabDelegatedUserFromCookie__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(5116);
/* harmony import */ var _grabDelegatedUserFromCookie__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_grabDelegatedUserFromCookie__WEBPACK_IMPORTED_MODULE_3__);
/* harmony import */ var _grabUserSchemaData__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(2527);
/* harmony import */ var _package_shared_functions_backend_varDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(1206);
/* harmony import */ var _package_shared_functions_backend_varDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_varDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_5__);
// @ts-check






/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
 * @typedef {object} grabTableSchemaDataReturn
 * @property {import("@/package-shared/types").DSQL_MYSQL_user_databases_Type} [database]
 * @property {import("@/package-shared/types").DSQL_TableSchemaType} [table]
 * @property {import("@/package-shared/types").MYSQL_user_database_tables_table_def} [props.tableRecord]
 * @property {import("@/package-shared/types").DSQL_DatabaseSchemaType[]} [props.dbSchemaData]
 * @property {any[]} [props.entries]
 * @property {any} [props.query]
 * @property {any} [props.confirmedDelegetedUser]
 * @property {number} [props.entriesCount]
 */ /**
 * @param {object} params
 * @param {http.IncomingMessage & { cookies: import("next/dist/server/api-utils").NextApiRequestCookies }} params.req - Database name slug
 * @param {{ id: number, first_name: string, last_name: string }} params.user - user object
 * @param {any} params.query - query params
 *
 * @returns {Promise<grabTableSchemaDataReturn | null>} new user auth object payload
 */ async function grabTableSchemaData({ req , user , query  }) {
    try {
        /**
         * Check delegated user token
         *
         * @description Check delegated user token
         */ const dbUserData = await _grabDelegatedUserFromCookie__WEBPACK_IMPORTED_MODULE_3___default()({
            request: req,
            user: user,
            databaseSlug: query.single,
            query
        });
        const dbUserDataObj = dbUserData;
        if (!dbUserDataObj) {
            return null;
        }
        const { dbUserId  } = dbUserDataObj;
        /**
         * Page/Site Data Data Fetching
         *
         * @description Fetch data on the server before returning
         */ const database = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_2___default()(`SELECT * FROM user_databases WHERE user_id='${dbUserId}' AND db_slug='${query.single}'`);
        if (!database?.[0]) {
            return null;
        }
        ////////////////////////////////////////
        ////////////////////////////////////////
        ////////////////////////////////////////
        /**
         * Confirm delegated User
         *
         * @description Confirm delegated User
         */ let confirmedDelegetedUser = dbUserData;
        ////////////////////////////////////////
        ////////////////////////////////////////
        ////////////////////////////////////////
        /**
         * Page/Site Data Data Fetching
         *
         * @description Fetch data on the server before returning
         */ let dbSchemaData = (0,_grabUserSchemaData__WEBPACK_IMPORTED_MODULE_4__/* ["default"] */ .Z)({
            userId: dbUserId
        });
        if (!dbSchemaData) {
            throw new Error("DB Schema not found!");
        }
        /** @type {import("@/package-shared/types").DSQL_TableSchemaType[]| undefined} */ const tables = dbSchemaData.filter((db)=>db.dbFullName === database[0].db_full_name)[0]?.tables;
        const targetTable = tables?.filter((table)=>table.tableName === query.single_table)[0];
        const targetTableRecord = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_2___default()(`SELECT * FROM user_database_tables WHERE user_id='${dbUserId}' AND db_id='${database[0].id}' AND table_slug='${query.single_table}'`);
        const tableEntries = await _package_shared_functions_backend_varDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_5___default()({
            database: database[0].db_full_name,
            queryString: `SELECT * FROM ${targetTable?.tableName} ORDER BY id DESC LIMIT 10`,
            tableSchema: targetTable
        });
        const tableEntriesCount = await _package_shared_functions_backend_varDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_5___default()({
            database: database[0].db_full_name,
            queryString: `SELECT COUNT(id) AS count FROM ${targetTable?.tableName}`,
            tableSchema: targetTable
        });
        ////////////////////////////////////////
        ////////////////////////////////////////
        ////////////////////////////////////////
        if (confirmedDelegetedUser.rootUserId) {
            const filteredDbSchema = dbSchemaData.filter((db)=>db.dbFullName == database[0].db_full_name);
            let targetFilteredDb = filteredDbSchema[0];
            const filteredTables = targetFilteredDb.tables.filter(// @ts-ignore
            (tbl)=>tbl.tableName === targetTable?.tableName);
            targetFilteredDb.tables = filteredTables;
            dbSchemaData = [
                targetFilteredDb
            ];
        }
        ////////////////////////////////////////
        ////////////////////////////////////////
        ////////////////////////////////////////
        /**
         * Server props return
         *
         * @description Return data fetched on the server side
         */ return {
            confirmedDelegetedUser: confirmedDelegetedUser || null,
            database: database[0] || null,
            dbSchemaData: dbSchemaData || null,
            entries: tableEntries || null,
            entriesCount: tableEntriesCount?.[0]?.count || 0,
            query,
            table: targetTable,
            tableRecord: targetTableRecord[0] || {}
        };
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    } catch (/** @type {any} */ error) {
        _serverError__WEBPACK_IMPORTED_MODULE_1___default()({
            component: "[single_table]/index-page-component/getServerSideProps/catch-error]",
            message: error.message,
            user: user
        });
        return {};
    }
} ////////////////////////////////////////
 ////////////////////////////////////////
 ////////////////////////////////////////


/***/ }),

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

/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "Z": () => (/* binding */ updateTableAfterFieldsUpdateFunctionExt)
/* harmony export */ });
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6517);
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _fetchApi__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6729);
// @ts-check
/**
 * ==============================================================================
 * Imports
 * ==============================================================================
 */ 

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/**
 * ==============================================================================
 * Auth user on client side
 * ==============================================================================
 * @param {object} params - Single object parameters
 * @param {{delegated: boolean}} [params.query] - Query object
 * @param {import("@/package-shared/types").DSQL_TableSchemaType} params.table - Target table object
 * @param {import("@/package-shared/types").DSQL_MYSQL_user_databases_Type} params.database - Target MYSQL database record object
 * @param {import("@/package-shared/types").DSQL_DatabaseSchemaType[]} params.dbSchemaData - DSQL db schema
 * @param {import("@/package-shared/types").DSQL_FieldSchemaType[]} [params.tableFields] - Table Fields
 * @param {import("@/package-shared/types").DSQL_IndexSchemaType[]} [params.tableIndexes] - Table INdexes
 * @param {React.Dispatch<React.SetStateAction<boolean>>} [params.setLoading]
 */ function updateTableAfterFieldsUpdateFunctionExt({ query , table , database , dbSchemaData , tableFields , tableIndexes , setLoading ,  }) {
    /**
     * @description Initialize
     */ let newDbSchemaData = [
        ...dbSchemaData
    ];
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    try {
        const dbIndex = newDbSchemaData.findIndex((db)=>db.dbFullName === database.db_full_name);
        const targetDb = newDbSchemaData[dbIndex];
        const targetTableIndex = targetDb.tables.findIndex((_table)=>_table.tableName === table.tableName);
        newDbSchemaData[dbIndex].tables[targetTableIndex].fields = tableFields ? lodash__WEBPACK_IMPORTED_MODULE_0__.cloneDeep(tableFields) : [];
        newDbSchemaData[dbIndex].tables[targetTableIndex].indexes = tableIndexes ? lodash__WEBPACK_IMPORTED_MODULE_0__.cloneDeep(tableIndexes) : [];
        const tempField = newDbSchemaData[dbIndex].tables[targetTableIndex].fields.find((fld)=>fld.newTempField);
        if (tempField) {
            window.alert("Please resolve all open fields before you save");
            setTimeout(()=>{
                setLoading?.(false);
            }, 1000);
            return;
        }
        (0,_fetchApi__WEBPACK_IMPORTED_MODULE_1__/* ["default"] */ .Z)("/api/updateDbSchemaDataForUser", {
            method: "post",
            body: {
                schema: newDbSchemaData,
                database: database.db_slug,
                table: table,
                delegated: query?.delegated
            }
        }, true).then((res)=>{
            if (res.success) {
                window.location.reload();
            } else {
                window.alert(res.msg || "Operation Failed. Please check permissions.");
            }
        }).finally(()=>{
            if (setLoading) {
                setTimeout(()=>{
                    setLoading(false);
                }, 1000);
            }
        });
    } catch (/** @type {any} */ error) {
        window.alert(error.message);
        setTimeout(()=>{
            setLoading?.(false);
        }, 1000);
        return;
    }
} ////////////////////////////////////////
 ////////////////////////////////////////
 ////////////////////////////////////////


/***/ }),

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

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

// EXPORTS
__webpack_require__.d(__webpack_exports__, {
  "TableFieldsContext": () => (/* binding */ TableFieldsContext),
  "default": () => (/* binding */ TableFieldsPage),
  "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/DeleteTableConfirmationPopup.jsx
var DeleteTableConfirmationPopup = __webpack_require__(1674);
// EXTERNAL MODULE: ./components/general/ExtraContentDatabase.jsx
var ExtraContentDatabase = __webpack_require__(4941);
// 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/TableFields.jsx + 7 modules
var TableFields = __webpack_require__(4893);
// EXTERNAL MODULE: ./components/general/ActiveCloneDbBanner.jsx
var ActiveCloneDbBanner = __webpack_require__(4986);
// EXTERNAL MODULE: ./components/general/ActiveCloneTableBanner.jsx
var ActiveCloneTableBanner = __webpack_require__(8515);
// EXTERNAL MODULE: ./components/admin/databases/DatabasesTablesList.jsx
var DatabasesTablesList = __webpack_require__(8264);
;// CONCATENATED MODULE: ./components/admin/databases/TableFieldsContent.jsx
// @ts-check
/**
 * ==============================================================================
 * Imports
 * ==============================================================================
 */ 









/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
 * ==============================================================================
 * Main Component { Functional }
 * ==============================================================================
 * @param {Object} props - Server props
 */ function TableFieldsContent(props) {
    /**
     * Get Contexts
     *
     * @abstract { React.useContext }
     */ const { user , database , table , tableFields , setTableFields , setTargetField , refreshFieldsListRef , updateTableAfterFieldsUpdateFunction , query , confirmedDelegetedUser ,  } = external_react_default().useContext(TableFieldsContext);
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * 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 cloneParentDb = table?.childTable ? table.childTableDbFullName?.replace(new RegExp(/datasquirel_user_\d+_/), "") : null;
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * 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__*/ (0,jsx_runtime_.jsxs)("h1", {
                                        className: "text-3xl m-0",
                                        children: [
                                            /*#__PURE__*/ jsx_runtime_.jsx("span", {
                                                children: "All Fields in"
                                            }),
                                            /*#__PURE__*/ jsx_runtime_.jsx("div", {
                                                className: "inline relative",
                                                children: /*#__PURE__*/ (0,jsx_runtime_.jsxs)("a", {
                                                    href: `/admin/${user?.id}/databases/${database.db_slug}/tables/${table.tableName}`,
                                                    className: "p-2 bg-white dark:bg-slate-800 rounded border border-solid border-slate-200 dark:border-slate-600 ml-2 text-primary hover:text-primary_dark relative",
                                                    onClick: (e)=>{
                                                        /** @type {HTMLAnchorElement} */ // @ts-ignore
                                                        const linkEl = e.target;
                                                        if (linkEl.closest(".copy-slug-span")) {
                                                            e.preventDefault();
                                                        }
                                                    },
                                                    children: [
                                                        table.tableFullName,
                                                        /*#__PURE__*/ jsx_runtime_.jsx("div", {
                                                            className: "absolute -top-4 -right-4",
                                                            children: /*#__PURE__*/ jsx_runtime_.jsx(CopySlug/* default */.Z, {
                                                                slugText: table.tableName,
                                                                justIcon: true
                                                            })
                                                        })
                                                    ]
                                                })
                                            }),
                                            /*#__PURE__*/ jsx_runtime_.jsx("span", {
                                                className: "ml-2",
                                                children: "Table"
                                            })
                                        ]
                                    })
                                ]
                            }),
                            /*#__PURE__*/ jsx_runtime_.jsx("div", {
                                children: /*#__PURE__*/ (0,jsx_runtime_.jsxs)("a", {
                                    href: `/admin/${user?.id}/databases/${database.db_slug}/tables/${table.tableName}/entries/add-entry`,
                                    className: "button flex items-center gap-2",
                                    children: [
                                        /*#__PURE__*/ jsx_runtime_.jsx("span", {
                                            className: "symbol",
                                            children: "+"
                                        }),
                                        /*#__PURE__*/ jsx_runtime_.jsx("span", {
                                            children: "Add New Table Entry"
                                        })
                                    ]
                                })
                            })
                        ]
                    }),
                    /*#__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(ActiveCloneTableBanner/* default */.Z, {
                table: table,
                database: database,
                user: user
            }),
            /*#__PURE__*/ jsx_runtime_.jsx(TableFields/* default */.Z, {
                user: user,
                tableFields: tableFields,
                setTableFields: setTableFields,
                setTargetField: setTargetField,
                refreshFieldsListRef: refreshFieldsListRef,
                updateTable: true,
                updateTableAfterFieldsUpdateFunction: updateTableAfterFieldsUpdateFunction,
                database: database,
                confirmedDelegetedUser: confirmedDelegetedUser,
                query: query,
                table: table
            })
        ]
    });
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */ 

// EXTERNAL MODULE: ./functions/frontend/updateTableAfterFieldsUpdateFunctionExt.js
var updateTableAfterFieldsUpdateFunctionExt = __webpack_require__(8382);
// EXTERNAL MODULE: ./functions/backend/serverError.js
var serverError = __webpack_require__(2317);
var serverError_default = /*#__PURE__*/__webpack_require__.n(serverError);
// EXTERNAL MODULE: ./functions/backend/grabTableSchemaData.js
var grabTableSchemaData = __webpack_require__(7809);
;// CONCATENATED MODULE: ./pages/admin/[user_id]/databases/[single]/tables/[single_table]/fields.jsx
// @ts-check
/**
 * ==============================================================================
 * Imports
 * ==============================================================================
 */ 

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

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







/** ****************************************************************************** */ /** @type {import("@/package-shared/types").FieldsContextType} */ // @ts-ignore
const init = {};
const TableFieldsContext = /*#__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").DSQL_TableSchemaType} props.table
 * @param {import("@/package-shared/types").DSQL_DatabaseSchemaType[]} props.dbSchemaData
 * @param {any} props.query
 * @param {any} props.confirmedDelegetedUser
 */ function TableFieldsPage({ user , database , table , dbSchemaData , query , confirmedDelegetedUser ,  }) {
    /**
     * Get Contexts
     *
     * @abstract { React.useContext }
     */ ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Javascript Variables
     *
     * @abstract Non hook variables and functions
     */ const pageTitle = `${table.tableFullName} Table | Datasquirel`;
    const pageDescription = "Single Table";
    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 {[ tableFields: import("@/package-shared/types").DSQL_FieldSchemaType[], setTableFields: React.Dispatch<React.SetStateAction<import("@/package-shared/types").DSQL_FieldSchemaType[]>> ]} */ // @ts-ignore
    const [tableFields, setTableFields] = external_react_default().useState(table.fields);
    /** @type {[ targetField: import("@/package-shared/types").DSQL_FieldSchemaType | null, setTargetField: React.Dispatch<React.SetStateAction<import("@/package-shared/types").DSQL_FieldSchemaType | null>> ]} */ // @ts-ignore
    const [targetField, setTargetField] = external_react_default().useState(null);
    /** @type {React.MutableRefObject<React.Dispatch<React.SetStateAction<number>> | undefined>} */ const refreshFieldsListRef = external_react_default().useRef();
    // const targetFieldIndex = targetField ? tableFields.findIndex((field) => field.fieldName === targetField.fieldName) : 1;
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     *
     * @param {React.Dispatch<React.SetStateAction<boolean>>} [setLoading]
     */ function updateTableAfterFieldsUpdateFunction(setLoading) {
        (0,updateTableAfterFieldsUpdateFunctionExt/* default */.Z)({
            query,
            table,
            database,
            dbSchemaData,
            tableFields,
            tableIndexes: table.indexes,
            setLoading
        });
    }
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * 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)(TableFieldsContext.Provider, {
            value: {
                user,
                database,
                table,
                dbSchemaData,
                targetField,
                setTargetField,
                refreshFieldsListRef,
                tableFields,
                setTableFields,
                updateTableAfterFieldsUpdateFunction,
                query,
                confirmedDelegetedUser
            },
            children: [
                /*#__PURE__*/ jsx_runtime_.jsx(TableFieldsContent, {}),
                /*#__PURE__*/ jsx_runtime_.jsx(DeleteTableConfirmationPopup/* default */.Z, {
                    database: database
                })
            ]
        })
    });
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
}
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
 * ==============================================================================
 * 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
            }
        };
    }
    try {
        /**
         * Check delegated user token
         *
         * @description Check delegated user token
         */ const data = await (0,grabTableSchemaData/* default */.Z)({
            req,
            query,
            user
        });
        if (!data || !data?.table) {
            throw new Error("Data Fetching Error!");
        }
        ////////////////////////////////////////
        ////////////////////////////////////////
        ////////////////////////////////////////
        /**
         * Server props return
         *
         * @description Return data fetched on the server side
         */ return {
            props: {
                user: user,
                ...data
            }
        };
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    } catch (/** @type {any} */ error) {
        serverError_default()({
            component: "fields-page-component/getServerSideProps/catch-error",
            message: error.message,
            user: user
        });
        return {
            // redirect: {
            //     destination: "/login",
            //     permanent: false
            // },
            props: {
                user: user,
                database: null,
                table: null
            }
        };
    }
}


/***/ }),

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

/***/ }),

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

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

/***/ }),

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

/***/ }),

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

module.exports = require("gsap");

/***/ }),

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

module.exports = require("gsap/Flip");

/***/ }),

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

module.exports = require("lodash");

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

module.exports = require("react");

/***/ }),

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

module.exports = require("react-dom/client");

/***/ }),

/***/ 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,4941,7023,7901,8682,2317,1206,5116,8345,4986,9594,8264,9471,9967,464,8515,3314,4893], () => (__webpack_exec__(325)));
module.exports = __webpack_exports__;

})();