/*! phoscon-app 2024-10-07 */

export function getScheduleDays(time,utc){var bin="00000000";if(-1!==time.indexOf("W")){for(var leadingZeros=8-(bin=parseInt(time.substring(time.indexOf("W")+1,time.indexOf("/"))).toString(2)).length,i=0;i<leadingZeros;i++)bin="0"+bin;utc&&(bin=convertWeekBitmapFromUtc(bin,time))}return bin};export function weekBitmapToText(weekbitmap){return new Promise((resolve,reject)=>{const waitForIt=weekbitmap=>{if(void 0===translate("btn_week_mo"))return void setTimeout(()=>{waitForIt(weekbitmap)});let text="";"1"===weekbitmap[1]&&(text+=translate("btn_week_mo")+" "),"1"===weekbitmap[2]&&(text+=translate("btn_week_tu")+" "),"1"===weekbitmap[3]&&(text+=translate("btn_week_we")+" "),"1"===weekbitmap[4]&&(text+=translate("btn_week_th")+" "),"1"===weekbitmap[5]&&(text+=translate("btn_week_fr")+" "),"1"===weekbitmap[6]&&(text+=translate("btn_week_sa")+" "),"1"===weekbitmap[7]&&(text+=translate("btn_week_su")+" "),resolve(text)};waitForIt(weekbitmap)})};export function toTimeString(h,m){let res="";return res+=h<10?"0"+h:h,res+=":",res+=m<10?"0"+m:m};export function weekBitmapToDecimal(weekBitmap){var weekBitmapUTC=convertUtcWeekBitmap(weekBitmap);return parseInt(weekBitmapUTC,2)};export function getScheduleFadingTime(schedule){var fadingtime=0;if("group"===(-1!=schedule.command.address.indexOf("scenes")?"scenes":"group"))fadingtime=void 0!==schedule.command.body.transitiontime?parseInt(schedule.command.body.transitiontime)/10:0;else{let sceneId=schedule.command.address.split("/")[6];app.groups.get(app.session.gid).attributes.scenes.forEach(function(scene){scene.id!==sceneId||(fadingtime=parseInt(scene.transitiontime)/10)})}return fadingtime};export function convertWeekBitmapFromUtc(weekBitmap,time){var result="0",hour=time.substr(time.indexOf("T")+1,2),min=time.substr(time.indexOf("T")+4,2),t=60*parseInt(hour)+parseInt(min);if(t-app.time.offset<=0){for(var c=2;c<8;c++)"0"==weekBitmap[c]?result+="0":result+="1";return result+=weekBitmap[1]}if(t-app.time.offset>1440){result+=weekBitmap[7];for(c=1;c<7;c++)"0"==weekBitmap[c]?result+="0":result+="1";return result}return weekBitmap};export function convertUtcWeekBitmap(weekBitmap){var t,result="0";if((t=60*(0===parseInt(app.curSchedule.hour)&&0===parseInt(app.curSchedule.minute)?24:parseInt(app.curSchedule.hour))+parseInt(app.curSchedule.minute))+app.time.offset<0){for(var c=2;c<8;c++)"0"==weekBitmap[c]?result+="0":result+="1";return result+=weekBitmap[1]}if(t+app.time.offset>1439){result+=weekBitmap[7];for(c=1;c<7;c++)"0"==weekBitmap[c]?result+="0":result+="1";return result}return weekBitmap};export function checkTimeInPast(){var result=!1,hour=parseInt(app.clock.hour),min=parseInt(app.clock.min);if("00000000"!==app.curSchedule.days||"timer"===app.curSchedule.type)return!1;var s_time=60*parseInt(app.curSchedule.hour)*60+60*parseInt(app.curSchedule.minute),c_time=60*hour*60+60*min;return"end"===app.curSchedule.activation&&(s_time-=parseInt(app.curSchedule.fadingtime)),s_time<=c_time&&(result=!0),result};