import{h}from"@stencil/core";import{__}from"@wordpress/i18n";export class ScProductLineItemNote{constructor(){this.note=void 0,this.expanded=!1,this.isOverflowing=!1}componentDidLoad(){this.setupObservers(),this.checkOverflow()}disconnectedCallback(){this.cleanupObservers()}setupObservers(){this.noteEl&&("undefined"!=typeof ResizeObserver&&(this.resizeObserver=new ResizeObserver((()=>{this.checkOverflow()})),this.resizeObserver.observe(this.noteEl)),"undefined"!=typeof MutationObserver&&(this.mutationObserver=new MutationObserver((()=>{this.checkOverflow()})),this.mutationObserver.observe(this.noteEl,{characterData:!0,subtree:!0,childList:!0})))}cleanupObservers(){this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=void 0),this.mutationObserver&&(this.mutationObserver.disconnect(),this.mutationObserver=void 0)}checkOverflow(){this.noteEl&&(this.isOverflowing=this.noteEl.scrollHeight>this.noteEl.clientHeight)}toggle(){this.expanded=!this.expanded}render(){return this.note?h("div",{class:"base",part:"base"},h("div",{class:{"line-item-note":!0,"line-item-note--is-expanded":this.expanded,"line-item-note--clickable":this.isOverflowing||this.expanded},tabIndex:this.isOverflowing||this.expanded?0:void 0,onClick:()=>(this.isOverflowing||this.expanded)&&this.toggle()},h("div",{ref:e=>this.noteEl=e,class:"line-item-note__text"},this.note),(this.isOverflowing||this.expanded)&&h("button",{class:"line-item-note__toggle",type:"button",onClick:e=>{e.stopPropagation(),this.toggle()},title:this.expanded?__("Collapse note","surecart"):__("Expand note","surecart")},h("slot",{name:"icon"},h("sc-icon",{name:this.expanded?"chevron-up":"chevron-down",style:{width:"16px",height:"16px"}}))))):null}static get is(){return"sc-product-line-item-note"}static get encapsulation(){return"shadow"}static get originalStyleUrls(){return{$:["sc-product-line-item-note.scss"]}}static get styleUrls(){return{$:["sc-product-line-item-note.css"]}}static get properties(){return{note:{type:"string",mutable:!1,complexType:{original:"string",resolved:"string",references:{}},required:!1,optional:!1,docs:{tags:[],text:""},attribute:"note",reflect:!1}}}static get states(){return{expanded:{},isOverflowing:{}}}static get elementRef(){return"el"}}