import{template as e,RenderIf as t,isLocalEnv as s,baseAssetURL as o}from"@gem-sdk/core";import r from"../../text/components/Text.liquid.js";import{getInsertLinkData as i,getSettingPreloadData as a}from"../../helpers.js";import{createStateOrContext as d,createStyle as n,createClass as l,createAttr as u,If as m}from"@gem-sdk/system";import{getAttr as c,getAttrHref as p}from"../common/attrs.js";import{getDateStyle as $,getTextFrontStyle as y,getTextBackStyle as g,getWrapperStyle as f,getContainStyle as h}from"../common/styles.js";import{getTextFrontClasses as w,getWrapperClasses as x,getContentClasses as b,getLinkClasses as v,getDateClasses as j,getTextBackClasses as k}from"../common/classes.js";import{getStandardEndtime as S}from"../common/helpers.js";let Countdown=E=>{let{setting:C,styles:L,builderProps:T,advanced:A,pageContext:N}=E,{labelTypo:_,numTypo:D,numTypography:H,labelTypography:I,enableLabelTextStyle:P}=L??{},{weekLabel:W,dayLabel:q,hourLabel:F,minuteLabel:G,secondLabel:O,enableWeek:J,enableDay:M,enableHour:R,enableMinute:V,enableSecond:Z,redirectUrl:z,translate:B}=C??{},K=!!z?.link,{urlData:Q}=i("",z),U=d({...C,...T}),X=n({...$(L)}),Y=e=>l({...j(e)}),ee=l({...w(L)}),et=n({...y(L)}),es=n({...g(L)}),eo=e=>l({...k(L,e)}),er=u({...c({uid:T?.uid||""})}),ei=u({...p({uid:Q.href||""})}),ea=n({...f(L)}),ed=l({...x(A?.cssClass)}),en=l({...b()}),el=n({...h(L)}),eu=(t,s,o)=>e`
    <div style="${X}" class="${Y(s)}">
    ${r({styles:{typography:H,typo:D},setting:{...C,text:"00",excludeFlex:!0,translate:""},style:et,className:ee,builderAttrs:{id:t},builderProps:{...T,uid:T?.uid,uidInteraction:`${T?.uid}-text`}})}
    ${m(!!P,e`
         ${r({styles:{typography:I,typo:_},setting:{...C,text:s,excludeFlex:!0,translate:o},style:es,className:eo(s),builderProps:{...T,uid:T?.uid,uidInteraction:`${T?.uid}-text`},pageContext:N})}
    `)}
    </div>
    `,em=l({...v()}),ec=S(C?.dateStandard,C?.timeZone),ep=()=>t(s,`<script ${a('class="gps-link" delay',"src")}="{{ 'gp-countdown-v7-5.js' | asset_url }}" defer="defer"></script>`,`<script ${a('class="gps-link" delay',"src")}="${o}/assets-v2/gp-countdown-v7-5.js?v={{ shop.metafields.GEMPAGES.ASSETS_VERSION }}" defer="defer"></script>`);return e`
    {%- liquid
      assign standardEndDate = ${ec}
      assign typeCountdown = "${C?.behaviour.toString()||""}"
      assign autoHideWhenTimeout = ${!!C?.autoHideWhenTimeout}
      assign current_time = 'now' | date: '%s' | times: 1000

    -%}
   {% if standardEndDate == nil or current_time <= standardEndDate or typeCountdown != "standard" or autoHideWhenTimeout != true %}
      <gp-countdown-timer
        ${{...er}}
        ${{...ei}}
        class="${ed}"
        style="${ea}"
        gp-data='${JSON.stringify(U).replaceAll("'","&#039;")}'>
        <div id="section-countdown" class="${en}" style="${el}">
          ${m(K,`<a
              href="${Q.href}"
              target="${Q?.target}"
              aria-label="Countdown link"
              class="${em}"
            > </a>`)}
          ${m(J,eu("week",W,B?"weekLabel":""))}
          ${m(M,eu("day",q,B?"dayLabel":""))}
          ${m(R,eu("hour",F,B?"hourLabel":""))}
          ${m(V,eu("minute",G,B?"minuteLabel":""))}
          ${m(Z,eu("second",O,B?"secondLabel":""))}
        </div>
     </gp-countdown-timer>
    {% endif %}
    ${ep()}
  `};export{Countdown as default};
