function e(e,t){return{type:`message`,label:e.slice(0,20),text:t??e}}function t(e,t){return{type:`uri`,label:e.slice(0,20),uri:t}}function n(e,t,n){return{type:`postback`,label:e.slice(0,20),data:t.slice(0,300),displayText:n?.slice(0,300)}}function r(e,t,n,r){return{type:`datetimepicker`,label:e.slice(0,20),data:t.slice(0,300),mode:n,initial:r?.initial,max:r?.max,min:r?.min}}function i(r){return r.type===`uri`&&r.uri?t(r.label,r.uri):r.type===`postback`&&r.data?n(r.label,r.data,r.label):e(r.label,r.data??r.label)}function a(e,t,n,r){let i={type:`confirm`,text:e.slice(0,240),actions:[t,n]};return{type:`template`,altText:r?.slice(0,400)??e.slice(0,400),template:i}}function o(e,t,n,r){let i=r?.thumbnailImageUrl?.trim()?160:60,a={type:`buttons`,title:e.slice(0,40),text:t.slice(0,i),actions:n.slice(0,4),thumbnailImageUrl:r?.thumbnailImageUrl,imageAspectRatio:r?.imageAspectRatio??`rectangle`,imageSize:r?.imageSize??`cover`,imageBackgroundColor:r?.imageBackgroundColor,defaultAction:r?.defaultAction};return{type:`template`,altText:r?.altText?.slice(0,400)??`${e}: ${t}`.slice(0,400),template:a}}function s(e,t){let n={type:`carousel`,columns:e.slice(0,10),imageAspectRatio:t?.imageAspectRatio??`rectangle`,imageSize:t?.imageSize??`cover`};return{type:`template`,altText:t?.altText?.slice(0,400)??`View carousel`,template:n}}function c(e){return{title:e.title?.slice(0,40),text:e.text.slice(0,120),actions:e.actions.slice(0,3),thumbnailImageUrl:e.thumbnailImageUrl,imageBackgroundColor:e.imageBackgroundColor,defaultAction:e.defaultAction}}function l(e,t){let n={type:`image_carousel`,columns:e.slice(0,10)};return{type:`template`,altText:t?.slice(0,400)??`View images`,template:n}}function u(e,t){return{imageUrl:e,action:t}}function d(t,r){return a(t,r?.yesData?n(r.yesText??`Yes`,r.yesData,r.yesText??`Yes`):e(r?.yesText??`Yes`),r?.noData?n(r.noText??`No`,r.noData,r.noText??`No`):e(r?.noText??`No`),r?.altText)}function f(t,n,r,i){return o(t,n,r.slice(0,4).map(t=>e(t.label,t.text)),{thumbnailImageUrl:i?.thumbnailImageUrl,altText:i?.altText})}function p(e,n,r,i){return o(e,n,r.slice(0,4).map(e=>t(e.label,e.url)),{thumbnailImageUrl:i?.thumbnailImageUrl,altText:i?.altText})}function m(r,i){return s(r.slice(0,10).map(r=>{let i=[];return r.actionUrl?i.push(t(r.actionLabel??`View`,r.actionUrl)):r.actionData?i.push(n(r.actionLabel??`Select`,r.actionData)):i.push(e(r.actionLabel??`Select`,r.title)),c({title:r.title,text:r.price?`${r.description}\n${r.price}`.slice(0,120):r.description,thumbnailImageUrl:r.imageUrl,actions:i})}),{altText:i})}function h(r){switch(r.type){case`confirm`:{let i=r.confirmData.startsWith(`http`)?t(r.confirmLabel,r.confirmData):r.confirmData.includes(`=`)?n(r.confirmLabel,r.confirmData,r.confirmLabel):e(r.confirmLabel,r.confirmData),o=r.cancelData.startsWith(`http`)?t(r.cancelLabel,r.cancelData):r.cancelData.includes(`=`)?n(r.cancelLabel,r.cancelData,r.cancelLabel):e(r.cancelLabel,r.cancelData);return a(r.text,i,o,r.altText)}case`buttons`:{let e=r.actions.slice(0,4).map(e=>i(e));return o(r.title,r.text,e,{thumbnailImageUrl:r.thumbnailImageUrl,altText:r.altText})}case`carousel`:return s(r.columns.slice(0,10).map(e=>{let t=e.actions.slice(0,3).map(e=>i(e));return c({title:e.title,text:e.text,thumbnailImageUrl:e.thumbnailImageUrl,actions:t})}),{altText:r.altText});default:return null}}export{h as buildTemplateMessageFromPayload,f as createButtonMenu,o as createButtonTemplate,c as createCarouselColumn,a as createConfirmTemplate,l as createImageCarousel,u as createImageCarouselColumn,p as createLinkMenu,m as createProductCarousel,s as createTemplateCarousel,d as createYesNoConfirm,r as datetimePickerAction,e as messageAction,n as postbackAction,t as uriAction};
