2022-03-24 03:11:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								import  { FlowStep }  from  "./FlowStep" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  Combine  from  "../Base/Combine" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  { UIEventSource }  from  "../../Logic/UIEventSource" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  LayerConfig  from  "../../Models/ThemeConfig/LayerConfig" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  { InputElement }  from  "../Input/InputElement" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  { AllKnownLayouts }  from  "../../Customizations/AllKnownLayouts" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  { FixedInputElement }  from  "../Input/FixedInputElement" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  Img  from  "../Base/Img" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  Title  from  "../Base/Title" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  { RadioButton }  from  "../Input/RadioButton" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  { And }  from  "../../Logic/Tags/And" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  { VariableUiElement }  from  "../Base/VariableUIElement" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  { FixedUiElement }  from  "../Base/FixedUiElement" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  Toggleable  from  "../Base/Toggleable" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  { BBox }  from  "../../Logic/BBox" ;  
						 
					
						
							
								
									
										
										
										
											2022-04-04 04:54:54 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  BaseUIElement  from  "../BaseUIElement" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  PresetConfig  from  "../../Models/ThemeConfig/PresetConfig" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  List  from  "../Base/List" ;  
						 
					
						
							
								
									
										
										
										
											2022-03-24 03:11:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export  default  class  SelectTheme  extends  Combine  implements  FlowStep < {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    features : any [ ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    theme : string , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    layer : LayerConfig , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    bbox : BBox , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} >  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    public  readonly  Value : UIEventSource < { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        features : any [ ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        theme : string , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        layer : LayerConfig , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        bbox : BBox , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } > ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    public  readonly  IsValid : UIEventSource < boolean > ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-04 04:54:54 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    constructor ( params :  ( {  features : any [ ] ,  layer : LayerConfig ,  bbox : BBox ,  } ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 03:11:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        let  options : InputElement < string > [ ]  =  AllKnownLayouts . layoutsList 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            . filter ( th  = >  th . layers . some ( l  = >  l . id  ===  params . layer . id ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            . filter ( th  = >  th . id  !==  "personal" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            . map ( th  = >  new  FixedInputElement < string > ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                new  Combine ( [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    new  Img ( th . icon ) . SetClass ( "block h-12 w-12 br-4" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-04 04:54:54 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    new  Title ( th . title ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 03:11:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                ] ) . SetClass ( "flex items-center" ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                th . id ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  themeRadios  =  new  RadioButton < string > ( options ,  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            selectFirstAsDefault : false 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  applicablePresets  =  themeRadios . GetValue ( ) . map ( theme  = >  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-04 04:54:54 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( theme  ===  undefined )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 03:11:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                return  [ ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // we get the layer with the correct ID via the actual theme config, as the actual theme might have different presets due to overrides
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            const  themeConfig  =  AllKnownLayouts . layoutsList . find ( th  = >  th . id  ===  theme ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            const  layer  =  themeConfig . layers . find ( l  = >  l . id  ===  params . layer . id ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  layer . presets 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  nonMatchedElements  =  applicablePresets . map ( presets  = >  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-04 04:54:54 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( presets  ===  undefined  ||  presets . length  ===  0 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 03:11:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                return  undefined 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  params . features . filter ( feat  = >  ! presets . some ( preset  = >  new  And ( preset . tags ) . matchesProperties ( feat . properties ) ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        super ( [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            new  Title ( "Select a theme" ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            "All of the following themes will show the import notes. However, the note on OpenStreetMap can link to only one single theme. Choose which theme that the created notes will link to" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            themeRadios , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            new  VariableUiElement ( applicablePresets . map ( applicablePresets  = >  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-04 04:54:54 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                if  ( themeRadios . GetValue ( ) . data  ===  undefined )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 03:11:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                    return  undefined 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-04 04:54:54 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                if  ( applicablePresets  ===  undefined  ||  applicablePresets . length  ===  0 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 03:11:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                    return  new  FixedUiElement ( "This theme has no presets loaded. As a result, imports won't work here" ) . SetClass ( "alert" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-04 04:54:54 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            } ,  [ themeRadios . GetValue ( ) ] ) ) , 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 03:11:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-04 04:54:54 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            new  VariableUiElement ( nonMatchedElements . map ( unmatched  = >  SelectTheme . nonMatchedElementsPanel ( unmatched ,  applicablePresets . data ) ,  [ applicablePresets ] ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 03:11:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . SetClass ( "flex flex-col" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . Value  =  themeRadios . GetValue ( ) . map ( theme  = >  ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            features : params.features , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            layer : params.layer , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            bbox : params.bbox , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            theme 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . IsValid  =  this . Value . map ( obj  = >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( obj  ===  undefined )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-04 04:54:54 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( [ obj . theme ,  obj . features ] . some ( v  = >  v  ===  undefined ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 03:11:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-04 04:54:54 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( applicablePresets . data  ===  undefined  ||  applicablePresets . data . length  ===  0 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 03:11:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                return  false 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-04 04:54:54 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( ( nonMatchedElements . data ? . length  ? ?  0 )  >  0 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 03:11:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } ,  [ applicablePresets ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-04 04:54:54 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    private  static  nonMatchedElementsPanel ( unmatched : any [ ] ,  applicablePresets : PresetConfig [ ] ) :  BaseUIElement  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( unmatched  ===  undefined  ||  unmatched . length  ===  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  applicablePresetsOverview  =  applicablePresets . map ( preset  = >  new  Combine ( [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            preset . title . txt ,  "needs tags" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            new  FixedUiElement ( preset . tags . map ( t  = >  t . asHumanString ( ) ) . join ( " & " ) ) . SetClass ( "thanks" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ] ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  unmatchedPanels : BaseUIElement [ ]  =  [ ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        for  ( const  feat  of  unmatched )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            const  parts : BaseUIElement [ ]  =  [ ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            parts . push ( new  Combine ( Object . keys ( feat . properties ) . map ( k  = >  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                k + "=" + feat . properties [ k ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ) ) . SetClass ( "flex flex-col" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            for  ( const  preset  of  applicablePresets )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                const  tags  =  new  And ( preset . tags ) . asChange ( { } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                const  missing  =  [ ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                for  ( const  { k ,  v }  of  tags )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    if  ( preset [ k ]  ===  undefined )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        missing . push ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            ` Expected  ${ k } = ${ v } , but it is completely missing ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    }  else  if  ( feat . properties [ k ]  !==  v )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        missing . push ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            ` Property with key  ${ k }  does not have expected value  ${ v } ; instead it is  ${ feat . properties } ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  ( missing . length  >  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    parts . push ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        new  Combine ( [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            new  FixedUiElement ( ` Preset  ${ preset . title . txt }  is not applicable: ` ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            new  List ( missing ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        ] ) . SetClass ( "flex flex-col alert" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            unmatchedPanels . push ( new  Combine ( parts ) . SetClass ( "flex flex-col" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  new  Combine ( [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            new  FixedUiElement ( unmatched . length  +  " objects dont match any presets" ) . SetClass ( "alert" ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            . . . applicablePresetsOverview , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            new  Toggleable ( new  Title ( "The following elements don't match any of the presets" ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                new  Combine ( unmatchedPanels ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ] ) . SetClass ( "flex flex-col" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 03:11:29 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}