/*! phoscon-app 2025-10-13 */

export const 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 const toTimeString=(h,m,s)=>{let res="";return res+=h<10?"0"+h:h,res+=":",res+=m<10?"0"+m:m,void 0!==s&&(res+=":",res+=s<10?"0"+s:s),res};export const localTimeToString=localtime=>{let time,h,m,s,date=new Date;return h=(time=localtime.split("T")[1]).split(":")[0],m=time.split(":")[1],s=time.split(":")[2],h&&m&&s?(date.setHours(h),date.setMinutes(m),date.setSeconds(s),-1!==localtime.indexOf("PT")?time:date.toLocaleTimeString()):""};export const weekBitmapToDecimal=weekBitmap=>{var weekBitmapUTC=convertUtcWeekBitmap(weekBitmap);return parseInt(weekBitmapUTC,2)};export const getScheduleFadingTime=schedule=>{var fadingtime=0;if("LightGroup"===(-1!=schedule.command.address.indexOf("scenes")?"scenes":"LightGroup"))fadingtime=void 0!==schedule.command.body.transitiontime?parseInt(schedule.command.body.transitiontime)/10:0;else{let sceneId=schedule.command.address.split("/")[6],group=app.groups.get(app.session.gid);group&&group.get("scenes").forEach(function(scene){scene.id!==sceneId||(fadingtime=parseInt(scene.transitiontime)/10)})}return fadingtime};export const 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 const 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 const 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};