import{t as e,p as t,H as s,c as i,h as o,F as a}from"./p-CAus4tQt.js";import{r as n}from"./p-DKrliuRO.js";import{u as r}from"./p-DrCYkHs5.js";import{I as l}from"./p-CulpZvvY.js";import{Z as c}from"./p-DBryW4-h.js";import{c as d}from"./p-DIuwqj_i.js";const u=t(class extends s{constructor(e){super(),!1!==e&&this.__registerHost(),this.contentChange=i(this,"contentChange",7)}content;contentChange;videoUrl="";isDialogOpen=!1;errorMessage;emitContent(e){this.content&&this.contentChange.emit({...this.content,...e})}openDialog(){const e=this.content;this.videoUrl=e?e.file_url:"",this.errorMessage=void 0,this.isDialogOpen=!0}closeDialog(){this.isDialogOpen=!1}handleUrlInput(e){this.videoUrl=e.target.value,this.errorMessage&&(this.errorMessage=void 0)}validateVideoUrl(e,t=!0){const s=r();return e.trim()?d(e)?(t&&(this.errorMessage=void 0),!0):(t&&(this.errorMessage=s("quick_message.video_link_invalid")),!1):(t&&(this.errorMessage=s("quick_message.video_link_required")),!1)}handleSaveVideo(){const e=this.videoUrl.trim();this.validateVideoUrl(e)&&(this.emitContent({file_url:e}),this.closeDialog())}buildVideoPreview(e){try{const t=new URL(e);if(/\.(mp4|webm|ogg)$/i.test(t.pathname))return{type:"video",src:e}}catch(e){}return{type:"video",src:e}}render(){if(!this.content)return null;const e=n.get("theme"),t=r(),s=this.content.file_url,i=s&&s?this.buildVideoPreview(s):void 0;return o("div",{class:"flex justify-end","data-theme":e},o("div",{class:"max-w-xs h-[220px] aspect-square"},o("button",{type:"button",class:"group relative flex aspect-square w-full items-center justify-center overflow-hidden rounded-[18px] border-[1.5px] bg-background shadow-sm transition-colors cursor-pointer border-primary",onClick:()=>this.openDialog()},i?o(a,null,o("video",{src:i.src,preload:"metadata",class:"h-[220px] object-cover",controls:!0},o("track",{kind:"captions",src:"",label:"English"})),o("div",{class:"absolute inset-0 flex flex-col items-center justify-center gap-2 bg-slate-900/60 opacity-0 transition-opacity group-hover:opacity-100"},o(l,{name:"Edit",addClass:"size-6 text-white"}),o("span",{class:"text-sm font-semibold text-white"},t("quick_message.change_video_link")))):o("div",{class:"flex flex-col items-center gap-2 px-6 text-center"},o(l,{name:"Play",addClass:"size-14 text-primary"}),o("span",{class:"text-base font-semibold leading-tight text-primary"},"+ ",t("quick_message.add_video")))),this.isDialogOpen&&this.renderDialog(t)))}renderDialog(e){return o("div",{class:"fixed inset-0 z-(--quick-message-modal-dialog-z-index,2147483010) flex items-center justify-center bg-slate-900/40 px-4",onClick:()=>this.closeDialog()},o("div",{class:"w-full max-w-md rounded-2xl border bg-background p-6 shadow-xl text-surface border-none",onClick:e=>e.stopPropagation()},o("div",{class:"flex items-start justify-between"},o("h3",{class:"text-base font-semibold"},e("quick_message.add_video")),o("button",{type:"button",class:"inline-flex cursor-pointer items-center justify-center rounded-full p-1",onClick:()=>this.closeDialog()},o(l,{name:"X"}))),o("div",{class:"mt-4 flex flex-col gap-4"},o("label",{class:"flex flex-col gap-2 text-sm font-medium"},e("quick_message.link_video"),o("input",{type:"url",value:this.videoUrl,placeholder:e("quick_message.type_video_link_here"),class:"rounded-xl border px-3 py-2 text-sm focus:outline-none ring-primary border-primary bg-background",onInput:e=>this.handleUrlInput(e)})),this.errorMessage&&o("p",{class:"text-xs text-red-500"},this.errorMessage)),o("div",{class:"mt-6 flex gap-3"},o(c,{variant:"outlined",onClick:()=>this.closeDialog(),fullWidth:!0,label:e("cancel")}),o(c,{variant:"primary",onClick:()=>this.handleSaveVideo(),fullWidth:!0,disabled:""===(this.videoUrl?this.videoUrl.trim():""),label:e("save")}))))}},[512,"quick-message-video-content",{content:[16],videoUrl:[32],isDialogOpen:[32],errorMessage:[32]}]);function p(){"undefined"!=typeof customElements&&["quick-message-video-content"].forEach((t=>{"quick-message-video-content"===t&&(customElements.get(e(t))||customElements.define(e(t),u))}))}p();export{u as Q,p as d}