"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getServerSideProps = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
/*
 *  This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */
const antd_1 = require("antd");
const link_1 = __importDefault(require("next/link"));
const path_contents_1 = __importDefault(require("components/share/path-contents"));
const path_actions_1 = __importDefault(require("components/share/path-actions"));
const loading_1 = __importDefault(require("components/share/loading"));
const get_public_path_info_1 = __importDefault(require("lib/share/get-public-path-info"));
const counter_1 = __importDefault(require("lib/share/counter"));
const layout_1 = require("components/share/layout");
const with_customize_1 = __importDefault(require("lib/with-customize"));
const customize_1 = require("lib/share/customize");
const util_1 = require("lib/share/util");
function PublicPath(props) {
    const { id, project_id, path, relativePath, contents, error, customize } = props;
    (0, counter_1.default)(id);
    if (id == null)
        return (0, jsx_runtime_1.jsx)(loading_1.default, { style: { fontSize: "30px" } });
    return ((0, jsx_runtime_1.jsx)(customize_1.Customize, { value: customize, children: (0, jsx_runtime_1.jsxs)(layout_1.Embed, { title: (0, util_1.getTitle)({ path, relativePath }), children: [(0, jsx_runtime_1.jsx)("div", { style: {
                        backgroundColor: "white",
                        display: "inline-block",
                        padding: "0 5px",
                        margin: "5px",
                        width: "100%",
                    }, children: (0, jsx_runtime_1.jsx)(path_actions_1.default, { id: id, path: path, project_id: project_id, relativePath: relativePath, isDir: !!contents?.isdir, exclude: new Set(["embed"]) }) }), contents != null && ((0, jsx_runtime_1.jsx)(path_contents_1.default, { id: id, relativePath: relativePath, path: path, ...contents })), error != null && ((0, jsx_runtime_1.jsx)(antd_1.Alert, { showIcon: true, type: "error", style: { maxWidth: "700px", margin: "30px auto" }, message: "Error loading file", description: (0, jsx_runtime_1.jsxs)("div", { children: ["There was a problem loading \"", relativePath, "\" in", " ", (0, jsx_runtime_1.jsx)(link_1.default, { href: `/share/public_paths/${id}`, children: (0, jsx_runtime_1.jsxs)("a", { children: [path, "."] }) }), (0, jsx_runtime_1.jsx)("br", {}), (0, jsx_runtime_1.jsx)("br", {}), error] }) }))] }) }));
}
exports.default = PublicPath;
async function getServerSideProps(context) {
    const id = context.params.id[0];
    const relativePath = context.params.id.slice(1).join("/");
    try {
        const props = await (0, get_public_path_info_1.default)({
            id,
            relativePath,
            req: context.req,
        });
        return await (0, with_customize_1.default)({
            context,
            props: { ...props, layout: "embed" },
        });
    }
    catch (_err) {
        console.log(_err);
        return { notFound: true };
    }
}
exports.getServerSideProps = getServerSideProps;
//# sourceMappingURL=%5B...id%5D.js.map