"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AccountBalanceCard = AccountBalanceCard;
exports.AccountBalanceCardIcon = AccountBalanceCardIcon;
exports.AccountBalanceCardHeader = AccountBalanceCardHeader;
exports.AccountBalanceCardTitle = AccountBalanceCardTitle;
exports.AccountBalanceCardDeleteButton = AccountBalanceCardDeleteButton;
exports.AccountBalanceCardContent = AccountBalanceCardContent;
exports.AccountBalanceCardLoading = AccountBalanceCardLoading;
exports.AccountBalanceCardEmpty = AccountBalanceCardEmpty;
exports.AccountBalanceCardInfo = AccountBalanceCardInfo;
exports.AccountBalanceCardUpdateButton = AccountBalanceCardUpdateButton;
exports.AccountBalanceCardTrigger = AccountBalanceCardTrigger;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = __importDefault(require("react"));
const react_collapsible_1 = require("@radix-ui/react-collapsible");
const utils_1 = require("../../../lib/utils");
const card_1 = require("../../../components/ui/card");
const button_1 = require("../../../components/ui/button");
const lucide_react_1 = require("lucide-react");
const collapsible_1 = require("../../../components/ui/collapsible");
const skeleton_1 = require("../../../components/ui/skeleton");
const use_time_1 = require("../../../hooks/use-time");
const dayjs_1 = __importDefault(require("dayjs"));
const icon_button_1 = require("../../../components/ui/icon-button");
const AccountBalanceCardContext = react_1.default.createContext({
    open: false
});
function AccountBalanceCard({ className, open, onOpenChange, children, ...props }) {
    return ((0, jsx_runtime_1.jsx)(react_collapsible_1.Collapsible, { open: open, onOpenChange: onOpenChange, "data-slot": "account-balance-card", className: (0, utils_1.cn)('w-full', className), ...props, children: (0, jsx_runtime_1.jsx)(AccountBalanceCardContext.Provider, { value: { open }, children: (0, jsx_runtime_1.jsx)(card_1.Card, { className: "relative gap-2 px-5 py-4 shadow-xs", children: children }) }) }));
}
function AccountBalanceCardIcon({ className, ...props }) {
    return ((0, jsx_runtime_1.jsx)(lucide_react_1.User, { "data-slot": "account-balance-card-icon", strokeWidth: 1, className: (0, utils_1.cn)('text-foreground mb-[14px] size-8 opacity-40', className), ...props }));
}
function AccountBalanceCardHeader({ className, ...props }) {
    return ((0, jsx_runtime_1.jsx)("div", { "data-slot": "account-balance-card-header", className: (0, utils_1.cn)('flex flex-col', className), ...props }));
}
function AccountBalanceCardTitle({ className, ...props }) {
    return ((0, jsx_runtime_1.jsx)("p", { "data-slot": "account-balance-card-title", className: (0, utils_1.cn)('text-shadcn-600 text-lg font-bold', className), ...props }));
}
function AccountBalanceCardDeleteButton({ className, ...props }) {
    return ((0, jsx_runtime_1.jsx)(icon_button_1.IconButton, { variant: "outline", size: "small", rounded: true, "data-slot": "account-balance-card-delete-button", className: (0, utils_1.cn)('absolute top-3 right-3', className), ...props, children: (0, jsx_runtime_1.jsx)(lucide_react_1.Trash, { className: "text-muted-foreground h-4 w-4" }) }));
}
function AccountBalanceCardContent({ className, ...props }) {
    return ((0, jsx_runtime_1.jsx)(collapsible_1.CollapsibleContent, { "data-slot": "account-balance-card-content", className: (0, utils_1.cn)('data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down overflow-hidden', className), ...props }));
}
function AccountBalanceCardLoading({ className, ...props }) {
    return ((0, jsx_runtime_1.jsx)(skeleton_1.Skeleton, { "data-slot": "account-balance-card-loading", className: (0, utils_1.cn)('bg-muted mt-3 h-3 w-full rounded-md', className), ...props }));
}
function AccountBalanceCardEmpty({ className, ...props }) {
    return ((0, jsx_runtime_1.jsx)("p", { "data-slot": "account-balance-card-empty", className: (0, utils_1.cn)('text-shadcn-500 mt-3 text-center text-sm font-normal', className), ...props }));
}
function AccountBalanceCardInfo({ className, assetCode, value, children: _children, ref, ...props }) {
    return ((0, jsx_runtime_1.jsxs)("div", { ref: ref, "data-slot": "account-balance-card-info", className: (0, utils_1.cn)('text-shadcn-500 mt-3 flex flex-row items-center justify-between text-sm font-normal', className), ...props, children: [(0, jsx_runtime_1.jsx)("p", { children: assetCode }), (0, jsx_runtime_1.jsx)("p", { children: value })] }));
}
function AccountBalanceCardUpdateButton({ className: _className, loading, timestamp, loadingLabel = 'Updating...', updatedInLabel = 'Updated in', updatedLabel = 'Updated', onRefresh, children: _children, ref, ...props }) {
    const _time = (0, use_time_1.useTime)({ interval: 1000 * 60 });
    const updated = react_1.default.useMemo(() => {
        return !(0, dayjs_1.default)(timestamp).isBefore((0, dayjs_1.default)().subtract(1, 'minute'));
    }, [_time, timestamp]);
    return ((0, jsx_runtime_1.jsxs)("div", { className: "mb-3 flex flex-row items-center justify-end gap-2", children: [(0, jsx_runtime_1.jsxs)("p", { className: "text-shadcn-500 text-xs font-medium", children: [loading && loadingLabel, !loading && !updated && updatedInLabel, !loading && updated && updatedLabel] }), !loading && updated && ((0, jsx_runtime_1.jsx)(lucide_react_1.CheckCircle2, { className: "h-4 w-4 text-green-600" })), (!updated || loading) && ((0, jsx_runtime_1.jsx)(button_1.Button, { ref: ref, variant: "link", "data-slot": "account-balance-card-update-button", className: "h-3 p-0", onClick: onRefresh, disabled: loading, ...props, children: (0, jsx_runtime_1.jsx)(lucide_react_1.RefreshCw, { className: (0, utils_1.cn)('size-4', { 'animate-spin': loading }) }) }))] }));
}
function AccountBalanceCardTrigger({ className, openLabel, closeLabel, children: _children, ...props }) {
    const { open } = react_1.default.useContext(AccountBalanceCardContext);
    return ((0, jsx_runtime_1.jsx)(collapsible_1.CollapsibleTrigger, { asChild: true, children: (0, jsx_runtime_1.jsx)(button_1.Button, { variant: "link", "data-slot": "account-balance-card-trigger", className: (0, utils_1.cn)('text-shadcn-600/40 h-4 p-0 text-xs', className), ...props, children: !open ? openLabel : closeLabel }) }));
}
