import{DEVICES as t}from"@gem-sdk/core";import{getDeviceSpecificStyle as e}from"./common.js";let appendPixelUnitIfNeed=t=>t?.includes("px")?t:`${t}px`,convertAutoToZero=t=>["auto","Auto",void 0].includes(t)?"0px":appendPixelUnitIfNeed(`${t}`),getGapWhenOnlyFeature=t=>{let{device:o,position:a,leftGap:r,rightGap:n}=t,l=e(t?.imageShape,o)?.width||"100%",u=e(t?.imageAlign,o);switch(a){case"left":return"flex-end"===u?`calc((100% - ${l}) + ${r})`:"center"===u?`calc((100% - ${l}) / 2 + ${r})`:r;case"center":return"flex-end"===u?`calc((200% - ${l}) / 2 + ${r})`:"center"===u?"50%":`calc(${l} / 2 + ${r})`;case"right":return"flex-start"===u?`calc((100% - ${l}) + ${n})`:"center"===u?`calc((100% - ${l}) / 2 + ${n})`:n}},getGapWhenNotOnlyFeature=t=>{let{position:e,leftGap:o,rightGap:a}=t;switch(e){case"left":return o;case"center":return"50%";case"right":return a}},getGapCompareProductImage=t=>{let{device:o,imageLayout:a}=t,r=e(a,o);return"only-feature"===r?getGapWhenOnlyFeature(t):getGapWhenNotOnlyFeature(t)},getValuePositon=(t,e,o)=>e?o:getGapCompareProductImage(t),getGapBottom=t=>{let{device:o,bottomGap:a,dotSize:r,dotGapToCarousel:n,key:l,dotStyle:u,imageLayout:s,isLiquid:i}=t,$=e(u,o),c=e(s,o);return i&&"outside"===$?{[`--bottom${l}`]:a}:"none"!==$&&"only-feature"===c?{[`--bottom${l}`]:`calc(${r?.[o]||r?.desktop||0}px + ${n?.[t.device]||n?.desktop||0}px + ${a})`}:{[`--bottom${l}`]:a}},getShapePosition=o=>{let{positionType:a,isLiquid:r,navigationPosition:n,dataImage:l}=o;return t.reduce((t,o)=>{let u="desktop"===o?"":`-${o}`,s=e(a,o)?.placement||"",i=convertAutoToZero(e(a,o)?.topGap),$=convertAutoToZero(e(a,o)?.rightGap),c=convertAutoToZero(e(a,o)?.bottomGap),g=convertAutoToZero(e(a,o)?.leftGap);n?.[o]!=="outside"||["bottom","top"].includes(s)||($=`calc(${$} + 56px)`,g=`calc(${g} + 56px)`);let p=t=>({position:t,device:o,imageLayout:l?.imageLayout,imageAlign:l?.imageAlign,imageShape:l?.imageShape,leftGap:g,rightGap:$}),m={device:o,bottomGap:c,key:u,dotSize:l?.dotSize,dotGapToCarousel:l?.dotGapToCarousel,dotStyle:l?.dotStyle,imageLayout:l?.imageLayout,isLiquid:r},h={};switch(s){case"top-left":h={[`--top${u}`]:i,[`--left${u}`]:getValuePositon(p("left"),r,g),[`--right${u}`]:"unset",[`--bottom${u}`]:"unset",[`--t${u}`]:"unset"};break;case"top":h={[`--top${u}`]:i,[`--left${u}`]:getValuePositon(p("center"),r,"50%"),[`--right${u}`]:"unset",[`--bottom${u}`]:"unset",[`--t${u}`]:"translateX(-50%)"};break;case"top-right":h={[`--top${u}`]:i,[`--right${u}`]:getValuePositon(p("right"),r,$),[`--left${u}`]:"unset",[`--bottom${u}`]:"unset",[`--t${u}`]:"unset"};break;case"left":h={[`--top${u}`]:"50%",[`--left${u}`]:getValuePositon(p("left"),r,g),[`--right${u}`]:"unset",[`--bottom${u}`]:"unset",[`--t${u}`]:"translateY(-50%)"};break;case"right":h={[`--top${u}`]:"50%",[`--right${u}`]:getValuePositon(p("right"),r,$),[`--left${u}`]:"unset",[`--bottom${u}`]:"unset",[`--t${u}`]:"translateY(-50%)"};break;case"bottom-left":h={...getGapBottom(m),[`--left${u}`]:getValuePositon(p("left"),r,g),[`--right${u}`]:"unset",[`--top${u}`]:"unset",[`--t${u}`]:"unset"};break;case"bottom":h={...getGapBottom(m),[`--left${u}`]:getValuePositon(p("center"),r,"50%"),[`--top${u}`]:"unset",[`--right${u}`]:"unset",[`--t${u}`]:"translateX(-50%)"};break;case"bottom-right":h={...getGapBottom(m),[`--right${u}`]:getValuePositon(p("right"),r,$),[`--left${u}`]:"unset",[`--top${u}`]:"unset",[`--t${u}`]:"unset"}}return{...t,...h}},{})};export{getGapBottom,getGapCompareProductImage,getShapePosition};
