import{t,p as e,H as n,c as s,h as i}from"./p-CAus4tQt.js";import{r as o}from"./p-DKrliuRO.js";import{u as a}from"./p-DrCYkHs5.js";import{Q as h,a as u}from"./p-C0cCRzP4.js";import{b as r,i as c}from"./p-DIuwqj_i.js";const l=e(class extends n{constructor(t){super(),!1!==t&&this.__registerHost(),this.contentChange=s(this,"contentChange",7)}content;maxLength=640;maxButtonCount=3;maxButtonNameLength=20;placeholder="พิมพ์ข้อความที่นี่";contentChange;isShowCreateButtonDialog=!1;createButtonLabel="";createButtonAction="";createButtonType="text";editingButtonId;emitContent(t){this.content&&this.contentChange.emit({...this.content,...t})}updateButtons(t){if(!this.content)return;const e=t(this.content.buttons||[]);this.emitContent({buttons:e})}reorderButtons(t,e){this.updateButtons((n=>{const s=n.findIndex((e=>e.id===t));if(-1===s)return n;const i="up"===e?s-1:s+1;if(i<0||i>=n.length)return n;const o=[...n];return[o[s],o[i]]=[o[i],o[s]],o}))}handleTextChange=t=>{this.emitContent({text:t.target.value})};openCreateButtonDialog(t){t?(this.editingButtonId=t.id,this.createButtonLabel=t.text||"",this.createButtonAction=t.action||"",this.createButtonType=t.action_type):(this.editingButtonId=void 0,this.createButtonLabel="",this.createButtonAction="",this.createButtonType="text"),this.isShowCreateButtonDialog=!0}closeCreateButtonDialog(){this.isShowCreateButtonDialog=!1,this.editingButtonId=void 0}handleCreateButtonSave(){const t=this.createButtonLabel.trim(),e=this.createButtonType,n=this.createButtonAction.trim(),s="text"===e?void 0:n,i="text"!==e&&(!n||"url"===e&&!r(n)||"tel"===e&&!c(n));if(t&&!i){if(this.editingButtonId){const n={id:this.editingButtonId,action_type:e,text:t,action:s};this.updateButtons((t=>t.map((t=>t.id===this.editingButtonId?n:t))))}else{const n={id:`button-${Date.now()}`,action_type:e,text:t,action:s};this.updateButtons((t=>[...t,n]))}this.closeCreateButtonDialog()}}setCreateButtonType(t){this.createButtonType=t,"text"===t&&(this.createButtonAction="")}handleDeleteEditingButton(){this.editingButtonId&&(this.updateButtons((t=>t.filter((t=>t.id!==this.editingButtonId)))),this.closeCreateButtonDialog())}render(){if(!this.content)return null;const t=o.get("theme"),e=this.content.text||"",n=this.content.buttons||[],s=a();return i("div",{class:"flex flex-col gap-4 items-end","data-theme":t},i("div",{class:"relative w-full max-w-md rounded-xl border-[1.5px] p-4 pb-8 focus:outline-none ring-primary border-primary"},i("textarea",{value:e,onInput:this.handleTextChange,placeholder:this.placeholder,class:"w-full border-primary pr-16 focus:outline-none ring-primary rounded-xl text-sm bg-background",maxLength:this.maxLength,rows:3}),i("div",{class:"flex items-center justify-end text-sm text-theme-gray"},e.length,"/",this.maxLength),i(h,{buttons:n,maxButtonCount:this.maxButtonCount,addButtonLabel:s("quick_message.add_button"),onButtonClick:t=>this.openCreateButtonDialog(t),onAddButton:()=>this.openCreateButtonDialog(),onReorderButton:(t,e)=>this.reorderButtons(t,e),listClass:"mt-2 flex flex-col gap-3",buttonClass:"px-2"}),i(u,{isOpen:this.isShowCreateButtonDialog,isEditing:!!this.editingButtonId,label:this.createButtonLabel,actionValue:this.createButtonAction,actionType:this.createButtonType,maxButtonNameLength:this.maxButtonNameLength,onLabelInput:t=>this.createButtonLabel=t,onActionInput:t=>this.createButtonAction=t,onActionTypeChange:t=>this.setCreateButtonType(t),onClose:()=>this.closeCreateButtonDialog(),onSave:()=>this.handleCreateButtonSave(),onDelete:this.editingButtonId?()=>this.handleDeleteEditingButton():void 0})))}},[512,"quick-message-button-content",{content:[16],maxLength:[2,"max-length"],maxButtonCount:[2,"max-button-count"],maxButtonNameLength:[2,"max-button-name-length"],placeholder:[1],isShowCreateButtonDialog:[32],createButtonLabel:[32],createButtonAction:[32],createButtonType:[32],editingButtonId:[32]}]);function m(){"undefined"!=typeof customElements&&["quick-message-button-content"].forEach((e=>{"quick-message-button-content"===e&&(customElements.get(t(e))||customElements.define(t(e),l))}))}m();export{l as Q,m as d}