"use strict";
(() => {
var exports = {};
exports.id = 8848;
exports.ids = [8848,372,8105,133,4135,8515,3314,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"
                        })
                    })
                ]
            })
        ]
    });
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */ 


/***/ }),

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

/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "Z": () => (/* binding */ ActiveCloneTableBanner)
/* 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 _mui_icons_material_MenuBookTwoTone__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(5557);
/* harmony import */ var _mui_icons_material_MenuBookTwoTone__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_mui_icons_material_MenuBookTwoTone__WEBPACK_IMPORTED_MODULE_2__);
// @ts-check
/**
 * ==============================================================================
 * Imports
 * ==============================================================================
 */ 


/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
 * ==============================================================================
 * Main Component { Functional }
 * ==============================================================================
 * @param {Object} props
 * @param {import("@/package-shared/types").DSQL_TableSchemaType} props.table
 * @param {import("@/package-shared/types").DSQL_MYSQL_user_databases_Type} props.database
 * @param {number} [props.activeDbClone]
 * @param {import("@/package-shared/types").UserType} props.user
 */ function ActiveCloneTableBanner({ table , database , user , activeDbClone ,  }) {
    /**
     * Get Contexts
     *
     * @abstract { React.useContext }
     */ ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Javascript Variables
     *
     * @abstract Non hook variables and functions
     */ const cloneParentDb = table?.childTableDbFullName ? table.childTableDbFullName.replace(new RegExp(/datasquirel_user_\d+_/), "") : null;
    const isCurrentDb = table.childTableDbFullName === database.db_full_name;
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * React Hooks
     *
     * @abstract { useState, useEffect, useRef, etc ... }
     */ ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Function Return
     *
     * @abstract Main Function Return
     */ if (!cloneParentDb) return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx((react__WEBPACK_IMPORTED_MODULE_1___default().Fragment), {});
    return /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("span", {
        className: "info small green gap-1" + (database?.active_clone ? " -mt-6" : ""),
        style: {
            fontWeight: "500"
        },
        children: [
            "This Table is an active clone of",
            " ",
            /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("a", {
                href: `/admin/${user?.id}/databases/${cloneParentDb}/tables/${table.childTableName}`,
                target: "_blank",
                className: "button gray outlined small-text",
                style: {
                    display: "inline-block",
                    fontSize: "12px",
                    padding: "3px 7px"
                },
                children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("b", {
                    children: table.childTableName
                })
            }),
            " ",
            "in",
            " ",
            isCurrentDb ? /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("span", {
                children: [
                    "this current database(",
                    /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("b", {
                        children: database.db_name
                    }),
                    ")."
                ]
            }) : /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)((react__WEBPACK_IMPORTED_MODULE_1___default().Fragment), {
                children: [
                    /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("a", {
                        href: `/admin/${user?.id}/databases/${cloneParentDb}`,
                        target: "_blank",
                        className: "button gray outlined small-text",
                        style: {
                            display: "inline-block",
                            fontSize: "12px",
                            padding: "3px 7px"
                        },
                        children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("b", {
                            children: cloneParentDb
                        })
                    }),
                    /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("span", {
                        children: "database."
                    })
                ]
            }),
            " ",
            database?.active_clone ? "" : "Only Foreign keys and Entries can be updated."
        ]
    });
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
}


/***/ }),

/***/ 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 {};
    }
} ////////////////////////////////////////
 ////////////////////////////////////////
 ////////////////////////////////////////


/***/ }),

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

/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "Z": () => (/* binding */ grabUserSchemaData)
/* harmony export */ });
// @ts-check
const serverError = __webpack_require__(2317);
const fs = __webpack_require__(7147);
const path = __webpack_require__(1017);
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
 * ==============================================================================
 * @param {Object} params
 * @param {string | number} params.userId
 * @returns {import("@/package-shared/types").DSQL_DatabaseSchemaType[] | null}
 */ function grabUserSchemaData({ userId  }) {
    try {
        const userSchemaFilePath = path.resolve(process.cwd(), `${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${userId}/main.json`);
        const userSchemaData = JSON.parse(fs.readFileSync(userSchemaFilePath, "utf-8"));
        return userSchemaData;
    } catch (/** @type {any} */ error) {
        serverError({
            component: "/functions/backend/grabUserSchemaData",
            message: error.message
        });
        return null;
    }
} /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */ 


/***/ }),

/***/ 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;
    }
} ////////////////////////////////////////
 ////////////////////////////////////////
 ////////////////////////////////////////


/***/ }),

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

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

// EXPORTS
__webpack_require__.d(__webpack_exports__, {
  "SingleTableContext": () => (/* binding */ SingleTableContext),
  "default": () => (/* binding */ SingleTable),
  "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: ./functions/frontend/fetchApi.js
var fetchApi = __webpack_require__(6729);
// 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/general/LoadingBlock.jsx
var LoadingBlock = __webpack_require__(5264);
// EXTERNAL MODULE: ./components/admin/databases/TableEntriesList.jsx + 1 modules
var TableEntriesList = __webpack_require__(6122);
// EXTERNAL MODULE: ./components/admin/databases/TableFields.jsx + 7 modules
var TableFields = __webpack_require__(4893);
;// CONCATENATED MODULE: ./functions/frontend/addNewTemplateIndex.js
// @ts-check
/**
 * ==============================================================================
 * Imports
 * ==============================================================================
 */ 
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
 * ==============================================================================
 * Auth user on client side
 * ==============================================================================
 * @param {object} params
 * @param {import("@/package-shared/types").DSQL_IndexSchemaType[]} params.tableIndexes
 * @param {React.Dispatch<React.SetStateAction<import("@/package-shared/types").DSQL_IndexSchemaType[]>>} params.setTableIndexes
 * @param {React.Dispatch<React.SetStateAction<number>>} [params.setRefresh]
 * @param {React.Dispatch<React.SetStateAction<number>>} [params.setPageRefresh]
 *
 * @requires search-field name attribute
 */ function addNewTemplateIndex({ tableIndexes , setTableIndexes , setRefresh , setPageRefresh ,  }) {
    /**
     * Check for user in local storage
     *
     * @description Preventdefault, declare variables
     */ let newArray = tableIndexes && tableIndexes[0] ? tableIndexes : [];
    newArray.push({
        newTempIndex: true
    });
    setTableIndexes(newArray);
    // setRefresh && setRefresh((prev) => prev + 1);
    // setPageRefresh && setPageRefresh((prev) => prev + 1);
    if (setRefresh) setRefresh((prev)=>prev + 1);
} ////////////////////////////////////////
 ////////////////////////////////////////
 ////////////////////////////////////////

;// CONCATENATED MODULE: ./functions/frontend/addNewIndex.js
// @ts-check
/** # MODULE TRACE 
======================================================================
 * Detected 1 files that call this module. The files are listed below:
======================================================================
 * `import` Statement Found in [NewIndexFieldTemp.jsx] => file:///d:\GitHub\datasquirel\components\admin\databases\NewIndexFieldTemp.jsx
==== MODULE TRACE END ==== */ /**
 * ==============================================================================
 * Imports
 * ==============================================================================
 */ 
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
 * ==============================================================================
 * Auth user on client side
 * ==============================================================================
 * @param {object} params
 * @param {number} params.fieldIndex
 * @param {React.Dispatch<React.SetStateAction<import("@/package-shared/types").DSQL_IndexSchemaType[]>>} params.setTableIndexes
 * @param {React.Dispatch<React.SetStateAction<number>>} params.setRefresh
 * @param {import("@/package-shared/types").DSQL_IndexSchemaType} params.payload
 * @requires search-field name attribute
 */ function addNewIndex({ fieldIndex , setTableIndexes , setRefresh , payload ,  }) {
    /**
     * Check for user in local storage
     *
     * @description Preventdefault, declare variables
     */ setTableIndexes((prev)=>{
        let newArray = prev;
        newArray.splice(fieldIndex, 1, payload);
        return newArray;
    });
    // setRefresh && setRefresh((prev) => prev + 1);
    // setPageRefresh && setPageRefresh((prev) => prev + 1);
    if (setRefresh) setRefresh((prev)=>prev + 1);
} ////////////////////////////////////////
 ////////////////////////////////////////
 ////////////////////////////////////////

// EXTERNAL MODULE: external "lodash"
var external_lodash_ = __webpack_require__(6517);
var external_lodash_default = /*#__PURE__*/__webpack_require__.n(external_lodash_);
;// CONCATENATED MODULE: ./components/admin/databases/NewIndexFieldTemp.jsx
// @ts-check
/** # MODULE TRACE 
======================================================================
 * Detected 1 files that call this module. The files are listed below:
======================================================================
 * `import` Statement Found in [TableIndexes.jsx] => file:///d:\GitHub\datasquirel\components\admin\databases\TableIndexes.jsx
==== MODULE TRACE END ==== */ /**
 * ==============================================================================
 * Imports
 * ==============================================================================
 */ 




/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
 * ==============================================================================
 * Main Component { Functional }
 * ==============================================================================
 * @param {Object} props - Server props
 * @param {import("@/package-shared/types").DSQL_IndexSchemaType} [props.tableIndex]
 * @param {number} props.fieldIndex
 * @param {import("@/package-shared/types").DSQL_TableSchemaType} [props.currentTable]
 * @param {import("@/package-shared/types").DSQL_FieldSchemaType[]} props.tableFields
 * @param {import("@/package-shared/types").DSQL_IndexSchemaType[]} [props.tableIndexes]
 * @param {React.Dispatch<React.SetStateAction<import("@/package-shared/types").DSQL_IndexSchemaType[]>>} props.setTableIndexes
 * @param {React.Dispatch<React.SetStateAction<number>>} props.setRefresh
 * @param {import("@/package-shared/types").UserType} props.user
 * @param {string|number} props.tableUniqueId
 */ function NewIndexFieldTemp({ tableIndex , fieldIndex , currentTable , tableFields , tableIndexes , setTableIndexes , setRefresh , user , tableUniqueId ,  }) {
    /**
     * Get Contexts
     *
     * @abstract { React.useContext }
     */ ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Javascript Variables
     *
     * @abstract Non hook variables and functions
     */ const columnDesc = "Select Columns to be indexed. NB the order matters";
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * React Hooks
     *
     * @abstract { useState, useEffect, useRef, etc ... }
     */ const [indexType, setIndexType] = external_react_default().useState("regular");
    /** @type {any} */ const indexTableFieldsState = external_react_default().useState(0);
    /** @type {[ indexTableFields: import("@/package-shared/types").DSQL_IndexTableFieldType[], setIndexTableFields: React.Dispatch<React.SetStateAction<import("@/package-shared/types").DSQL_IndexTableFieldType[]>> ]} */ const [indexTableFields, setIndexTableFields] = indexTableFieldsState;
    /** @type {React.LegacyRef<HTMLElement | undefined>} */ const newFieldRef = external_react_default().useRef();
    external_react_default().useEffect(()=>{
        newFieldRef.current?.scrollIntoView({
            block: "center",
            behavior: "smooth"
        });
        newFieldRef.current?.querySelector("input")?.focus();
    }, []);
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Function Return
     *
     * @abstract Main Function Return
     */ return /*#__PURE__*/ jsx_runtime_.jsx("div", {
        className: "w-full mt-1 xl:flex-nowrap flex-wrap",
        // @ts-ignore
        ref: newFieldRef,
        children: /*#__PURE__*/ (0,jsx_runtime_.jsxs)("form", {
            className: "flex flex-row items-start gap-4 w-full justify-between border border-solid p-4 pt-6 border-slate-400 rounded focus:shadow-lg shadow-slate-700/40 relative flex-wrap xl:flex-nowrap shadow-xl",
            onSubmit: (e)=>{
                e.preventDefault();
                /** @type {HTMLFormElement} */ // @ts-ignore
                const formEl = e.target;
                let new_index_name = formEl["new_index_name"].value.replace(/_index/, "").replace(/_{1,}$/, "") + "_index";
                if (!indexTableFields || !indexTableFields[0]) {
                    alert("Please Select at least 1 table column name");
                    return;
                }
                /** @type {import("@/package-shared/types").DSQL_IndexSchemaType} */ let newIndexObject = {
                    indexType: indexType,
                    indexName: new_index_name,
                    indexTableFields,
                    alias: tableUniqueId + "_" + new_index_name
                };
                addNewIndex({
                    fieldIndex,
                    setTableIndexes,
                    payload: newIndexObject,
                    setRefresh
                });
            },
            children: [
                /*#__PURE__*/ jsx_runtime_.jsx("span", {
                    className: "absolute -top-2 text-sm bg-fuchsia-600 text-white px-2 rounded-full",
                    children: "New Index"
                }),
                /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                    className: "gap-4 flex-wrap xl:flex-nowrap flex-col xl:flex-row items-stretch w-full",
                    children: [
                        /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                            className: "flex flex-col items-start gap-0.5",
                            style: {
                                minWidth: "70px"
                            },
                            children: [
                                /*#__PURE__*/ jsx_runtime_.jsx("label", {
                                    htmlFor: "new_field_required",
                                    children: "Type"
                                }),
                                /*#__PURE__*/ jsx_runtime_.jsx("select", {
                                    name: "new_field_required",
                                    id: "new_field_required",
                                    className: "px-2",
                                    onChange: (e)=>{
                                        setIndexType(e.target.value);
                                    },
                                    children: indexType?.match(/regular/i) ? /*#__PURE__*/ jsx_runtime_.jsx("option", {
                                        value: "regular",
                                        children: "Default"
                                    }) : /*#__PURE__*/ jsx_runtime_.jsx("option", {
                                        value: "fullText",
                                        children: "Full Text"
                                    })
                                })
                            ]
                        }),
                        /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                            className: "flex flex-col items-start gap-0.5",
                            children: [
                                /*#__PURE__*/ jsx_runtime_.jsx("label", {
                                    htmlFor: "new_index_name",
                                    children: "Index Name"
                                }),
                                /*#__PURE__*/ jsx_runtime_.jsx("input", {
                                    type: "text",
                                    name: "new_index_name",
                                    id: "new_index_name",
                                    placeholder: "Eg. title_index",
                                    onInput: async (e)=>{
                                        /** @type {HTMLInputElement} */ // @ts-ignore
                                        const inputEl = e.target;
                                        inputEl.value = inputEl.value.toLowerCase().replace(/ /g, "_");
                                    },
                                    required: true
                                })
                            ]
                        }),
                        /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                            className: "flex flex-col items-start gap-4 xl:gap-0.5",
                            children: [
                                /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                                    className: "items-start",
                                    children: [
                                        /*#__PURE__*/ jsx_runtime_.jsx("label", {
                                            htmlFor: "new_field_data_type",
                                            children: "Table Column(s)"
                                        }),
                                        /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                                            className: "dropdown-wrapper reversed text-sm items-start gap-2",
                                            children: [
                                                /*#__PURE__*/ jsx_runtime_.jsx("span", {
                                                    className: "px-2 bg-slate-200 dark:bg-slate-700 rounded-full hover:bg-slate-100 dark:hover:bg-slate-600 hidden xl:flex",
                                                    children: "Info"
                                                }),
                                                /*#__PURE__*/ jsx_runtime_.jsx("div", {
                                                    className: "dropdown mt-0 xl:-mt-2",
                                                    children: /*#__PURE__*/ jsx_runtime_.jsx("span", {
                                                        children: columnDesc
                                                    })
                                                })
                                            ]
                                        })
                                    ]
                                }),
                                /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                                    className: "w-auto flex flex-row items-stretch gap-4",
                                    children: [
                                        /*#__PURE__*/ (0,jsx_runtime_.jsxs)("select", {
                                            name: "new_field_data_type",
                                            id: "new_field_data_type",
                                            className: "w-full xl:w-auto",
                                            onChange: (e)=>{
                                                if (e.target.value.match(/--/)) return;
                                                const targetOption = Array.from(e.target.options).filter((option)=>option.value === e.target.value);
                                                const dataType = targetOption[0].dataset.type;
                                                if (dataType?.match(/text/i)) {
                                                    setIndexType("fullText");
                                                    setIndexTableFields([
                                                        {
                                                            value: e.target.value,
                                                            dataType: dataType
                                                        }, 
                                                    ]);
                                                } else {
                                                    try {
                                                        const existingTextDataType = indexTableFields.filter((obj)=>obj.dataType.match(/text/i));
                                                        if (existingTextDataType[0]) throw new Error("TEXT type exists");
                                                        let existingFieldsArray = indexTableFields;
                                                        if (existingFieldsArray.findIndex((obj)=>obj.value === e.target.value) >= 0 || e.target.value.match(/^--$/)) {
                                                            return;
                                                        }
                                                        if (dataType) {
                                                            existingFieldsArray.push({
                                                                value: e.target.value,
                                                                dataType
                                                            });
                                                            setIndexTableFields([
                                                                ...existingFieldsArray, 
                                                            ]);
                                                        } else {
                                                            window.alert("Datatype not provided. Please recheck fields.");
                                                        }
                                                    } catch (/** @type {any} */ error) {
                                                        (0,fetchApi/* default */.Z)("/api/admin/clientError", {
                                                            method: "post",
                                                            body: {
                                                                component: "NewIndexFieldTemp/lines-177-190",
                                                                message: error.message,
                                                                user: user
                                                            }
                                                        });
                                                        if (dataType) {
                                                            setIndexTableFields([
                                                                {
                                                                    value: e.target.value,
                                                                    dataType: dataType
                                                                }, 
                                                            ]);
                                                        } else {
                                                            window.alert("Couldn't set Index Fields");
                                                        }
                                                    }
                                                    setIndexType("regular");
                                                }
                                            },
                                            children: [
                                                /*#__PURE__*/ jsx_runtime_.jsx("option", {
                                                    value: "--",
                                                    children: "--"
                                                }),
                                                tableFields.filter((field)=>!field?.fieldName?.match(/^id$|^date_/) && !field.foreignKey).map((field, index)=>{
                                                    return /*#__PURE__*/ jsx_runtime_.jsx("option", {
                                                        value: field.fieldName,
                                                        "data-type": field.dataType,
                                                        children: field.fieldName
                                                    }, index + 1);
                                                })
                                            ]
                                        }),
                                        indexTableFields && indexTableFields[0] && /*#__PURE__*/ jsx_runtime_.jsx("div", {
                                            className: "px-3 py-1 bg-slate-100 dark:bg-slate-500/10 rounded",
                                            children: indexTableFields.map((field, index)=>{
                                                return /*#__PURE__*/ (0,jsx_runtime_.jsxs)("span", {
                                                    className: "text-sm px-3 py-1 bg-white dark:bg-slate-700 rounded-full shadow-lg font-bold flex items-center justify-center gap-1",
                                                    children: [
                                                        /*#__PURE__*/ jsx_runtime_.jsx("span", {
                                                            children: field.value
                                                        }),
                                                        /*#__PURE__*/ jsx_runtime_.jsx("span", {
                                                            className: "font-normal w-5 h-5 rounded-full flex items-center justify-center cursor-pointer bg-slate-200 dark:bg-slate-600 text-xs hover:bg-slate-400",
                                                            onClick: (e)=>{
                                                                let updatedArray = indexTableFields.filter((_field)=>!_field.value.match(new RegExp(`^${external_lodash_default().escapeRegExp(field.value)}$`)));
                                                                setIndexTableFields([
                                                                    ...updatedArray, 
                                                                ]);
                                                            },
                                                            children: "✖"
                                                        })
                                                    ]
                                                }, index + 1);
                                            })
                                        })
                                    ]
                                })
                            ]
                        })
                    ]
                }),
                /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                    className: "secondary mt-auto flex-wrap xl:flex-nowrap w-full xl:w-auto",
                    children: [
                        /*#__PURE__*/ jsx_runtime_.jsx("button", {
                            type: "submit",
                            className: "secondary mt-auto py-3 w-full sm:w-auto justify-center grow",
                            children: "Add Index"
                        }),
                        /*#__PURE__*/ jsx_runtime_.jsx("div", {
                            className: "button outlined gray mt-auto py-2.5 w-full sm:w-auto justify-center grow",
                            onClick: (e)=>{
                                setTableIndexes((prev)=>prev.filter((field, index)=>index != fieldIndex));
                            },
                            children: "Cancel"
                        })
                    ]
                })
            ]
        })
    });
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */ 

// EXTERNAL MODULE: ./functions/frontend/defaultFieldsRegexp.js
var defaultFieldsRegexp = __webpack_require__(3907);
;// CONCATENATED MODULE: ./components/admin/databases/indexes/indexSelectChange.js
// @ts-check

/**
 *
 * @param {object} param0
 * @param {any} param0.e
 * @param {import("@/package-shared/types").DSQL_IndexTableFieldType[]} param0.indexTableFields
 * @param {React.Dispatch<React.SetStateAction<import("@/package-shared/types").DSQL_IndexTableFieldType[]>>} param0.setIndexTableFields
 * @param {React.Dispatch<React.SetStateAction<string>>} param0.setIndexType
 * @param {import("@/package-shared/types").UserType} param0.user
 * @returns
 */ function indexSelectChange({ e , indexTableFields , setIndexTableFields , setIndexType , user ,  }) {
    if (e.target.value.match(/--/)) return;
    const targetOption = Array.from(e.target.options).filter((option)=>option.value === e.target.value);
    const dataType = targetOption[0].dataset.type;
    if (dataType.match(/text/i)) {
        setIndexType("fullText");
        setIndexTableFields([
            {
                value: e.target.value,
                dataType: dataType
            }, 
        ]);
    } else {
        try {
            const existingTextDataType = indexTableFields.filter((obj)=>obj.dataType.match(/text/i));
            if (existingTextDataType[0]) throw new Error("TEXT type exists");
            let existingFieldsArray = indexTableFields;
            if (existingFieldsArray.findIndex((obj)=>obj.value === e.target.value) >= 0 || e.target.value.match(/^--$/)) {
                return;
            }
            existingFieldsArray.push({
                value: e.target.value,
                dataType
            });
            setIndexTableFields([
                ...existingFieldsArray
            ]);
        } catch (/** @type {any} */ error) {
            (0,fetchApi/* default */.Z)("/api/admin/clientError", {
                method: "post",
                body: {
                    component: "ExistingIndexEdit/lines-184-197",
                    message: error.message,
                    user: user
                }
            });
            setIndexTableFields([
                {
                    value: e.target.value,
                    dataType: dataType
                }, 
            ]);
        }
        setIndexType("regular");
    }
}

;// CONCATENATED MODULE: ./components/admin/databases/ExistingIndexEdit.jsx
// @ts-check
/**
 * ==============================================================================
 * Imports
 * ==============================================================================
 */ 




/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ let timeout;
/** ****************************************************************************** */ /**
 * ==============================================================================
 * Main Component { Functional }
 * ==============================================================================
 * @param {Object} props - Server props
 * @param {import("@/package-shared/types").DSQL_IndexSchemaType} props.targetIndexObject
 * @param {number} props.fieldIndex
 * @param {import("@/package-shared/types").DSQL_FieldSchemaType[]} props.tableFields
 * @param {React.MutableRefObject<React.Dispatch<React.SetStateAction<number>>>} [props.refreshFieldsListRef]
 * @param {React.Dispatch<React.SetStateAction<import("@/package-shared/types").DSQL_IndexSchemaType[]>>} props.setTableIndexes
 * @param {React.Dispatch<React.SetStateAction<number>>} props.setRefresh
 * @param {React.Dispatch<React.SetStateAction<boolean>>} props.setActiveEdit
 * @param {import("@/package-shared/types").UserType} props.user
 * @param {string|number} props.tableUniqueId
 */ function ExistingIndexEdit({ targetIndexObject , fieldIndex , tableFields , refreshFieldsListRef , setTableIndexes , setRefresh , setActiveEdit , user , tableUniqueId ,  }) {
    /**
     * Get Contexts
     *
     * @abstract { React.useContext }
     */ ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Javascript Variables
     *
     * @abstract Non hook variables and functions
     */ const columnDesc = "Select Columns to be indexed. NB the order matters";
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * React Hooks
     *
     * @abstract { useState, useEffect, useRef, etc ... }
     */ const [indexData, setIndexData] = external_react_default().useState(targetIndexObject);
    const [indexType, setIndexType] = external_react_default().useState(indexData.indexType || "regular");
    const [indexTableFields, setIndexTableFields] = external_react_default().useState(indexData.indexTableFields ? [
        ...indexData.indexTableFields
    ] : []);
    /** @type {React.MutableRefObject<HTMLElement | undefined>} */ const newFieldRef = external_react_default().useRef();
    external_react_default().useEffect(()=>{
        newFieldRef.current?.scrollIntoView({
            block: "center",
            behavior: "smooth"
        });
        newFieldRef.current?.querySelector("input")?.focus();
    }, []);
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Function Return
     *
     * @abstract Main Function Return
     */ return /*#__PURE__*/ jsx_runtime_.jsx("div", {
        className: "w-full -mt-3 flex-wrap",
        // @ts-ignore
        ref: newFieldRef,
        children: /*#__PURE__*/ (0,jsx_runtime_.jsxs)("form", {
            className: "flex flex-col xl:flex-row items-start gap-4 w-full justify-between p-4 relative xl:flex-nowrap flex-wrap border border-t-0 border-slate-200 dark:border-slate-600 border-solid rounded-b",
            onSubmit: (e)=>{
                e.preventDefault();
                /** @type {HTMLFormElement} */ // @ts-ignore
                const formEl = e.target;
                let new_index_name = formEl["new_index_name"].value.replace(/_index/, "").replace(/_{1,}$/, "") + "_index";
                let newDataObject = indexData;
                newDataObject.indexName = new_index_name;
                newDataObject.alias = tableUniqueId + "_" + new_index_name, newDataObject.indexTableFields = indexTableFields;
                setTableIndexes((prev)=>{
                    let newArray = prev;
                    newArray[fieldIndex] = newDataObject;
                    return newArray;
                });
                setActiveEdit(false);
                setRefresh((prev)=>prev + 1);
            },
            children: [
                /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                    className: "gap-4 xl:flex-nowrap flex-wrap flex-col xl:flex-row items-stretch w-full",
                    children: [
                        /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                            className: "flex flex-col items-start gap-0.5",
                            style: {
                                minWidth: "70px"
                            },
                            children: [
                                /*#__PURE__*/ jsx_runtime_.jsx("label", {
                                    htmlFor: "new_field_required",
                                    children: "Type"
                                }),
                                /*#__PURE__*/ jsx_runtime_.jsx("select", {
                                    name: "new_field_required",
                                    id: "new_field_required",
                                    className: "px-2",
                                    onChange: (e)=>{
                                        setIndexType(e.target.value);
                                        setIndexData((prev)=>{
                                            let existingIndexData = prev;
                                            existingIndexData.indexType = e.target.value;
                                            return existingIndexData;
                                        });
                                    },
                                    defaultValue: indexType,
                                    children: indexType?.match(/regular/i) ? /*#__PURE__*/ jsx_runtime_.jsx("option", {
                                        value: "regular",
                                        children: "Default"
                                    }) : /*#__PURE__*/ jsx_runtime_.jsx("option", {
                                        value: "fullText",
                                        children: "Full Text"
                                    })
                                })
                            ]
                        }),
                        /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                            className: "flex flex-col items-start gap-0.5",
                            children: [
                                /*#__PURE__*/ jsx_runtime_.jsx("label", {
                                    htmlFor: "new_index_name",
                                    children: "Index Name"
                                }),
                                /*#__PURE__*/ jsx_runtime_.jsx("input", {
                                    type: "text",
                                    name: "new_index_name",
                                    id: "new_index_name",
                                    placeholder: "Eg. title_index",
                                    onInput: async (e)=>{
                                        /** @type {HTMLInputElement} */ // @ts-ignore
                                        const inputEl = e.target;
                                        inputEl.value = inputEl.value.toLowerCase().replace(/ /g, "_");
                                    },
                                    required: true,
                                    defaultValue: indexData.indexName
                                })
                            ]
                        }),
                        /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                            className: "flex flex-col items-start gap-4 xl:gap-0.5",
                            children: [
                                /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                                    className: "items-start",
                                    children: [
                                        /*#__PURE__*/ jsx_runtime_.jsx("label", {
                                            htmlFor: "new_field_data_type",
                                            children: "Table Column(s)"
                                        }),
                                        /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                                            className: "dropdown-wrapper reversed text-sm items-start gap-2",
                                            children: [
                                                /*#__PURE__*/ jsx_runtime_.jsx("span", {
                                                    className: "px-2 bg-slate-200 dark:bg-slate-700 rounded-full hover:bg-slate-100 dark:hover:bg-slate-600 hidden xl:flex",
                                                    children: "Info"
                                                }),
                                                /*#__PURE__*/ jsx_runtime_.jsx("div", {
                                                    className: "dropdown mt-0 xl:-mt-2",
                                                    children: /*#__PURE__*/ jsx_runtime_.jsx("span", {
                                                        children: columnDesc
                                                    })
                                                })
                                            ]
                                        })
                                    ]
                                }),
                                /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                                    className: "w-auto flex flex-row items-stretch gap-4",
                                    children: [
                                        /*#__PURE__*/ (0,jsx_runtime_.jsxs)("select", {
                                            name: "new_field_data_type",
                                            id: "new_field_data_type",
                                            className: "w-full xl:w-auto",
                                            onChange: (e)=>{
                                                indexSelectChange({
                                                    e,
                                                    indexTableFields,
                                                    setIndexTableFields,
                                                    setIndexType,
                                                    user
                                                });
                                            },
                                            children: [
                                                /*#__PURE__*/ jsx_runtime_.jsx("option", {
                                                    value: "--",
                                                    children: "--"
                                                }),
                                                tableFields.filter((field)=>!field?.fieldName?.match(/^id$|^date_/) && !field.foreignKey).map((field, index)=>{
                                                    return /*#__PURE__*/ jsx_runtime_.jsx("option", {
                                                        value: field.fieldName,
                                                        "data-type": field.dataType,
                                                        children: field.fieldName
                                                    }, index + 1);
                                                })
                                            ]
                                        }),
                                        indexTableFields && indexTableFields[0] && /*#__PURE__*/ jsx_runtime_.jsx("div", {
                                            className: "card no-hover px-3 py-1 items-center",
                                            children: indexTableFields.map((field, index)=>{
                                                return /*#__PURE__*/ (0,jsx_runtime_.jsxs)("span", {
                                                    className: "text-sm px-3 py-1 bg-white dark:bg-slate-700 rounded-full shadow-lg font-bold flex items-center justify-center gap-1",
                                                    children: [
                                                        /*#__PURE__*/ jsx_runtime_.jsx("span", {
                                                            children: field.value
                                                        }),
                                                        /*#__PURE__*/ jsx_runtime_.jsx("span", {
                                                            className: "font-normal w-5 h-5 rounded-full flex items-center justify-center cursor-pointer bg-slate-200 text-xs hover:bg-slate-400",
                                                            onClick: (e)=>{
                                                                let updatedArray = indexTableFields.filter((_field)=>!_field.value.match(new RegExp(`^${external_lodash_default().escapeRegExp(field.value)}$`)));
                                                                setIndexTableFields([
                                                                    ...updatedArray, 
                                                                ]);
                                                            },
                                                            children: "✖"
                                                        })
                                                    ]
                                                }, index + 1);
                                            })
                                        })
                                    ]
                                })
                            ]
                        })
                    ]
                }),
                /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                    className: "secondary mt-auto xl:flex-nowrap flex-wrap w-full xl:w-auto",
                    children: [
                        /*#__PURE__*/ jsx_runtime_.jsx("button", {
                            type: "submit",
                            className: "secondary mt-auto py-3 w-full md:w-auto grow",
                            children: "Save Updates"
                        }),
                        /*#__PURE__*/ jsx_runtime_.jsx("div", {
                            className: "button outlined gray mt-auto py-2.5 w-full md:w-auto justify-center grow",
                            onClick: (e)=>{
                                // const originIndexFields = targetIndexObject.indexTableFields
                                // setIndexTableFields([...originIndexFields])
                                // setIndexData(targetIndexObject)
                                setActiveEdit(false);
                            },
                            children: "Cancel"
                        })
                    ]
                })
            ]
        })
    });
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */ 

// EXTERNAL MODULE: ./components/general/ui/ButtonGroup.jsx
var ButtonGroup = __webpack_require__(5449);
;// CONCATENATED MODULE: ./components/admin/databases/SingleTableIndexCard.jsx
// @ts-check
/**
 * ==============================================================================
 * Imports
 * ==============================================================================
 */ 




/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ let SingleTableIndexCard_timeout;
/** ****************************************************************************** */ /**
 * ==============================================================================
 * Main Component { Functional }
 * ==============================================================================
 * @param {Object} props
 * @param {import("@/package-shared/types").DSQL_IndexSchemaType} props.tableIndex
 * @param {number} props.fieldIndex
 * @param {import("@/package-shared/types").DSQL_IndexSchemaType[]} [props.tableIndexes]
 * @param {React.Dispatch<React.SetStateAction<import("@/package-shared/types").DSQL_IndexSchemaType[]>>} props.setTableIndexes
 * @param {React.MutableRefObject<React.Dispatch<React.SetStateAction<number>>>} [props.refreshFieldsListRef]
 * @param {import("@/package-shared/types").DSQL_MYSQL_user_databases_Type} props.database
 * @param {import("@/package-shared/types").DSQL_TableSchemaType} [props.currentTable]
 * @param {import("@/package-shared/types").DSQL_FieldSchemaType[]} props.tableFields
 * @param {React.Dispatch<React.SetStateAction<number>>} props.setRefresh
 * @param {any} props.confirmedDelegetedUser
 * @param {import("@/package-shared/types").UserType} props.user
 * @param {string|number} props.tableUniqueId
 */ function SingleTableIndexCard({ tableIndex , fieldIndex , tableIndexes , setTableIndexes , refreshFieldsListRef , database , currentTable , tableFields , setRefresh , confirmedDelegetedUser , user , tableUniqueId ,  }) {
    /**
     * Get Contexts
     *
     * @abstract { React.useContext }
     */ ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * 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 ... }
     */ const [indexData, setindexData] = external_react_default().useState(tableIndex);
    const [activeEdit, setActiveEdit] = external_react_default().useState(false);
    const [refreshComp, setRefreshComp] = external_react_default().useState(0);
    // React.useEffect(() => {
    //     setindexData(tableIndex)
    //     setRefreshComp(prev => prev + 1);
    // }, [activeEdit])
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Function Return
     *
     * @abstract Main Function Return
     */ return /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
        className: "flex-col w-full" + (activeEdit ? " shadow-xl shadow-slate-300/40 dark:shadow-black/30 relative z-50" : ""),
        children: [
            /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                className: "card no-hover items-center w-full py-4" + (activeEdit ? " rounded-t" : " rounded") + (indexData.indexName?.match(defaultFieldsRegexp/* default */.Z) ? " text-slate-400 pointer-events-none border-slate-200 border" : ""),
                onClick: (e)=>{
                // setTargetField(field);
                },
                children: [
                    /*#__PURE__*/ jsx_runtime_.jsx("span", {
                        className: "font-bold dark:text-white",
                        children: indexData.indexName
                    }),
                    !indexData.indexName?.match(defaultFieldsRegexp/* default */.Z) && !active_clone_parent_db && !remote_connected && /*#__PURE__*/ jsx_runtime_.jsx("div", {
                        className: "ml-0 md:ml-auto flex-wrap",
                        children: (!isDelegated || isDelegated && isTableEditable) && /*#__PURE__*/ jsx_runtime_.jsx((external_react_default()).Fragment, {
                            children: /*#__PURE__*/ jsx_runtime_.jsx(ButtonGroup/* default */.Z, {
                                children: /*#__PURE__*/ jsx_runtime_.jsx("div", {
                                    className: "button outlined gray smallest",
                                    onClick: (e)=>{
                                        if (window.confirm(`Delete "${tableIndex.indexName}"?`)) {
                                            setTableIndexes((prev)=>prev.filter((field, index)=>index != fieldIndex));
                                        }
                                    },
                                    style: {
                                        color: "var(--slate-500)"
                                    },
                                    children: "Delete"
                                })
                            })
                        })
                    })
                ]
            }),
            activeEdit && /*#__PURE__*/ jsx_runtime_.jsx("div", {
                className: "w-full",
                children: /*#__PURE__*/ jsx_runtime_.jsx(ExistingIndexEdit, {
                    fieldIndex: fieldIndex,
                    // tableIndexes={tableIndexes}
                    setTableIndexes: setTableIndexes,
                    refreshFieldsListRef: refreshFieldsListRef,
                    // targetField={tableIndex}
                    setActiveEdit: setActiveEdit,
                    // database={database}
                    // currentTable={currentTable}
                    tableFields: tableFields,
                    targetIndexObject: indexData,
                    setRefresh: setRefresh,
                    user: user,
                    tableUniqueId: tableUniqueId
                })
            })
        ]
    });
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */ 

;// CONCATENATED MODULE: ./components/admin/databases/TableIndexes.jsx
// @ts-check
/**
 * ==============================================================================
 * Imports
 * ==============================================================================
 */ 





/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ let reactKey = 1;
/** ****************************************************************************** */ /**
 * ==============================================================================
 * Main Component { Functional }
 * ==============================================================================
 * @param {Object} props - Server props
 * @param {import("@/package-shared/types").UserType} props.user
 * @param {import("@/package-shared/types").DSQL_TableSchemaType} props.table
 * @param {string|number} props.tableUniqueId
 * @param {import("@/package-shared/types").DSQL_IndexSchemaType[]} props.tableIndexes
 * @param {React.Dispatch<React.SetStateAction<import("@/package-shared/types").DSQL_IndexSchemaType[]>>} props.setTableIndexes
 * @param {import("@/package-shared/types").DSQL_FieldSchemaType[]} props.tableFields
 * @param {(setLoading?: React.Dispatch<React.SetStateAction<boolean>>) => void} props.updateTableAfterFieldsUpdateFunction
 * @param {any} props.confirmedDelegetedUser
 * @param {import("@/package-shared/types").DSQL_MYSQL_user_databases_Type} props.database
 */ function TableIndexes({ user , table , tableUniqueId , tableIndexes , setTableIndexes , tableFields , updateTableAfterFieldsUpdateFunction , confirmedDelegetedUser , database ,  }) {
    /**
     * Get Contexts
     *
     * @abstract { React.useContext }
     */ ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Javascript Variables
     *
     * @abstract Non hook variables and functions
     */ const indexes = table.indexes;
    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 ... }
     */ const [refresh, setRefresh] = external_react_default().useState(0);
    const [loading, setLoading] = external_react_default().useState(false);
    const [collapse, setCollapse] = external_react_default().useState(false);
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    if (isDelegated && !isTableEditable) {
        return /*#__PURE__*/ jsx_runtime_.jsx(jsx_runtime_.Fragment, {});
    }
    /**
     * Function Return
     *
     * @abstract Main Function Return
     */ return /*#__PURE__*/ (0,jsx_runtime_.jsxs)("section", {
        className: "paper blue",
        children: [
            loading && /*#__PURE__*/ jsx_runtime_.jsx(LoadingBlock/* default */.Z, {}),
            table.childTable ? /*#__PURE__*/ (0,jsx_runtime_.jsxs)((external_react_default()).Fragment, {
                children: [
                    /*#__PURE__*/ jsx_runtime_.jsx("h2", {
                        className: "text-xl m-0 text-left title",
                        children: "Indexes"
                    }),
                    /*#__PURE__*/ jsx_runtime_.jsx("span", {
                        children: "Table indexes are inherited from parent table"
                    }),
                    tableIndexes && tableIndexes[0] && tableIndexes.map((tableIndex, index)=>{
                        return /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                            className: "card w-full light-gray py-4 no-hover items-center",
                            children: [
                                /*#__PURE__*/ jsx_runtime_.jsx("b", {
                                    children: tableIndex.indexName
                                }),
                                /*#__PURE__*/ (0,jsx_runtime_.jsxs)("span", {
                                    className: "info small gray grow-0 ml-auto w-auto",
                                    children: [
                                        tableIndex.indexType,
                                        " index"
                                    ]
                                })
                            ]
                        }, index);
                    })
                ]
            }) : /*#__PURE__*/ (0,jsx_runtime_.jsxs)((external_react_default()).Fragment, {
                children: [
                    /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                        className: "w-full justify-between flex-wrap",
                        children: [
                            /*#__PURE__*/ jsx_runtime_.jsx("h2", {
                                className: "text-xl m-0 text-left title",
                                children: "Indexes"
                            }),
                            (!isDelegated || isDelegated && isTableEditable) && !active_clone_parent_db && !remote_connected && /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                                className: "button secondary outlined flex items-center gap-2",
                                onClick: (e)=>{
                                    if (collapse) setCollapse(false);
                                    addNewTemplateIndex({
                                        tableIndexes,
                                        setTableIndexes,
                                        setRefresh
                                    });
                                },
                                children: [
                                    /*#__PURE__*/ jsx_runtime_.jsx("span", {
                                        className: "symbol",
                                        children: "+"
                                    }),
                                    /*#__PURE__*/ jsx_runtime_.jsx("span", {
                                        children: "Add Index"
                                    })
                                ]
                            })
                        ]
                    }),
                    /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                        className: "flex-col w-full",
                        style: collapse ? {
                            maxHeight: "200px"
                        } : {},
                        children: [
                            tableIndexes && tableIndexes[0] && tableIndexes.map((tableIndex, index)=>{
                                reactKey++;
                                if (tableIndex.newTempIndex) {
                                    return /*#__PURE__*/ jsx_runtime_.jsx(NewIndexFieldTemp, {
                                        fieldIndex: index,
                                        tableIndex: tableIndex,
                                        currentTable: table,
                                        tableIndexes: tableIndexes,
                                        setTableIndexes: setTableIndexes,
                                        tableFields: tableFields,
                                        setRefresh: setRefresh,
                                        user: user,
                                        tableUniqueId: tableUniqueId
                                    }, reactKey);
                                } else {
                                    return /*#__PURE__*/ jsx_runtime_.jsx(SingleTableIndexCard, {
                                        fieldIndex: index,
                                        tableIndex: tableIndex,
                                        database: database,
                                        currentTable: table,
                                        tableIndexes: tableIndexes,
                                        setTableIndexes: setTableIndexes,
                                        tableFields: tableFields,
                                        setRefresh: setRefresh,
                                        confirmedDelegetedUser: confirmedDelegetedUser,
                                        user: user,
                                        tableUniqueId: tableUniqueId
                                    }, reactKey);
                                }
                            }),
                            (!isDelegated || isDelegated && isTableEditable) && !active_clone_parent_db && !remote_connected && /*#__PURE__*/ (0,jsx_runtime_.jsxs)((external_react_default()).Fragment, {
                                children: [
                                    /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                                        className: "button outlined gray w-full justify-center more-padding",
                                        style: {
                                            borderStyle: "dashed"
                                        },
                                        onClick: (e)=>{
                                            addNewTemplateIndex({
                                                tableIndexes,
                                                setTableIndexes,
                                                setRefresh
                                            });
                                        },
                                        children: [
                                            /*#__PURE__*/ jsx_runtime_.jsx("span", {
                                                className: "symbol",
                                                children: "+"
                                            }),
                                            /*#__PURE__*/ jsx_runtime_.jsx("span", {
                                                children: "Add New Index"
                                            })
                                        ]
                                    }),
                                    /*#__PURE__*/ jsx_runtime_.jsx("div", {
                                        className: "button w-full blue",
                                        onClick: (e)=>{
                                            setLoading(true);
                                            updateTableAfterFieldsUpdateFunction && updateTableAfterFieldsUpdateFunction(setLoading);
                                        },
                                        children: /*#__PURE__*/ jsx_runtime_.jsx("span", {
                                            children: "Update Table Indexes"
                                        })
                                    })
                                ]
                            })
                        ]
                    })
                ]
            })
        ]
    });
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */ 

// 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/SingleTableContent.jsx
// @ts-check
/**
 * ==============================================================================
 * Imports
 * ==============================================================================
 */ 














/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
 * ==============================================================================
 * Main Component { Functional }
 * ==============================================================================
 * @param {Object} props - Server props
 */ function SingleTableContent(props) {
    /**
     * Get Contexts
     *
     * @abstract { React.useContext }
     */ const { user , database , table , tableRecord , dbSchemaData , targetField , setTargetField , refreshFieldsListRef , setTableFields , tableFields , tableIndexes , setTableIndexes , updateTableAfterFieldsUpdateFunction , entries , targetEntry , setTargetEntry , richTextEditors , jsonTextEditors , query , confirmedDelegetedUser , entriesCount ,  } = external_react_default().useContext(SingleTableContext);
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Javascript Variables
     *
     * @abstract Non hook variables and functions
     */ if (!database || !user || !tableRecord || !table) return;
    const dataTypes = __webpack_require__(9594);
    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;
    const tableUniqueId = `dsql${user.id}${database.id}${tableRecord.id}`;
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * React Hooks
     *
     * @abstract { useState, useEffect, useRef, etc ... }
     */ const [loading, setLoading] = external_react_default().useState(false);
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     * Function Return
     *
     * @abstract Main Function Return
     */ return /*#__PURE__*/ (0,jsx_runtime_.jsxs)((external_react_default()).Fragment, {
        children: [
            loading && /*#__PURE__*/ jsx_runtime_.jsx(LoadingBlock/* default */.Z, {}),
            /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                className: "flex-col items-start gap-4 xl:gap-0 w-full relative z-50",
                children: [
                    /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                        className: "w-full justify-between flex-wrap",
                        children: [
                            /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                                className: "flex-wrap",
                                children: [
                                    /*#__PURE__*/ jsx_runtime_.jsx(BackButton/* default */.Z, {}),
                                    /*#__PURE__*/ jsx_runtime_.jsx("h1", {
                                        className: "text-3xl m-0",
                                        children: /*#__PURE__*/ (0,jsx_runtime_.jsxs)("span", {
                                            children: [
                                                table.tableFullName.replace(/ table/i, ""),
                                                " ",
                                                "Table"
                                            ]
                                        })
                                    }),
                                    /*#__PURE__*/ jsx_runtime_.jsx(CopySlug/* default */.Z, {
                                        slugText: table.tableName,
                                        outlined: true
                                    })
                                ]
                            }),
                            /*#__PURE__*/ jsx_runtime_.jsx("div", {
                                className: "flex-wrap flex-col md:flex-row w-full md:w-auto items-stretch md:items-center",
                                children: /*#__PURE__*/ (0,jsx_runtime_.jsxs)(ButtonGroup/* default */.Z, {
                                    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("a", {
                                            href: `/admin/${user?.id}/databases/${database.db_slug}/tables/${table.tableName}/entries`,
                                            className: "button secondary flex items-center gap-2",
                                            children: /*#__PURE__*/ jsx_runtime_.jsx("span", {
                                                children: "Entries"
                                            })
                                        }),
                                        /*#__PURE__*/ jsx_runtime_.jsx("a", {
                                            href: `/admin/${user?.id}/databases/${database.db_slug}/tables/${table.tableName}/fields`,
                                            className: "button outlined secondary flex items-center gap-2",
                                            children: /*#__PURE__*/ jsx_runtime_.jsx("span", {
                                                children: "All Fields"
                                            })
                                        }),
                                        (!isDelegated || isDelegated && (isTableEditable || isTableDeletable)) && !active_clone_parent_db && !remote_connected && /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
                                            className: "dropdown-wrapper mt-4 xl:mt-0",
                                            children: [
                                                /*#__PURE__*/ jsx_runtime_.jsx("span", {
                                                    className: "hidden xl:flex button outlined gray",
                                                    children: "More"
                                                }),
                                                /*#__PURE__*/ jsx_runtime_.jsx("div", {
                                                    className: "dropdown mobile-transform right-aligned mt-0 xl:-mt-2 gap-2",
                                                    children: /*#__PURE__*/ (0,jsx_runtime_.jsxs)(ButtonGroup/* default */.Z, {
                                                        column: true,
                                                        className: "w-full",
                                                        children: [
                                                            (!isDelegated || isDelegated && isTableEditable) && !active_clone_parent_db && !remote_connected && /*#__PURE__*/ jsx_runtime_.jsx("a", {
                                                                className: "button outlined-gray more-padding w-full",
                                                                href: `/admin/${user?.id}/databases/${database.db_slug}/tables/${table.tableName}/edit-table`,
                                                                children: "Edit Table"
                                                            }),
                                                            (!isDelegated || isDelegated && isTableDeletable) && !active_clone_parent_db && !remote_connected && /*#__PURE__*/ jsx_runtime_.jsx("button", {
                                                                className: "outlined-gray more-padding w-full",
                                                                onClick: (e)=>{
                                                                    if (window.confirm(`Delete "${table.tableFullName}" table?`)) {
                                                                        setLoading(true);
                                                                        (0,fetchApi/* default */.Z)("/api/deleteUserTable", {
                                                                            method: "post",
                                                                            body: {
                                                                                database: database,
                                                                                table: {
                                                                                    table_slug: table.tableName
                                                                                }
                                                                            }
                                                                        }, true).then((res)=>{
                                                                            if (res.success) {
                                                                                window.location.reload();
                                                                            }
                                                                        });
                                                                    }
                                                                },
                                                                children: "Delete Table"
                                                            })
                                                        ]
                                                    })
                                                })
                                            ]
                                        })
                                    ]
                                })
                            })
                        ]
                    }),
                    /*#__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,
                collapsed: true,
                database: database,
                table: table,
                confirmedDelegetedUser: confirmedDelegetedUser,
                query: query
            }),
            /*#__PURE__*/ jsx_runtime_.jsx(TableIndexes, {
                user: user,
                table: table,
                tableUniqueId: tableUniqueId,
                // dbSchemaData={dbSchemaData}
                tableIndexes: tableIndexes,
                setTableIndexes: setTableIndexes,
                database: database,
                tableFields: tableFields,
                updateTableAfterFieldsUpdateFunction: updateTableAfterFieldsUpdateFunction,
                confirmedDelegetedUser: confirmedDelegetedUser
            }),
            entries && dbSchemaData && richTextEditors && jsonTextEditors && /*#__PURE__*/ jsx_runtime_.jsx(TableEntriesList/* default */.Z, {
                user: user,
                entries: entries,
                database: database,
                table: table,
                setTargetEntry: setTargetEntry,
                dbSchemaData: dbSchemaData,
                richTextEditors: richTextEditors,
                dataTypes: dataTypes,
                title: "Entries",
                query: query,
                confirmedDelegetedUser: confirmedDelegetedUser,
                jsonTextEditors: jsonTextEditors,
                entriesCount: entriesCount
            })
        ]
    });
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */  /** ****************************************************************************** */ 

// EXTERNAL MODULE: ./components/general/ExtraContentDatabase.jsx
var ExtraContentDatabase = __webpack_require__(4941);
// 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);
// EXTERNAL MODULE: ./layouts/components/GeneralLayout/ScrollToTopButton.jsx
var ScrollToTopButton = __webpack_require__(9360);
;// CONCATENATED MODULE: ./pages/admin/[user_id]/databases/[single]/tables/[single_table]/index.jsx
// @ts-check
/**
 * ==============================================================================
 * Imports
 * ==============================================================================
 */ 

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

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








/** ****************************************************************************** */ /** @type {import("@/package-shared/types").SingleTableContextType} */ // @ts-ignore
const init = {};
const SingleTableContext = /*#__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").MYSQL_user_database_tables_table_def} props.tableRecord
 * @param {import("@/package-shared/types").DSQL_DatabaseSchemaType[]} props.dbSchemaData
 * @param {any[]} props.entries
 * @param {any} props.query
 * @param {any} props.confirmedDelegetedUser
 * @param {number} props.entriesCount
 */ function SingleTable({ user , database , table , tableRecord , dbSchemaData , entries , query , confirmedDelegetedUser , entriesCount ,  }) {
    /**
     * 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 ... }
     */ const [tableFields, setTableFields] = external_react_default().useState(table.fields);
    /** @type {any} */ const tableIndexesState = external_react_default().useState(table.indexes);
    /** @type {[ targetField: import("@/package-shared/types").DSQL_IndexSchemaType[], setTargetField: React.Dispatch<React.SetStateAction<import("@/package-shared/types").DSQL_IndexSchemaType[]>> ]} */ const [tableIndexes, setTableIndexes] = tableIndexesState;
    /** @type {any} */ const targetFieldState = external_react_default().useState(null);
    /** @type {[ targetField: import("@/package-shared/types").DSQL_FieldSchemaType | null, setTargetField: React.Dispatch<React.SetStateAction<import("@/package-shared/types").DSQL_FieldSchemaType | null>> ]} */ const [targetField, setTargetField] = targetFieldState;
    const [targetEntry, setTargetEntry] = external_react_default().useState(null);
    /** @type {React.MutableRefObject<React.Dispatch<React.SetStateAction<number>>>} */ // @ts-ignore
    const refreshFieldsListRef = external_react_default().useRef(null);
    // const targetFieldIndex = targetField ? tableFields.findIndex((field) => field.fieldName === targetField.fieldName) : 1;
    const richTextEditors = external_react_default().useRef([]);
    const jsonTextEditors = external_react_default().useRef([]);
    ////////////////////////////////////////
    ////////////////////////////////////////
    ////////////////////////////////////////
    /**
     *
     * @param {React.Dispatch<React.SetStateAction<boolean>>} [setLoading]
     */ function updateTableAfterFieldsUpdateFunction(setLoading) {
        (0,updateTableAfterFieldsUpdateFunctionExt/* default */.Z)({
            query,
            table,
            database,
            dbSchemaData,
            tableFields,
            tableIndexes,
            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)(SingleTableContext.Provider, {
            value: {
                user,
                database,
                table,
                tableRecord,
                dbSchemaData,
                targetField,
                setTargetField,
                refreshFieldsListRef,
                tableFields,
                setTableFields,
                tableIndexes,
                setTableIndexes,
                updateTableAfterFieldsUpdateFunction,
                entries,
                targetEntry,
                setTargetEntry,
                richTextEditors,
                jsonTextEditors,
                query,
                confirmedDelegetedUser,
                entriesCount
            },
            children: [
                /*#__PURE__*/ jsx_runtime_.jsx(SingleTableContent, {}),
                /*#__PURE__*/ jsx_runtime_.jsx(DeleteTableConfirmationPopup/* default */.Z, {
                    database: database,
                    targetTable: tableRecord
                }),
                /*#__PURE__*/ jsx_runtime_.jsx(ScrollToTopButton/* default */.Z, {
                    snug: true
                })
            ]
        })
    });
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
}
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
 * ==============================================================================
 * 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) {
            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: "[single_table]/index-page-component/getServerSideProps/catch-error]",
            message: error.message,
            user: user
        });
        return {
            redirect: {
                destination: req.url ? req.url.replace(/\/[^\/]+$/, "") + (query?.delegated ? "?delegated=true" : "") : "/",
                permanent: false
            }
        };
    }
}


/***/ }),

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

module.exports = require("@monaco-editor/react");

/***/ }),

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

/***/ }),

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

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

/***/ }),

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

module.exports = require("@tinymce/tinymce-react");

/***/ }),

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

module.exports = require("gsap");

/***/ }),

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

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

/***/ }),

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

module.exports = require("html-prettify");

/***/ }),

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

/***/ }),

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

module.exports = require("react-tiny-popover");

/***/ }),

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

})();