"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useLogic = void 0;
const react_1 = require("react");
const useLogic = ({ startAdornment, isExpanded, onChange, subtitle, }) => {
    const [isUncontrolledExpanded, setIsUncontrolledExpanded] = (0, react_1.useState)(false);
    const isControlled = typeof isExpanded === 'boolean';
    const actualIsExpanded = isControlled ? isExpanded : isUncontrolledExpanded;
    const hasStartAdornment = Boolean(startAdornment);
    const hasSubtitle = Boolean(subtitle);
    const handleClick = (event) => {
        if (isControlled) {
            onChange?.(!isExpanded, event);
        }
        else {
            const newValue = !isUncontrolledExpanded;
            setIsUncontrolledExpanded(newValue);
            onChange?.(newValue, event);
        }
    };
    const handleKeyDown = (event) => {
        if (event.key === 'Enter' || event.key === ' ') {
            event.preventDefault();
            handleClick(event);
        }
    };
    return {
        handleClick,
        handleKeyDown,
        actualIsExpanded,
        isUncontrolledExpanded,
        hasStartAdornment,
        hasSubtitle,
    };
};
exports.useLogic = useLogic;
