1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
extern crate proc_macro;
use self::proc_macro::TokenStream;
use heck::KebabCase;
use heck::SnakeCase;
use quote::{format_ident, quote};
use syn::parse::{Parse, ParseStream, Result};
use syn::{parse_macro_input, DeriveInput, Expr, ExprArray};
use syn::{Lit, Meta, MetaNameValue};

// Derive Proc Macro to generate extension traits for Style
// add helpers for variants of properties that have no arguments
// excluding `Initial` and `Initial`.
//
// For instance if the enum is
// #[short_prop = "p"]
// CssPadding {
//     Auto,
//     Length(ExactLength),
//     Initial,
//     Inherit,
//  }
/// then `padding_auto()` will be generated on Style.
//  if short_prop attribute is set, then that will be set too
//  i.e. `p_auto()`
#[proc_macro_derive(CssStyleMacro, attributes(short_prop))]
pub fn expand(input: TokenStream) -> TokenStream {
    let input = parse_macro_input!(input as DeriveInput);

    let mut short_prop: Option<String> = None;

    // Iterate over the struct's #[...] attributes
    for option in input.attrs.into_iter() {
        let option = option.parse_meta().unwrap();
        match option {
            // Match '#[ident = lit]' attributes. Match guard makes it '#[short_prop = lit]'
            Meta::NameValue(MetaNameValue {
                ref path, ref lit, ..
            }) if path.is_ident("short_prop") => {
                if let Lit::Str(lit) = lit {
                    short_prop = Some(lit.value());
                }
            }
            _ => {}
        }
    }

    let short_prop = short_prop.clone();

    let css_type_name = input.ident.clone();
    let variant_ident = format_ident!(
        "{}",
        css_type_name
            .to_string()
            .trim_start_matches("Css")
            .to_string()
    );
    let trait_name_ident = format_ident!("{}Trait", input.ident);
    let snake_case_type = variant_ident.to_string().to_snake_case();
    let snake_case_type_ident = format_ident!("{}", snake_case_type);

    let (base_defn_quote, base_impl_quote) = if let Some(short_prop) = short_prop.clone() {
        let short_prop_ident = format_ident!("{}", short_prop);
        (
            quote!(
                #[track_caller]
                fn #snake_case_type_ident<T>(self, val:T) -> Style  where T: UpdateStyle<#css_type_name> ;

                 #[track_caller]
                 fn #short_prop_ident<T>(self, val:T) -> Style  where T: UpdateStyle<#css_type_name>;
            ),
            quote!(

            #[track_caller]
            fn #snake_case_type_ident<T>(mut self, val:T) -> Style  where T: UpdateStyle<#css_type_name> {

                self.updated_at.push(format!("{}", Location::caller()));
                val.update_style(&mut self);
                self

             }

             #[track_caller]
             fn #short_prop_ident<T>(mut self, val:T) -> Style  where T: UpdateStyle<#css_type_name> {

                self.updated_at.push(format!("{}", Location::caller()));
                val.update_style(&mut self);
                 self
              }
            ),
        )
    } else {
        (
            quote!(

            #[track_caller]
            fn #snake_case_type_ident<T>(self, val:T) -> Style  where T: UpdateStyle<#css_type_name>;

            ),
            quote!(

            #[track_caller]
            fn #snake_case_type_ident<T>(mut self, val:T) -> Style  where T: UpdateStyle<#css_type_name> {

                self.updated_at.push(format!("{}", Location::caller()));
                val.update_style(&mut self);
                self
             }

            ),
        )
    };

    // let inner_quote = quote! {
    //     fn update_style(self, style: &Style)-> Style {
    //         with_themes( |borrowed_themes| {
    //             let new_style = style.clone();
    //             for (i, style_val) in &mut self.iter().cloned().map(|v| v.into()).enumerate() {
    //                 if let Some(breakpoint) = borrowed_themes.iter().find_map( |theme| theme.media_bp_scale.get(i) ){
    //                     new_style.updated_at.push(format!("{}", Location::caller()));
    //                     let rules = new_style.media_rules.entry(breakpoint.0.clone()).or_insert(vec![]);
    //                     rules.push(Rule{value:Box::new(style_val.clone())})
    //                 }
    //             }
    //             new_style
    //         })
    //     }
    // };

    let update_style_quote = quote! {
        impl CssValueTrait for #css_type_name{}

    // impl UpdateStyle<#css_type_name> for #css_type_name {
    //     fn update_style(self, style: &mut Style)-> Style{
    //         let val : #css_type_name = self.into();



    //         let new_style =  style.clone();
    //         new_style.updated_at.push(format!("{}", Location::caller()));
    //         new_style.add_rule(Box::new(val));
    //         new_style
    //     }
    // }

    // impl UpdateStyle<#css_type_name> for &str {
    //     fn update_style(self, style: &mut Style)-> Style{
    //         let new_style =  style.clone();
    //         let val : #css_type_name = self.into();
    //         new_style.updated_at.push(format!("{}", Location::caller()));
    //         new_style.add_rule(Box::new(val));
    //         new_style
    //     }
    // }



    impl From<&str> for #css_type_name where {
        fn from(v: &str) -> Self {
            #css_type_name::StringValue(v.to_string())
        }
    }

    // impl <R>UpdateStyle<#css_type_name> for &Vec<R> where R:Into<#css_type_name> + Clone{#inner_quote }
    // impl <R>UpdateStyle<#css_type_name> for &[R] where R:Into<#css_type_name> + Clone{#inner_quote }
    // impl <R>UpdateStyle<#css_type_name> for &[R;1] where R:Into<#css_type_name> + Clone{
    //     fn update_style(self, style: &Style)-> Style {
    //         self.as_ref().update_style(style)
    //     }
    // }

    // impl <R>UpdateStyle<#css_type_name> for &[R;2] where R:Into<#css_type_name> + Clone{
    //     fn update_style(self, style: &Style)-> Style {
    //         self.as_ref().update_style(style)
    //     }
    // }
    // impl <R>UpdateStyle<#css_type_name> for &[R;3] where R:Into<#css_type_name> + Clone{
    //     fn update_style(self, style: &Style)-> Style {
    //         self.as_ref().update_style(style)
    //     }
    // }
    // impl <R>UpdateStyle<#css_type_name> for &[R;4] where R:Into<#css_type_name> + Clone{
    //     fn update_style(self, style: &Style)-> Style {
    //         self.as_ref().update_style(style)
    //     }
    // }

    // impl <R>UpdateStyle<#css_type_name> for &[R;5] where R:Into<#css_type_name> + Clone{
    //     fn update_style(self, style: &Style)-> Style {
    //         self.as_ref().update_style(style)
    //     }
    // }

    // impl <R>UpdateStyle<#css_type_name> for &[R;6] where R:Into<#css_type_name> + Clone{
    //     fn update_style(self, style: &Style)-> Style {
    //         self.as_ref().update_style(style)
    //     }
    // }

    // impl <R>UpdateStyle<#css_type_name> for &[R;7] where R:Into<#css_type_name> + Clone{
    //     fn update_style(self, style: &Style)-> Style {
    //         self.as_ref().update_style(style)
    //     }
    // }
    // impl <R>UpdateStyle<#css_type_name> for &[R;8] where R:Into<#css_type_name> + Clone{
    //     fn update_style(self, style: &Style)-> Style {
    //         self.as_ref().update_style(style)
    //     }
    // }

    // impl <R>UpdateStyle<#css_type_name> for &[R;9] where R:Into<#css_type_name> + Clone{
    //     fn update_style(self, style: &Style)-> Style {
    //         self.as_ref().update_style(style)
    //     }
    // }

    // impl <R>UpdateStyle<#css_type_name> for &[R;10] where R:Into<#css_type_name> + Clone{
    //     fn update_style(self, style: &Style)-> Style {
    //         self.as_ref().update_style(style)
    //     }
    // }
    };

    let mut create_extension_trait = false;

    if let syn::Data::Enum(data_enum) = input.data {
        let count = data_enum
            .variants
            .iter()
            .filter(|v| v.fields == syn::Fields::Unit)
            .filter(|v| v.ident.clone().to_string() != "Inherit".to_string())
            .filter(|v| v.ident.clone().to_string() != "Initial".to_string())
            .count();
        if count > 0 {
            create_extension_trait = true;
        }

        let func_impls_defn = data_enum
            .variants
            .iter()
            .filter(|v| v.fields == syn::Fields::Unit)
            .filter(|v| v.ident.clone().to_string() != "Inherit".to_string())
            .filter(|v| v.ident.clone().to_string() != "Initial".to_string())
            .map(|v| {
                let snake_case_variant = v.ident.clone().to_string().to_snake_case();
                let value_variant_name = format_ident!(
                    "{}",
                    css_type_name
                        .clone()
                        .to_string()
                        .trim_start_matches("Css")
                        .to_string()
                );
                let snake_case_type = value_variant_name.clone().to_string().to_snake_case();

                let f_small_name = format_ident!("{}_{}", snake_case_type, snake_case_variant);
                let f_small_name_ident = format_ident!("{}", f_small_name);

                if let Some(short_prop) = short_prop.clone() {
                    let short_prop_ident = format_ident!("{}_{}", short_prop, snake_case_variant);
                    quote! {
                        fn #f_small_name_ident(self) -> Style;
                        fn #short_prop_ident(self) -> Style;

                    }
                } else {
                    quote! {
                        fn #f_small_name_ident(self) -> Style;
                    }
                }
            });

        let trait_definition = quote! {
            pub trait #trait_name_ident {
                #(
                #func_impls_defn
                )*

                #base_defn_quote



            }
        };

        let func_impls = data_enum
            .variants
            .iter()
            .filter(|v| v.fields == syn::Fields::Unit)
            .filter(|v| v.ident.clone().to_string() != "Inherit".to_string())
            .filter(|v| v.ident.clone().to_string() != "Initial".to_string())
            .map(|v| {
                let f_big_name = v.ident.clone();
                let snake_case_variant = v.ident.clone().to_string().to_snake_case();
                // let snake_case_type = value_variant_name.clone().to_string().to_snake_case();

                let f_small_name = format_ident!("{}_{}", snake_case_type, snake_case_variant);
                let f_small_name_ident = format_ident!("{}", f_small_name);
                if let Some(short_prop) = short_prop.clone() {
                    let short_prop_ident = format_ident!("{}_{}", short_prop, snake_case_variant);
                    quote! {
                        #[track_caller]
                        fn #short_prop_ident(mut self) -> Style {


                            self.updated_at.push(format!("{}", Location::caller()));
                            self.add_rule(Box::new(#css_type_name :: #f_big_name));
                            self
                        }
                        #[track_caller]
                            fn #f_small_name_ident(mut self) -> Style {


                            self.updated_at.push(format!("{}", Location::caller()));
                            self.add_rule(Box::new(#css_type_name :: #f_big_name));
                            self
                        }
                    }
                } else {
                    quote! {
                        #[track_caller]
                        fn #f_small_name_ident(mut self) -> Style {

                            self.updated_at.push(format!("{}", Location::caller()));
                            self.add_rule(Box::new(#css_type_name :: #f_big_name));
                            self
                        }

                    }
                }
            });

        let trait_impl = quote! {

            impl #trait_name_ident for Style {
                #(#func_impls)*
                #base_impl_quote

            }
        };

        if create_extension_trait {
            let exp = quote! {
                #update_style_quote
                #trait_definition
                #trait_impl
            };

            exp.into()
        } else {
            let exp = quote! {
                    pub trait #trait_name_ident {
                      #base_defn_quote
                    }


                impl #trait_name_ident for Style {
                    #base_impl_quote
                }
                    #update_style_quote
            };
            exp.into()
        }
    } else {
        let exp = quote! {
            pub trait #trait_name_ident {
                #base_defn_quote
            }


        impl #trait_name_ident for Style {
            #base_impl_quote
        }
        #update_style_quote
        };

        exp.into()
    }
}

// // Prop Macro to generate all short property methods on Style.
// // Will eventually be moved to the derive macro above.
// struct GenerateShortFNames {
//     properties: ExprArray,
// }

// impl Parse for GenerateShortFNames {
//     fn parse(input: ParseStream) -> Result<Self> {
//         let properties: ExprArray = input.parse()?;

//         Ok(GenerateShortFNames { properties })
//     }
// }

// #[proc_macro]
// pub fn generate_short_f_names(input: TokenStream) -> TokenStream {
//     let GenerateShortFNames { properties } = parse_macro_input!(input as GenerateShortFNames);

//     let mut exp = quote! {};
//     for property in properties.elems.iter() {
//         if let Expr::Tuple(ref tuple) = property {
//             let mut iter = tuple.elems.iter();
//             let theme_id = iter.next().unwrap().clone();
//             let generic_type_name = iter.next().unwrap().clone();

//             if let (Expr::Lit(ref theme_id), Expr::Lit(ref generic_type_name)) =
//                 (theme_id, generic_type_name)
//             {
//                 if let (syn::Lit::Str(ref short_name), syn::Lit::Str(ref long_name)) =
//                     (theme_id.lit.clone(), generic_type_name.lit.clone())
//                 {
//                     let short_name_ident = format_ident!("{}", short_name.value());
//                     let long_name_ident = format_ident!("Css{}", long_name.value());

//                     let variant_name = format_ident!("{}", long_name.value());

//                     let expanded = quote! {

//                        #[track_caller]
//                        pub fn #short_name_ident<T>(&self, val:T) -> Style  where T: UpdateStyle<#long_name_ident> {
//                            val.update_style(self)
//                        }

//                     };

//                     // println!("{}",expanded);
//                     exp = quote! {
//                         #exp
//                         #expanded
//                     };

//                     // println!("{}",TokenStream::from(exp));
//                 }
//             }
//         }
//     }

//     // let elem_ident = Ident::from(elem);

//     // let exp = quote!{};

//     exp.into()
// }

// impl From<&str> for #type_name where {
//         fn from(v: &str) -> Self {
//             #type_name::StringValue(v.to_string())
//         }
//     }

// Proc macro to impl from<&str> for Css values
// allows StringValue variant to be created.
struct GenerateFromStr {
    properties: ExprArray,
}

impl Parse for GenerateFromStr {
    fn parse(input: ParseStream) -> Result<Self> {
        let properties: ExprArray = input.parse()?;

        Ok(GenerateFromStr { properties })
    }
}

#[proc_macro]
pub fn generate_from_strs(input: TokenStream) -> TokenStream {
    let GenerateFromStr { properties } = parse_macro_input!(input as GenerateFromStr);

    let mut exp = quote! {};
    for property in properties.elems.iter() {
        if let Expr::Lit(ref property) = property {
            if let syn::Lit::Str(ref property) = property.lit {
                let type_name = format_ident!("Css{}", property.value());

                let expanded = quote! {

                impl From<&str> for #type_name where {
                        fn from(v: &str) -> Self {
                            #type_name::StringValue(v.to_string())
                        }
                    }

                };
                // println!("{}",expanded);
                exp = quote! {
                    #exp
                    #expanded
                };
            }
        }
    }

    // let exp = quote!{};
    TokenStream::from(exp)
}

// #[track_caller]
// pub fn hover(&self) -> Style {
//     let new_style = self.clone();
//     new_style.updated_at.push(format!("{}", Location::caller()));
//     new_style.pseudo = Pseudo::Hover;
//     new_style
// }

// psuedo selectors:
//
// Proc macro to generate psuedo methods for Style
struct CreatePseudos {
    properties: ExprArray,
}

impl Parse for CreatePseudos {
    fn parse(input: ParseStream) -> Result<Self> {
        let properties: ExprArray = input.parse()?;

        Ok(CreatePseudos { properties })
    }
}

#[proc_macro]
pub fn create_pseudos(input: TokenStream) -> TokenStream {
    let CreatePseudos { properties } = parse_macro_input!(input as CreatePseudos);

    let mut exp = quote! {};
    for property in properties.elems.iter() {
        if let Expr::Lit(ref property) = property {
            if let syn::Lit::Str(ref property) = property.lit {
                let pseudoname = format_ident!("{}", property.value());

                let fname = format_ident!("{}", property.value().to_snake_case());

                let expanded = quote! {



                #[track_caller]
                pub fn #fname(mut self) -> Style {

                    self.updated_at.push(format!("{}", Location::caller()));
                    self.pseudo = Pseudo::#pseudoname;
                    self
                }

                };
                // println!("{}",expanded);
                exp = quote! {
                    #exp
                    #expanded
                };
            }
        }

        // let elem_ident = Ident::from(elem);
    }

    // let exp = quote!{};
    TokenStream::from(exp)
}

//
// impl <T> From<T> for CssWidth where T:SizeTheme + 'static{
//     fn from(v: T) -> Self {
//         let theme = get_theme();
//         let borrowed_theme = theme.borrow();
//         borrowed_theme.get::<T,CssSize>(v).unwrap().into()
//     }
// }

// impl <T>From<(T,CssWidth)> for CssWidth where T: SizeTheme + 'static {
//     fn from(v:(T,CssWidth)) -> Self {
//         let theme = get_theme();
//         let borrowed_theme = theme.borrow();
//         if let Some(theme_value) = borrowed_theme.get::<T,CssSpace>(v.0){
//             theme_value.clone().into()
//         } else {
//             v.1
//         }
//     }
// }
////
//
// Proc macro to generate Css Values from theme variants
//
// [ (ThemeId, GenericTypeName, SpecificTypeName )]
struct CreateFromTraits {
    properties: ExprArray,
}

impl Parse for CreateFromTraits {
    fn parse(input: ParseStream) -> Result<Self> {
        let properties: ExprArray = input.parse()?;

        Ok(CreateFromTraits { properties })
    }
}

#[proc_macro]
pub fn generate_froms(input: TokenStream) -> self::proc_macro::TokenStream {
    let CreateFromTraits { properties } = parse_macro_input!(input as CreateFromTraits);

    let mut exp = quote! {};
    for property in properties.elems.iter() {
        if let Expr::Tuple(ref tuple) = property {
            let mut iter = tuple.elems.iter();
            let theme_id = iter.next().unwrap().clone();
            let generic_type_name = iter.next().unwrap().clone();
            let specific_type_name = iter.next().unwrap().clone();
            let theme_scale = iter.next().unwrap().clone();

            if let (
                Expr::Lit(ref theme_id),
                Expr::Lit(ref generic_type_name),
                Expr::Lit(ref specific_type_name),
                Expr::Lit(ref theme_scale),
            ) = (theme_id, generic_type_name, specific_type_name, theme_scale)
            {
                if let (
                    syn::Lit::Str(ref theme_ids),
                    syn::Lit::Str(ref generic_type_names),
                    syn::Lit::Str(ref specific_type_names),
                    syn::Lit::Str(ref theme_scale),
                ) = (
                    theme_id.lit.clone(),
                    generic_type_name.lit.clone(),
                    specific_type_name.lit.clone(),
                    theme_scale.lit.clone(),
                ) {
                    let themeid_ident = format_ident!("{}", theme_ids.value());
                    let generic_ident = format_ident!("{}", generic_type_names.value());
                    let specific_ident = format_ident!("{}", specific_type_names.value());

                    let theme_scale_ident = format_ident!("{}", theme_scale.value());
                    let theme_scale_string = theme_scale.value();
                    let expanded = quote! {


                            impl <T> From<T> for #specific_ident where T:#themeid_ident + 'static{
                                fn from(v: T) -> Self {
                                    with_themes( |borrowed_themes| {
                                    borrowed_themes.iter().find_map( |theme| theme.get::<T,#generic_ident>(v.clone())).unwrap().into()
                                    })
                                }
                            }

                            impl <T>From<(T,#generic_ident)> for #specific_ident where T: #themeid_ident + 'static {
                                fn from(v:(T,#generic_ident)) -> Self {
                                    with_themes( |borrowed_themes| {

                                    if let Some(theme_value) = borrowed_themes.iter().find_map( |theme| theme.get::<T,#generic_ident>(v.0.clone())){
                                        theme_value.clone().into()
                                    } else {
                                        v.1.clone().into()
                                    }
                                    })
                                }
                            }

                            impl<Th> UpdateStyle<#specific_ident> for Th
                                where Th: #themeid_ident + 'static {
                                fn update_style(self, style: &mut Style) {
                                    let val : #specific_ident = self.into();

                                    style.add_rule(Box::new(val));

                                }
                            }


                            impl <Th>UpdateStyle<#specific_ident> for (Th, #generic_ident)
                                    where Th: #themeid_ident + 'static {
                                    fn update_style(self, style: &mut Style) {
                                        let val : #specific_ident = self.into();

                                        style.add_rule(Box::new(val));

                                    }
                                }

                            impl UpdateStyle<#specific_ident> for usize {
                                fn update_style(self, style: &mut Style){
                                     *style =
                                     with_themes( |borrowed_themes| {

                                        let theme_value : #specific_ident =
                                            if let Some(theme_value) = borrowed_themes.iter().find_map( |theme| theme.#theme_scale_ident.get(self) ){
                                                theme_value.clone().into()

                                            } else {

                                                panic!("Theme scale does not exist {}", #theme_scale_string )

                                            };

                                        let mut new_style = style.clone();
                                        new_style.add_rule(Box::new(theme_value));
                                        new_style
                                     });
                                }
                        }
                        impl UpdateStyle<#specific_ident> for &[usize; 1]
                        where
                        #specific_ident: 'static + Clone + CssValueTrait,
                         {
                            fn update_style(self, style: &mut Style) {
                                let ref_self : &[usize] = self.as_ref();
                                <&[usize] as UpdateStyle<#specific_ident>>::update_style(ref_self, style);
                            }
                        }

                        impl UpdateStyle<#specific_ident> for &[usize; 2]
                        where
                        #specific_ident: 'static + Clone + CssValueTrait,
                         {
                            fn update_style(self, style: &mut Style) {
                                let ref_self : &[usize] = self.as_ref();
                                <&[usize] as UpdateStyle<#specific_ident>>::update_style(ref_self,style);
                            }
                        }

                        impl UpdateStyle<#specific_ident> for &[usize; 3]
                        where
                        #specific_ident: 'static + Clone + CssValueTrait,
                         {
                            fn update_style(self, style: &mut Style) {
                                let ref_self : &[usize] = self.as_ref();
                                <&[usize] as UpdateStyle<#specific_ident>>::update_style(ref_self,style);
                            }
                        }


                        impl UpdateStyle<#specific_ident> for &[usize; 4]
                        where
                        #specific_ident: 'static + Clone + CssValueTrait,
                         {
                            fn update_style(self, style: &mut Style) {
                                let ref_self : &[usize] = self.as_ref();
                                <&[usize] as UpdateStyle<#specific_ident>>::update_style(ref_self,style);
                            }
                        }

                        impl UpdateStyle<#specific_ident> for &[usize; 5]
                        where
                        #specific_ident: 'static + Clone + CssValueTrait,
                         {
                            fn update_style(self, style: &mut Style) {
                                let ref_self : &[usize] = self.as_ref();
                                <&[usize] as UpdateStyle<#specific_ident>>::update_style(ref_self,style);
                            }
                        }

                        impl UpdateStyle<#specific_ident> for &[usize; 6]
                        where
                        #specific_ident: 'static + Clone + CssValueTrait,
                         {
                            fn update_style(self, style: &mut Style) {
                                let ref_self : &[usize] = self.as_ref();
                                <&[usize] as UpdateStyle<#specific_ident>>::update_style(ref_self,style);
                            }
                        }

                        impl UpdateStyle<#specific_ident> for &[usize; 7]
                        where
                        #specific_ident: 'static + Clone + CssValueTrait,
                         {
                            fn update_style(self, style: &mut Style) {
                                let ref_self : &[usize] = self.as_ref();
                                <&[usize] as UpdateStyle<#specific_ident>>::update_style(ref_self,style);
                            }
                        }


                        impl UpdateStyle<#specific_ident> for &[usize; 8]
                        where
                        #specific_ident: 'static + Clone + CssValueTrait,
                         {
                            fn update_style(self, style: &mut Style) {
                                let ref_self : &[usize] = self.as_ref();
                                <&[usize] as UpdateStyle<#specific_ident>>::update_style(ref_self,style);
                            }
                        }

                        impl UpdateStyle<#specific_ident> for &[usize; 9]
                        where
                        #specific_ident: 'static + Clone + CssValueTrait,
                         {
                            fn update_style(self, style: &mut Style) {
                                let ref_self : &[usize] = self.as_ref();
                                <&[usize] as UpdateStyle<#specific_ident>>::update_style(ref_self,style);
                            }
                        }


                        impl UpdateStyle<#specific_ident> for &[usize; 10]
                        where
                        #specific_ident: 'static + Clone + CssValueTrait,
                         {
                            fn update_style(self, style: &mut Style) {
                                let ref_self : &[usize] = self.as_ref();
                                <&[usize] as UpdateStyle<#specific_ident>>::update_style(ref_self,style);
                            }
                        }





                        impl UpdateStyle<#specific_ident> for &[usize] where
                        #specific_ident: 'static + Clone + CssValueTrait,{
                            fn update_style(self, style: &mut Style){

                                *style = with_themes( |borrowed_themes| {


                                    let mut  new_style = style.clone();
                                    if let Some(bp_scale) = &borrowed_themes.iter().find_map(|theme| if !theme.media_bp_scale.is_empty() { Some(theme.media_bp_scale.clone())} else { None }) {


                                        let mut old_style = None;

                                        for (style_idx, bp) in bp_scale.iter().enumerate(){
                                            if let Some(theme_idx) = self.get(style_idx){
                                            if let Some(generic_value )= borrowed_themes
                                                .iter()
                                                .find_map( |theme| theme.#theme_scale_ident.get(*theme_idx)).cloned(){

                                                    let specific_value : #specific_ident = generic_value.into();

                                                    let rules = new_style
                                                                    .media_rules
                                                                    .entry(bp.clone().0)
                                                                    .or_insert(vec![]);
                                                    rules.push(Rule {
                                                        value: Box::new(specific_value.clone()),
                                                    });

                                                    old_style = Some(specific_value);
                                                }else {
                                                    panic!("No theme scale for that index!")
                                                }

                                            } else {
                                                    let rules = new_style
                                                        .media_rules
                                                        .entry(bp.clone().0)
                                                        .or_insert(vec![]);
                                                        rules.push(Rule {
                                                            value: Box::new(old_style.clone().unwrap()),
                                                        });

                                                }


                                        }
                                    } else {
                                        panic!("No breakpoints have been defined!")

                                    }



                                    new_style
                                });

                            }
                        }

                    };

                    let ident_from_generic = if generic_ident != specific_ident {
                        quote!(
                            impl UpdateStyle<#specific_ident> for #generic_ident {
                            fn update_style(self, style: &mut Style) {
                                let val : #specific_ident = self.into();
                                style.add_rule(Box::new(val));
                            }
                        }
                        )
                    } else {
                        quote!()
                    };

                    // println!("{}", expanded);
                    exp = quote! {
                        #ident_from_generic
                        #exp
                        #expanded
                    };
                }
            }
        }
    }

    exp.into()
}

struct CreateEnums {
    properties: ExprArray,
}

impl Parse for CreateEnums {
    fn parse(input: ParseStream) -> Result<Self> {
        let properties: ExprArray = input.parse()?;

        Ok(CreateEnums { properties })
    }
}

#[proc_macro]
pub fn create_enums(input: TokenStream) -> TokenStream {
    let CreateEnums { properties } = parse_macro_input!(input as CreateEnums);

    let mut exp = quote! {};
    for property in properties.elems.iter() {
        if let Expr::Lit(ref property) = property {
            if let syn::Lit::Str(ref property) = property.lit {
                let type_name = format_ident!("Css{}", property.value());

                let css_name = format!("{}: {{}};", property.value().to_kebab_case());

                let expanded = quote! {

                    #[derive(Display,Clone,Debug,CssStyleMacro)]
                    #[display(fmt = #css_name)]
                    pub enum #type_name {
                        #[display(fmt = "inherit")]
                        Inherit,
                        StringValue(String),
                    }


                };
                // println!("{}",expanded);
                exp = quote! {
                    #exp
                    #expanded
                };
            }
        }
    }

    TokenStream::from(exp)
}