import { html } from "lit";
import { multiClassMap, tw } from "../../../directives/multi-class-map.js";
import minus from "../../../images/minus.js";
import plus from "../../../images/plus.js";
import { renderButton } from "../button.js";
import "../atomic-icon/atomic-icon.js";
import { ref } from "lit/directives/ref.js";
const getLineClampClass = (truncateAfter)=>{
    const lineClampMap = {
        none: 'line-clamp-none',
        1: 'line-clamp-1',
        2: 'line-clamp-2',
        3: 'line-clamp-3',
        4: 'line-clamp-4'
    };
    return lineClampMap[truncateAfter] || 'line-clamp-2';
};
const renderExpandableText = ({ props: { isExpanded, isTruncated, isCollapsible, truncateAfter, onToggleExpand, showMoreLabel, showLessLabel, textRef } })=>(children)=>{
        const expandableTextClasses = tw({
            'expandable-text leading-[var(--line-height)]': true,
            [getLineClampClass(truncateAfter)]: !isExpanded,
            [`min-lines-${truncateAfter}`]: true
        });
        const buttonClasses = tw({
            'expandable-text-button p-1 text-xs leading-[calc(1/.75)]': true,
            invisible: !isTruncated && !isExpanded,
            hidden: isExpanded && (!isTruncated || !isCollapsible)
        });
        const buttonClassString = Object.entries(buttonClasses).filter(([, value])=>value).map(([key])=>key).join(' ');
        const buttonLabel = isExpanded ? showLessLabel : showMoreLabel;
        const icon = isExpanded ? minus : plus;
        return html`<div class="flex flex-col items-start">
      <div
        part="expandable-text"
        class="${multiClassMap(expandableTextClasses)}"
        ${ref(textRef)}
      >
        ${children}
      </div>

      ${renderButton({
            props: {
                style: 'text-primary',
                class: buttonClassString,
                title: buttonLabel,
                onClick: onToggleExpand
            }
        })(html` <atomic-icon
            icon="${icon}"
            class="mx-1 w-2 align-baseline"
          ></atomic-icon>
          ${buttonLabel}`)}
    </div>`;
    };
export { renderExpandableText };
