"use strict";
/*
 * ATTENTION: An "eval-source-map" devtool has been used.
 * This devtool is neither made for production nor for readable output files.
 * It uses "eval()" calls to create a separate source file with attached SourceMaps in the browser devtools.
 * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
 * or disable the default devtool with "devtool: false".
 * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
 */
self["webpackHotUpdate_N_E"]("app/admin/documents/page",{

/***/ "(app-pages-browser)/./src/components/admin/DocumentUpload.tsx":
/*!*************************************************!*\
  !*** ./src/components/admin/DocumentUpload.tsx ***!
  \*************************************************/
/***/ (function(module, __webpack_exports__, __webpack_require__) {

eval(__webpack_require__.ts("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */   DocumentUpload: function() { return /* binding */ DocumentUpload; }\n/* harmony export */ });\n/* harmony import */ var react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react/jsx-dev-runtime */ \"(app-pages-browser)/./node_modules/next/dist/compiled/react/jsx-dev-runtime.js\");\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! react */ \"(app-pages-browser)/./node_modules/next/dist/compiled/react/index.js\");\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var _components_ui_Button__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @/components/ui/Button */ \"(app-pages-browser)/./src/components/ui/Button.tsx\");\n/* harmony import */ var _components_ui_ProgressBar__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @/components/ui/ProgressBar */ \"(app-pages-browser)/./src/components/ui/ProgressBar.tsx\");\n/* harmony import */ var _lib_hooks_useIngestionStatus__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @/lib/hooks/useIngestionStatus */ \"(app-pages-browser)/./src/lib/hooks/useIngestionStatus.ts\");\n/* harmony import */ var _lib_pocketbase__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @/lib/pocketbase */ \"(app-pages-browser)/./src/lib/pocketbase.ts\");\n/* harmony import */ var _lib_services__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @/lib/services */ \"(app-pages-browser)/./src/lib/services.ts\");\n/* __next_internal_client_entry_do_not_use__ DocumentUpload auto */ \nvar _s = $RefreshSig$();\n\n\n\n\n\n\nfunction DocumentUpload(param) {\n    let { onSuccess } = param;\n    _s();\n    const fileInputRef = (0,react__WEBPACK_IMPORTED_MODULE_1__.useRef)(null);\n    const [uploading, setUploading] = (0,react__WEBPACK_IMPORTED_MODULE_1__.useState)(false);\n    const [jobId, setJobId] = (0,react__WEBPACK_IMPORTED_MODULE_1__.useState)(null);\n    const [uploadError, setUploadError] = (0,react__WEBPACK_IMPORTED_MODULE_1__.useState)(null);\n    const [dragOver, setDragOver] = (0,react__WEBPACK_IMPORTED_MODULE_1__.useState)(false);\n    const { status, progress } = (0,_lib_hooks_useIngestionStatus__WEBPACK_IMPORTED_MODULE_4__.useIngestionStatus)(jobId);\n    const handleFiles = (0,react__WEBPACK_IMPORTED_MODULE_1__.useCallback)(async (files)=>{\n        if (!files || files.length === 0) return;\n        const file = files[0];\n        if (!file) return;\n        const allowed = [\n            \".pdf\",\n            \".md\",\n            \".txt\"\n        ];\n        const ext = file.name.slice(file.name.lastIndexOf(\".\")).toLowerCase();\n        if (!allowed.includes(ext)) {\n            setUploadError(\"Unsupported file type: \".concat(ext, \". Use PDF, MD, or TXT.\"));\n            return;\n        }\n        setUploadError(null);\n        setUploading(true);\n        setJobId(null);\n        try {\n            // Create record in PocketBase\n            const format = ext.slice(1);\n            const fd = new FormData();\n            fd.append(\"file\", file);\n            fd.append(\"filename\", file.name);\n            fd.append(\"format\", format);\n            fd.append(\"status\", \"processing\");\n            const doc = await _lib_pocketbase__WEBPACK_IMPORTED_MODULE_5__.pb.collection(\"source_documents\").create(fd);\n            var _process_env_NEXT_PUBLIC_POCKETBASE_URL;\n            // Build PocketBase file download URL\n            const pbUrl = (_process_env_NEXT_PUBLIC_POCKETBASE_URL = \"http://localhost:8090\") !== null && _process_env_NEXT_PUBLIC_POCKETBASE_URL !== void 0 ? _process_env_NEXT_PUBLIC_POCKETBASE_URL : \"http://localhost:8090\";\n            const fileUrl = \"\".concat(pbUrl, \"/api/files/source_documents/\").concat(doc.id, \"/\").concat(doc.file);\n            // Kick off ingestion\n            const { jobId: jId } = await (0,_lib_services__WEBPACK_IMPORTED_MODULE_6__.postIngest)({\n                documentId: doc.id,\n                filename: file.name,\n                format,\n                fileUrl\n            });\n            setJobId(jId);\n        } catch (err) {\n            setUploadError(err instanceof Error ? err.message : \"Upload failed\");\n        } finally{\n            setUploading(false);\n        }\n    }, []);\n    function handleChange(e) {\n        void handleFiles(e.target.files);\n        e.target.value = \"\";\n    }\n    function handleDrop(e) {\n        e.preventDefault();\n        setDragOver(false);\n        void handleFiles(e.dataTransfer.files);\n    }\n    function handleDragOver(e) {\n        e.preventDefault();\n        setDragOver(true);\n    }\n    function handleDragLeave() {\n        setDragOver(false);\n    }\n    const isDone = (status === null || status === void 0 ? void 0 : status.status) === \"done\";\n    const isFailed = (status === null || status === void 0 ? void 0 : status.status) === \"failed\";\n    if (isDone && jobId) {\n        return /*#__PURE__*/ (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxDEV)(\"div\", {\n            style: {\n                background: \"var(--success)\",\n                borderRadius: \"var(--r-md)\",\n                padding: \"var(--s-5)\",\n                textAlign: \"center\",\n                display: \"flex\",\n                flexDirection: \"column\",\n                gap: \"var(--s-3)\"\n            },\n            children: [\n                /*#__PURE__*/ (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxDEV)(\"p\", {\n                    style: {\n                        margin: 0,\n                        fontWeight: 600,\n                        color: \"var(--teal-900)\"\n                    },\n                    children: [\n                        \"Ingestion complete! \",\n                        status.themesFound,\n                        \" themes, \",\n                        status.topicsFound,\n                        \" topics found.\"\n                    ]\n                }, void 0, true, {\n                    fileName: \"C:\\\\Users\\\\RaymondVerhoef\\\\Gitea\\\\learning-platform\\\\app\\\\frontend\\\\src\\\\components\\\\admin\\\\DocumentUpload.tsx\",\n                    lineNumber: 107,\n                    columnNumber: 9\n                }, this),\n                /*#__PURE__*/ (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxDEV)(_components_ui_Button__WEBPACK_IMPORTED_MODULE_2__.Button, {\n                    variant: \"secondary\",\n                    size: \"sm\",\n                    onClick: ()=>{\n                        setJobId(null);\n                        onSuccess();\n                    },\n                    children: \"Upload another\"\n                }, void 0, false, {\n                    fileName: \"C:\\\\Users\\\\RaymondVerhoef\\\\Gitea\\\\learning-platform\\\\app\\\\frontend\\\\src\\\\components\\\\admin\\\\DocumentUpload.tsx\",\n                    lineNumber: 110,\n                    columnNumber: 9\n                }, this)\n            ]\n        }, void 0, true, {\n            fileName: \"C:\\\\Users\\\\RaymondVerhoef\\\\Gitea\\\\learning-platform\\\\app\\\\frontend\\\\src\\\\components\\\\admin\\\\DocumentUpload.tsx\",\n            lineNumber: 96,\n            columnNumber: 7\n        }, this);\n    }\n    var _status_reason;\n    return /*#__PURE__*/ (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxDEV)(\"div\", {\n        style: {\n            display: \"flex\",\n            flexDirection: \"column\",\n            gap: \"var(--s-4)\"\n        },\n        children: [\n            /*#__PURE__*/ (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxDEV)(\"div\", {\n                onDrop: handleDrop,\n                onDragOver: handleDragOver,\n                onDragLeave: handleDragLeave,\n                onClick: ()=>{\n                    var _fileInputRef_current;\n                    return (_fileInputRef_current = fileInputRef.current) === null || _fileInputRef_current === void 0 ? void 0 : _fileInputRef_current.click();\n                },\n                style: {\n                    border: \"2px dashed \".concat(dragOver ? \"var(--accent)\" : \"var(--cream)\"),\n                    borderRadius: \"var(--r-lg)\",\n                    padding: \"var(--s-8, 64px) var(--s-5)\",\n                    textAlign: \"center\",\n                    cursor: \"pointer\",\n                    background: dragOver ? \"var(--accent-soft)\" : \"var(--bg-warm)\",\n                    transition: \"background 150ms, border-color 150ms\"\n                },\n                children: [\n                    /*#__PURE__*/ (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxDEV)(\"input\", {\n                        ref: fileInputRef,\n                        type: \"file\",\n                        accept: \".pdf,.md,.txt\",\n                        style: {\n                            display: \"none\"\n                        },\n                        onChange: handleChange\n                    }, void 0, false, {\n                        fileName: \"C:\\\\Users\\\\RaymondVerhoef\\\\Gitea\\\\learning-platform\\\\app\\\\frontend\\\\src\\\\components\\\\admin\\\\DocumentUpload.tsx\",\n                        lineNumber: 141,\n                        columnNumber: 9\n                    }, this),\n                    /*#__PURE__*/ (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxDEV)(\"p\", {\n                        style: {\n                            margin: \"0 0 var(--s-2)\",\n                            fontSize: \"var(--t-lead)\",\n                            fontWeight: 600,\n                            color: \"var(--fg)\"\n                        },\n                        children: \"Drop a document here\"\n                    }, void 0, false, {\n                        fileName: \"C:\\\\Users\\\\RaymondVerhoef\\\\Gitea\\\\learning-platform\\\\app\\\\frontend\\\\src\\\\components\\\\admin\\\\DocumentUpload.tsx\",\n                        lineNumber: 148,\n                        columnNumber: 9\n                    }, this),\n                    /*#__PURE__*/ (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxDEV)(\"p\", {\n                        style: {\n                            margin: 0,\n                            fontSize: \"var(--t-small)\",\n                            color: \"var(--fg-muted)\"\n                        },\n                        children: \"or tap to browse — PDF, Markdown, TXT\"\n                    }, void 0, false, {\n                        fileName: \"C:\\\\Users\\\\RaymondVerhoef\\\\Gitea\\\\learning-platform\\\\app\\\\frontend\\\\src\\\\components\\\\admin\\\\DocumentUpload.tsx\",\n                        lineNumber: 158,\n                        columnNumber: 9\n                    }, this)\n                ]\n            }, void 0, true, {\n                fileName: \"C:\\\\Users\\\\RaymondVerhoef\\\\Gitea\\\\learning-platform\\\\app\\\\frontend\\\\src\\\\components\\\\admin\\\\DocumentUpload.tsx\",\n                lineNumber: 126,\n                columnNumber: 7\n            }, this),\n            uploadError && /*#__PURE__*/ (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxDEV)(\"div\", {\n                style: {\n                    background: \"#f8d7da\",\n                    color: \"#c0392b\",\n                    borderRadius: \"var(--r-sm)\",\n                    padding: \"var(--s-3) var(--s-4)\",\n                    fontSize: \"var(--t-small)\"\n                },\n                children: uploadError\n            }, void 0, false, {\n                fileName: \"C:\\\\Users\\\\RaymondVerhoef\\\\Gitea\\\\learning-platform\\\\app\\\\frontend\\\\src\\\\components\\\\admin\\\\DocumentUpload.tsx\",\n                lineNumber: 164,\n                columnNumber: 9\n            }, this),\n            (uploading || jobId) && /*#__PURE__*/ (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxDEV)(\"div\", {\n                style: {\n                    display: \"flex\",\n                    flexDirection: \"column\",\n                    gap: \"var(--s-2)\"\n                },\n                children: [\n                    /*#__PURE__*/ (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxDEV)(_components_ui_ProgressBar__WEBPACK_IMPORTED_MODULE_3__.ProgressBar, {\n                        value: uploading ? 5 : progress,\n                        label: uploading ? \"Uploading…\" : isFailed ? \"Failed: \".concat((_status_reason = status === null || status === void 0 ? void 0 : status.reason) !== null && _status_reason !== void 0 ? _status_reason : \"unknown error\") : (status === null || status === void 0 ? void 0 : status.status) ? \"\".concat(status.status.charAt(0).toUpperCase()).concat(status.status.slice(1), \"…\") : \"Processing…\",\n                        color: isFailed ? \"#c0392b\" : \"var(--accent)\"\n                    }, void 0, false, {\n                        fileName: \"C:\\\\Users\\\\RaymondVerhoef\\\\Gitea\\\\learning-platform\\\\app\\\\frontend\\\\src\\\\components\\\\admin\\\\DocumentUpload.tsx\",\n                        lineNumber: 179,\n                        columnNumber: 11\n                    }, this),\n                    status && /*#__PURE__*/ (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxDEV)(\"div\", {\n                        style: {\n                            fontSize: \"var(--t-small)\",\n                            color: \"var(--fg-muted)\",\n                            display: \"flex\",\n                            gap: \"var(--s-4)\",\n                            flexWrap: \"wrap\"\n                        },\n                        children: [\n                            /*#__PURE__*/ (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxDEV)(\"span\", {\n                                children: [\n                                    \"Chunks: \",\n                                    status.chunksEmbedded,\n                                    \"/\",\n                                    status.chunksTotal\n                                ]\n                            }, void 0, true, {\n                                fileName: \"C:\\\\Users\\\\RaymondVerhoef\\\\Gitea\\\\learning-platform\\\\app\\\\frontend\\\\src\\\\components\\\\admin\\\\DocumentUpload.tsx\",\n                                lineNumber: 202,\n                                columnNumber: 15\n                            }, this),\n                            /*#__PURE__*/ (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxDEV)(\"span\", {\n                                children: [\n                                    \"Themes: \",\n                                    status.themesFound\n                                ]\n                            }, void 0, true, {\n                                fileName: \"C:\\\\Users\\\\RaymondVerhoef\\\\Gitea\\\\learning-platform\\\\app\\\\frontend\\\\src\\\\components\\\\admin\\\\DocumentUpload.tsx\",\n                                lineNumber: 203,\n                                columnNumber: 15\n                            }, this),\n                            /*#__PURE__*/ (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxDEV)(\"span\", {\n                                children: [\n                                    \"Topics: \",\n                                    status.topicsFound\n                                ]\n                            }, void 0, true, {\n                                fileName: \"C:\\\\Users\\\\RaymondVerhoef\\\\Gitea\\\\learning-platform\\\\app\\\\frontend\\\\src\\\\components\\\\admin\\\\DocumentUpload.tsx\",\n                                lineNumber: 204,\n                                columnNumber: 15\n                            }, this)\n                        ]\n                    }, void 0, true, {\n                        fileName: \"C:\\\\Users\\\\RaymondVerhoef\\\\Gitea\\\\learning-platform\\\\app\\\\frontend\\\\src\\\\components\\\\admin\\\\DocumentUpload.tsx\",\n                        lineNumber: 193,\n                        columnNumber: 13\n                    }, this)\n                ]\n            }, void 0, true, {\n                fileName: \"C:\\\\Users\\\\RaymondVerhoef\\\\Gitea\\\\learning-platform\\\\app\\\\frontend\\\\src\\\\components\\\\admin\\\\DocumentUpload.tsx\",\n                lineNumber: 178,\n                columnNumber: 9\n            }, this)\n        ]\n    }, void 0, true, {\n        fileName: \"C:\\\\Users\\\\RaymondVerhoef\\\\Gitea\\\\learning-platform\\\\app\\\\frontend\\\\src\\\\components\\\\admin\\\\DocumentUpload.tsx\",\n        lineNumber: 125,\n        columnNumber: 5\n    }, this);\n}\n_s(DocumentUpload, \"YWcKUF7Ga0zlCuEtKN+CCdia0aE=\", false, function() {\n    return [\n        _lib_hooks_useIngestionStatus__WEBPACK_IMPORTED_MODULE_4__.useIngestionStatus\n    ];\n});\n_c = DocumentUpload;\nvar _c;\n$RefreshReg$(_c, \"DocumentUpload\");\n\n\n;\n    // Wrapped in an IIFE to avoid polluting the global scope\n    ;\n    (function () {\n        var _a, _b;\n        // Legacy CSS implementations will `eval` browser code in a Node.js context\n        // to extract CSS. For backwards compatibility, we need to check we're in a\n        // browser context before continuing.\n        if (typeof self !== 'undefined' &&\n            // AMP / No-JS mode does not inject these helpers:\n            '$RefreshHelpers$' in self) {\n            // @ts-ignore __webpack_module__ is global\n            var currentExports = module.exports;\n            // @ts-ignore __webpack_module__ is global\n            var prevSignature = (_b = (_a = module.hot.data) === null || _a === void 0 ? void 0 : _a.prevSignature) !== null && _b !== void 0 ? _b : null;\n            // This cannot happen in MainTemplate because the exports mismatch between\n            // templating and execution.\n            self.$RefreshHelpers$.registerExportsForReactRefresh(currentExports, module.id);\n            // A module can be accepted automatically based on its exports, e.g. when\n            // it is a Refresh Boundary.\n            if (self.$RefreshHelpers$.isReactRefreshBoundary(currentExports)) {\n                // Save the previous exports signature on update so we can compare the boundary\n                // signatures. We avoid saving exports themselves since it causes memory leaks (https://github.com/vercel/next.js/pull/53797)\n                module.hot.dispose(function (data) {\n                    data.prevSignature =\n                        self.$RefreshHelpers$.getRefreshBoundarySignature(currentExports);\n                });\n                // Unconditionally accept an update to this module, we'll check if it's\n                // still a Refresh Boundary later.\n                // @ts-ignore importMeta is replaced in the loader\n                module.hot.accept();\n                // This field is set when the previous version of this module was a\n                // Refresh Boundary, letting us know we need to check for invalidation or\n                // enqueue an update.\n                if (prevSignature !== null) {\n                    // A boundary can become ineligible if its exports are incompatible\n                    // with the previous exports.\n                    //\n                    // For example, if you add/remove/change exports, we'll want to\n                    // re-execute the importing modules, and force those components to\n                    // re-render. Similarly, if you convert a class component to a\n                    // function, we want to invalidate the boundary.\n                    if (self.$RefreshHelpers$.shouldInvalidateReactRefreshBoundary(prevSignature, self.$RefreshHelpers$.getRefreshBoundarySignature(currentExports))) {\n                        module.hot.invalidate();\n                    }\n                    else {\n                        self.$RefreshHelpers$.scheduleUpdate();\n                    }\n                }\n            }\n            else {\n                // Since we just executed the code for the module, it's possible that the\n                // new exports made it ineligible for being a boundary.\n                // We only care about the case when we were _previously_ a boundary,\n                // because we already accepted this update (accidental side effect).\n                var isNoLongerABoundary = prevSignature !== null;\n                if (isNoLongerABoundary) {\n                    module.hot.invalidate();\n                }\n            }\n        }\n    })();\n//# sourceURL=[module]\n//# sourceMappingURL=data:application/json;charset=utf-8;base64, \n//# sourceURL=webpack-internal:///(app-pages-browser)/./src/components/admin/DocumentUpload.tsx\n"));

/***/ })

});