11import { LitElement , html , css } from "https://unpkg.com/lit-element@2.4.0/lit-element.js?module" ;
2- // NIDA CARD v41 — intro in 10 talen, standaardtaal Engels
2+ // NIDA CARD v42 — fix: nextAction toont altijd eerstvolgende actie (ook na Isha)
33
44// Hijri maandnamen per taal
55const HIJRI_MONTHS = {
@@ -299,29 +299,47 @@ class NidaCard extends LitElement {
299299 const nowMin = new Date ( ) . getHours ( ) * 60 + new Date ( ) . getMinutes ( ) ;
300300 const isRam = this . _isRamadan ( ) ;
301301 const acts = [ ] ;
302+
303+ const _fmt = ( min ) => {
304+ const m = ( ( min % 1440 ) + 1440 ) % 1440 ;
305+ return `${ String ( Math . floor ( m / 60 ) ) . padStart ( 2 , '0' ) } :${ String ( m % 60 ) . padStart ( 2 , '0' ) } ` ;
306+ } ;
307+
302308 const pmap = [ { k :'fajr' , e :'sensor.02_fajr_readable' } , { k :'dhuhr' , e :'sensor.04_dhuhr_readable' } , { k :'asr' , e :'sensor.05_asr_readable' } , { k :'maghrib' , e :'sensor.07_maghrib_readable' } , { k :'isha' , e :'sensor.08_isha_readable' } ] ;
303309 for ( const p of pmap ) {
304310 const t = this . _s ( p . e ) ; if ( ! t || t === 'unavailable' ) continue ;
305- const [ h , m ] = t . split ( ':' ) . map ( Number ) ; const pm = h * 60 + m ;
306- for ( const off of [ 10 , 5 ] ) { const r = pm - off ; if ( r > nowMin ) acts . push ( { type :'tadkir' , prayerKey :p . k , min :r , time :`${ String ( Math . floor ( r / 60 ) ) . padStart ( 2 , '0' ) } :${ String ( r % 60 ) . padStart ( 2 , '0' ) } ` } ) ; }
307- if ( pm > nowMin ) acts . push ( { type :'adhan' , prayerKey :p . k , min :pm , time :t } ) ;
311+ const [ h , m ] = t . split ( ':' ) . map ( Number ) ;
312+ // Als gebed al voorbij is vandaag → voeg toe als morgen (+1440)
313+ let pm = h * 60 + m ;
314+ if ( pm <= nowMin ) pm += 1440 ;
315+ // Pre-adhan reminders (10 en 5 min voor)
316+ for ( const off of [ 10 , 5 ] ) {
317+ const r = pm - off ;
318+ if ( r > nowMin ) acts . push ( { type :'tadkir' , prayerKey :p . k , min :r , time :_fmt ( r ) } ) ;
319+ }
320+ acts . push ( { type :'adhan' , prayerKey :p . k , min :pm , time :_fmt ( pm ) } ) ;
321+ }
322+
323+ // Suhoor: altijd tonen als sensor beschikbaar is (ook buiten Ramadan)
324+ const imsak = this . _s ( 'sensor.01_imsak_readable' ) ;
325+ if ( imsak && imsak !== 'unavailable' ) {
326+ const [ ih , im ] = imsak . split ( ':' ) . map ( Number ) ;
327+ let sm = ih * 60 + im ;
328+ if ( sm <= nowMin ) sm += 1440 ;
329+ acts . push ( { type :'suhoor' , prayerKey :null , min :sm , time :_fmt ( sm ) } ) ;
308330 }
331+
332+ // Tarhim: alleen tijdens Ramadan
309333 if ( isRam ) {
310334 const f = this . _s ( 'sensor.02_fajr_readable' ) ;
311- if ( f ) {
312- const [ h , m ] = f . split ( ':' ) . map ( Number ) ;
313- let tm = h * 60 + m - 30 ;
335+ if ( f && f !== 'unavailable' ) {
336+ const [ fh , fm ] = f . split ( ':' ) . map ( Number ) ;
337+ let tm = fh * 60 + fm - 30 ;
314338 if ( tm <= nowMin ) tm += 1440 ;
315- acts . push ( { type :'tarhim' , prayerKey :null , min :tm , time :`${ String ( Math . floor ( ( tm % 1440 ) / 60 ) ) . padStart ( 2 , '0' ) } :${ String ( tm % 60 ) . padStart ( 2 , '0' ) } ` } ) ;
316- const im = this . _s ( 'sensor.01_imsak_readable' ) ;
317- if ( im ) {
318- const [ ih , im2 ] = im . split ( ':' ) . map ( Number ) ;
319- let sm = ih * 60 + im2 ;
320- if ( sm <= nowMin ) sm += 1440 ;
321- acts . push ( { type :'suhoor' , prayerKey :null , min :sm , time :`${ String ( Math . floor ( ( sm % 1440 ) / 60 ) ) . padStart ( 2 , '0' ) } :${ String ( sm % 60 ) . padStart ( 2 , '0' ) } ` } ) ;
322- }
339+ acts . push ( { type :'tarhim' , prayerKey :null , min :tm , time :_fmt ( tm ) } ) ;
323340 }
324341 }
342+
325343 if ( ! acts . length ) return null ;
326344 acts . sort ( ( a , b ) => a . min - b . min ) ;
327345 return acts [ 0 ] ;
@@ -1080,6 +1098,4 @@ class NidaCard extends LitElement {
10801098}
10811099
10821100customElements . define ( 'nida-card' , NidaCard ) ;
1083- console . log ( '%c NIDA CARD v41 geladen ✓ ' , 'background:#c9a84c;color:#000;font-weight:bold;' ) ;
1084-
1085-
1101+ console . log ( '%c NIDA CARD v42 geladen ✓ ' , 'background:#c9a84c;color:#000;font-weight:bold;' ) ;
0 commit comments