1"use strict";
2var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3    if (k2 === undefined) k2 = k;
4    var desc = Object.getOwnPropertyDescriptor(m, k);
5    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6      desc = { enumerable: true, get: function() { return m[k]; } };
7    }
8    Object.defineProperty(o, k2, desc);
9}) : (function(o, m, k, k2) {
10    if (k2 === undefined) k2 = k;
11    o[k2] = m[k];
12}));
13var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14    Object.defineProperty(o, "default", { enumerable: true, value: v });
15}) : function(o, v) {
16    o["default"] = v;
17});
18var __importStar = (this && this.__importStar) || function (mod) {
19    if (mod && mod.__esModule) return mod;
20    var result = {};
21    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22    __setModuleDefault(result, mod);
23    return result;
24};
25var __importDefault = (this && this.__importDefault) || function (mod) {
26    return (mod && mod.__esModule) ? mod : { "default": mod };
27};
28Object.defineProperty(exports, "__esModule", { value: true });
29exports.LogBoxInspectorStackFrames = exports.getCollapseMessage = void 0;
30/**
31 * Copyright (c) 650 Industries.
32 * Copyright (c) Meta Platforms, Inc. and affiliates.
33 *
34 * This source code is licensed under the MIT license found in the
35 * LICENSE file in the root directory of this source tree.
36 */
37const react_1 = __importStar(require("react"));
38const react_native_1 = require("react-native");
39const LogBoxInspectorSection_1 = require("./LogBoxInspectorSection");
40const LogBoxInspectorSourceMapStatus_1 = require("./LogBoxInspectorSourceMapStatus");
41const LogBoxInspectorStackFrame_1 = require("./LogBoxInspectorStackFrame");
42const LogContext_1 = require("../Data/LogContext");
43const LogBoxButton_1 = require("../UI/LogBoxButton");
44const LogBoxStyle = __importStar(require("../UI/LogBoxStyle"));
45const openFileInEditor_1 = __importDefault(require("../modules/openFileInEditor"));
46function getCollapseMessage(stackFrames, collapsed) {
47    if (stackFrames.length === 0) {
48        return 'No frames to show';
49    }
50    const collapsedCount = stackFrames.reduce((count, { collapse }) => {
51        if (collapse === true) {
52            return count + 1;
53        }
54        return count;
55    }, 0);
56    if (collapsedCount === 0) {
57        return 'Showing all frames';
58    }
59    const framePlural = `frame${collapsedCount > 1 ? 's' : ''}`;
60    if (collapsedCount === stackFrames.length) {
61        return collapsed
62            ? `See${collapsedCount > 1 ? ' all ' : ' '}${collapsedCount} collapsed ${framePlural}`
63            : `Collapse${collapsedCount > 1 ? ' all ' : ' '}${collapsedCount} ${framePlural}`;
64    }
65    else {
66        return collapsed
67            ? `See ${collapsedCount} more ${framePlural}`
68            : `Collapse ${collapsedCount} ${framePlural}`;
69    }
70}
71exports.getCollapseMessage = getCollapseMessage;
72function LogBoxInspectorStackFrames({ onRetry, type }) {
73    const log = (0, LogContext_1.useSelectedLog)();
74    const [collapsed, setCollapsed] = (0, react_1.useState)(() => {
75        // Only collapse frames initially if some frames are not collapsed.
76        return log.getAvailableStack(type)?.some(({ collapse }) => !collapse);
77    });
78    function getStackList() {
79        if (collapsed === true) {
80            return log.getAvailableStack(type)?.filter(({ collapse }) => !collapse);
81        }
82        else {
83            return log.getAvailableStack(type);
84        }
85    }
86    if (log.getAvailableStack(type)?.length === 0) {
87        return null;
88    }
89    return (react_1.default.createElement(LogBoxInspectorSection_1.LogBoxInspectorSection, { heading: type === 'component' ? 'Component Stack' : 'Call Stack', action: react_1.default.createElement(LogBoxInspectorSourceMapStatus_1.LogBoxInspectorSourceMapStatus, { onPress: log.symbolicated[type].status === 'FAILED' ? onRetry : null, status: log.symbolicated[type].status }) },
90        log.symbolicated[type].status !== 'COMPLETE' && (react_1.default.createElement(react_native_1.View, { style: stackStyles.hintBox },
91            react_1.default.createElement(react_native_1.Text, { style: stackStyles.hintText }, "This call stack is not symbolicated. Some features are unavailable such as viewing the function name or tapping to open files."))),
92        react_1.default.createElement(StackFrameList, { list: getStackList(), status: log.symbolicated[type].status }),
93        react_1.default.createElement(StackFrameFooter, { onPress: () => setCollapsed(!collapsed), message: getCollapseMessage(log.getAvailableStack(type), !!collapsed) })));
94}
95exports.LogBoxInspectorStackFrames = LogBoxInspectorStackFrames;
96function StackFrameList({ list, status, }) {
97    return list.map((frame, index) => {
98        const { file, lineNumber } = frame;
99        return (react_1.default.createElement(LogBoxInspectorStackFrame_1.LogBoxInspectorStackFrame, { key: index, frame: frame, onPress: status === 'COMPLETE' && file != null && lineNumber != null
100                ? () => (0, openFileInEditor_1.default)(file, lineNumber)
101                : undefined }));
102    });
103}
104function StackFrameFooter({ message, onPress }) {
105    return (react_1.default.createElement(react_native_1.View, { style: stackStyles.collapseContainer },
106        react_1.default.createElement(LogBoxButton_1.LogBoxButton, { backgroundColor: {
107                default: 'transparent',
108                pressed: LogBoxStyle.getBackgroundColor(1),
109            }, onPress: onPress, style: stackStyles.collapseButton },
110            react_1.default.createElement(react_native_1.Text, { style: stackStyles.collapse }, message))));
111}
112const stackStyles = react_native_1.StyleSheet.create({
113    section: {
114        marginTop: 15,
115    },
116    heading: {
117        alignItems: 'center',
118        flexDirection: 'row',
119        paddingHorizontal: 12,
120        marginBottom: 10,
121    },
122    headingText: {
123        color: LogBoxStyle.getTextColor(1),
124        flex: 1,
125        fontSize: 20,
126        fontWeight: '600',
127        includeFontPadding: false,
128        lineHeight: 20,
129    },
130    body: {
131        paddingBottom: 10,
132    },
133    bodyText: {
134        color: LogBoxStyle.getTextColor(1),
135        fontSize: 14,
136        includeFontPadding: false,
137        lineHeight: 18,
138        fontWeight: '500',
139        paddingHorizontal: 27,
140    },
141    hintText: {
142        color: LogBoxStyle.getTextColor(0.7),
143        fontSize: 13,
144        includeFontPadding: false,
145        lineHeight: 18,
146        fontWeight: '400',
147        marginHorizontal: 10,
148    },
149    hintBox: {
150        backgroundColor: LogBoxStyle.getBackgroundColor(),
151        marginHorizontal: 10,
152        paddingHorizontal: 5,
153        paddingVertical: 10,
154        borderRadius: 5,
155        marginBottom: 5,
156    },
157    collapseContainer: {
158        marginLeft: 15,
159        flexDirection: 'row',
160    },
161    collapseButton: {
162        borderRadius: 5,
163    },
164    collapse: {
165        color: LogBoxStyle.getTextColor(0.7),
166        fontSize: 12,
167        fontWeight: '300',
168        lineHeight: 20,
169        marginTop: 0,
170        paddingHorizontal: 10,
171        paddingVertical: 5,
172    },
173});
174//# sourceMappingURL=LogBoxInspectorStackFrames.js.map