library angular2.src.transform.quick_transformer;

import 'package:barback/barback.dart';
import 'package:dart_style/dart_style.dart';

import 'common/formatter.dart' as formatter;
import 'common/options.dart';
import 'common/options_reader.dart';
import 'deferred_rewriter/transformer.dart';
// import 'directive_metadata_linker/transformer.dart';
// import 'directive_processor/transformer.dart';
import 'inliner_for_test/transformer.dart';
import 'reflection_remover/transformer.dart';
// import 'stylesheet_compiler/transformer.dart';
// import 'template_compiler/transformer.dart';

export 'common/options.dart';

/// Replaces Angular 2 mirror use with generated code.
///
/// Typical users should not use this implementation and should instead use
/// package:angular2/transformer.dart.
///
/// This alternative excludes phases that generate new [Asset]s, including only
/// the phases that replace existing [Asset]s.
///
/// This can be used if all code that would be generated already exists as real
/// files, rather than needing to be generated by [Transformer]s.
class AngularTransformerGroup extends TransformerGroup {
  AngularTransformerGroup._(phases, {bool formatCode: false}) : super(phases) {
    if (formatCode) {
      formatter.init(new DartFormatter());
    }
  }

  factory AngularTransformerGroup(TransformerOptions options) {
    var phases;
    if (options.inlineViews) {
      phases = [
        [new InlinerForTest(options)]
      ];
    } else {
      // Only the phases that replace [Asset]s.
      phases = [
        [new ReflectionRemover(options)],
        [new DeferredRewriter(options)],
      ];
      /*
      phases = [
        [new DirectiveProcessor(options)],
        [new DirectiveMetadataLinker()],
        [new ReflectionRemover(options)],
        [
          new DeferredRewriter(options),
          new StylesheetCompiler(),
          new TemplateCompiler(options)
        ],
      ];
      */
    }
    return new AngularTransformerGroup._(phases,
        formatCode: options.formatCode);
  }

  factory AngularTransformerGroup.asPlugin(BarbackSettings settings) {
    return new AngularTransformerGroup(parseBarbackSettings(settings));
  }
}
