import{getResponsiveValueByScreen as t}from"@gem-sdk/core";import{getImageSrc as e,composeAspectRatio as o}from"../../image/common/helpers.js";let getAspectRatioData=({styles:t,leftImage:e,rightImage:o})=>{let i=(e?.width??0)/(e?.height??1),a=(o?.width??0)/(o?.height??1),l=i<=a?`${e?.width??0}/${e?.height??1}`:`${o?.width??0}/${o?.height??1}`,s=i<=a?e:o,r=composeResponsiveAspectRatio({aspect:t?.aspectRatio,auto:s,custom:t?.customAspectRadio,defaultRatio:l});return{defaultRatio:l,responsiveAspectRatio:r}},composeResponsiveAspectRatio=({aspect:t,auto:e,custom:i,defaultRatio:a})=>({desktop:o({device:"desktop",aspect:t,auto:e,custom:i})??a,tablet:o({device:"tablet",aspect:t,auto:e,custom:i}),mobile:o({device:"mobile",aspect:t,auto:e,custom:i})}),composeLabelPosition=({input:e,isHorizontal:o})=>{let{device:i,positionHoz:a,positionVer:l}=e,s=o?t(a,i,"hoz-center"):t(l,i,"ver-center"),r={topLeft:"50%",bottomRight:"auto"};return({"hoz-center":{topLeft:"50%",bottomRight:"auto"},top:{topLeft:"8px",bottomRight:"auto"},bottom:{topLeft:"auto",bottomRight:"8px"},"ver-center":{topLeft:"50%",bottomRight:"auto"},left:{topLeft:"8px",bottomRight:"auto"},right:{topLeft:"auto",bottomRight:"8px"}})[s]??r},getLabelPosition=({position:t,labelPositionHoz:e,labelPositionVer:o,isHorizontal:i})=>({desktop:composeLabelPosition({input:{device:"desktop",positionHoz:e,positionVer:o},isHorizontal:i})?.[t??"topLeft"],tablet:composeLabelPosition({input:{device:"tablet",positionHoz:e,positionVer:o},isHorizontal:i})?.[t??"topLeft"],mobile:composeLabelPosition({input:{device:"mobile",positionHoz:e,positionVer:o},isHorizontal:i})?.[t??"topLeft"]}),generateTranslateByDevices=({isHorizontal:t,labelPositionHoz:e,labelPositionVer:o})=>{let i=t?e:o,a={desktop:i?.desktop??"hoz-center",tablet:i?.tablet??i?.desktop??"hoz-center",mobile:i?.mobile??i?.tablet??i?.desktop??"hoz-center"},l={desktop:"translateX(0) translateY(0)",tablet:"translateX(0) translateY(0)",mobile:"translateX(0) translateY(0)"};for(let e in a){let o=a?.[e];o.includes("center")?l[e]=t?"translateX(0) translateY(-50%)":"translateX(-50%) translateY(0)":l[e]="translateX(0) translateY(0)"}return l},getSliderPositionPercentage=t=>{let e="string"==typeof t?parseInt(t??0):t;return(e??50)/100},FLEX_ALIGN={left:"start",center:"center",right:"end",justify:"start"},getData=t=>{let{handle:o=null,hover:i=!1,handleSize:a=40,leftImageAlt:l="",leftImageTitle:s="",leftImageCss:r={},leftImageLabel:n=null,rightImageAlt:p="",rightImageTitle:g="",rightImageCss:c={},rightImageLabel:u=null,sliderLineWidth:m=2,sliderLineColor:b="#ffffff",sliderPositionPercentage:h=.5,vertical:d=!1,componentUid:f="",styles:L={},leftImage:y,rightImage:R,enableLabel:S=!1,qualityType:P,qualityPercent:v}=t,C=!d,k=S&&!!n,x=S&&!!u,A=(y?.width??0)<(R?.width??0)?{...y}:{...R},I=t=>{let{isLiquid:o}=t??{};return o?e(y):y?.src??""},$=t=>{let{isLiquid:o}=t??{};return o?e(R):R?.src??""},{responsiveAspectRatio:z,defaultRatio:X}=getAspectRatioData({leftImage:y,rightImage:R,styles:L});return{styles:L,handle:o,hover:i,handleSize:a,leftImageAlt:l,leftImageTitle:s,leftImageCss:r,leftImageLabel:n,rightImageAlt:p,rightImageTitle:g,rightImageCss:c,rightImageLabel:u,sliderLineWidth:m,sliderLineColor:b,sliderPositionPercentage:h,vertical:d,componentUid:f,tempImage:A,aspectRatio:z,defaultRatio:X,isHorizontal:C,hasLeftLabel:k,hasRightLabel:x,qualityType:P,qualityPercent:v,getLeftImageSrc:I,getRightImageSrc:$}},getImageClipStyle=t=>{let{isHorizontal:e,containerWidth:o,containerHeight:i,sliderPosition:a,type:l}=t,s=e?o*a:i*a;return"left"===l?{clip:e?`rect(auto, ${s}px, auto, auto)`:`rect(auto, auto, ${s}px, auto)`}:{clip:e?`rect(auto, auto, auto, ${s}px)`:`rect(${s}px, auto, auto, auto)`}},getSliderPositionStyle=t=>{let{isHorizontal:e,containerWidth:o,containerHeight:i,sliderPosition:a,handleSize:l}=t,s=e?o*a:i*a,r=l/2;return{[e?"top":"left"]:0,[e?"left":"top"]:`${s-r}px`}},getLabelContainerStyles=t=>({...getImageClipStyle(t)}),getReactStyles=t=>({sliderPosition:getSliderPositionStyle(t),leftImageClip:getImageClipStyle({...t,type:"left"}),rightImageClip:getImageClipStyle({...t,type:"right"}),leftLabelContainer:getLabelContainerStyles({...t,type:"left"}),rightLabelContainer:getLabelContainerStyles({...t,type:"right"})});export{FLEX_ALIGN,composeLabelPosition,composeResponsiveAspectRatio,generateTranslateByDevices,getAspectRatioData,getData,getImageClipStyle,getLabelContainerStyles,getLabelPosition,getReactStyles,getSliderPositionPercentage,getSliderPositionStyle};
