jQuery(document).ready(function(e){function i(){let i={};e(".dina-weekly-time-ranges .dina-day-block").each(function(){let t=e(this).data("day");i[t]=[],e(this).find(".dina-time-range-row").each(function(){let n=e(this).find(".dina-from-time").val(),a=e(this).find(".dina-to-time").val();n&&a&&i[t].push({from:n,to:a})})}),e(".dina-redux-weekly-time-json").val(JSON.stringify(i)).trigger("change")}e(".dina-weekly-time-ranges").on("click",".dina-add-time-range",function(){let t=e(this).closest(".dina-day-block"),n=e(`
            <div class="dina-time-range-row">
                <input type="time" class="dina-from-time" />
                <span>${dinaWeeklyTimeRangesData.i18n.to}</span>
                <input type="time" class="dina-to-time" />
                <button type="button" class="dina-remove-time button-link">⨉</button>
            </div>
        `);t.find(".dina-time-entries").append(n),i()}),e(".dina-weekly-time-ranges").on("click",".dina-remove-time",function(){e(this).closest(".dina-time-range-row").remove(),i()}),e(".dina-weekly-time-ranges").on("change","input[type='time']",i);let t=e(".dina-redux-weekly-time-json").val();if(t)try{let n=JSON.parse(t);e(".dina-weekly-time-ranges .dina-day-block").each(function(){let i=e(this).data("day"),t=n[i]||[];!function i(t,n){let a=t.find(".dina-time-entries");a.empty(),n.forEach((i,t)=>{let n=e(`
                <div class="dina-time-range-row">
                    <input type="time" class="dina-from-time" value="${i.from}" />
                    <span>${dinaWeeklyTimeRangesData.i18n.to}</span>
                    <input type="time" class="dina-to-time" value="${i.to}" />
                    <button type="button" class="dina-remove-time button-link">⨉</button>
                </div>
            `);a.append(n)})}(e(this),t)})}catch(a){console.error("Invalid initial JSON",a)}e(".dina-weekly-time-ranges").on("click",".dina-day-header",function(){let i=e(this).closest(".dina-day-block");i.toggleClass("open")})});