text: "use strict";
  function __export(m) {
      for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  }
  Object.defineProperty(exports, "__esModule", { value: true });
  var color_1 = require("tns-core-modules/color");
  var utils_1 = require("tns-core-modules/utils/utils");
  var imageSource = require("tns-core-modules/image-source/image-source");
  var frame = require("tns-core-modules/ui/frame");
  __export(require("./photoviewer.common"));
  var _dataSource;
  var PhotoViewer = (function () {
      function PhotoViewer() {
          var photosArray = NSMutableArray.alloc().init();
          _dataSource = new NYTPhotoViewerArrayDataSource({ photos: photosArray });
      }
      Object.defineProperty(PhotoViewer.prototype, "ios", {
          get: function () {
              return this.nativeView;
          },
          enumerable: true,
          configurable: true
      });
      PhotoViewer.prototype.showGallery = function (imagesArray, options) {
          var _this = this;
          if (!options)
              options = {};
          if (!options.ios)
              options.ios = {};
          if (!options.android)
              options.android = {};
          var photosArray = NSMutableArray.alloc().init();
          var startIndex = options.startIndex || 0;
          var iosCompletionCallback = options.ios.completionCallback || null;
          imagesArray.forEach(function (imageItem) {
              var imageToAdd = NYTImage.alloc().init();
              var fontFamily = options.ios.fontFamily || "HelveticaNeue";
              var titleFontSize = options.ios.titleFontSize || 16;
              var summaryFontSize = options.ios.summaryFontSize || 14;
              var creditFontSize = options.ios.creditFontSize || 14;
              var titleColor = options.ios.titleColor || new color_1.Color("white").ios;
              var summaryColor = options.ios.summaryColor || new color_1.Color("lightgray").ios;
              var creditColor = options.ios.creditColor || new color_1.Color("gray").ios;
              if (isNYTPhotoItem(imageItem)) {
                  console.log("received photoItem", imageItem);
                  if (imageItem.imageURL)
                      imageToAdd.image = getUIImage(imageItem.imageURL);
                  else
                      imageToAdd.image = imageItem.image;
                  imageToAdd.placeholderImage = imageItem.placeholderImage;
                  imageToAdd.attributedCaptionTitle = _this.attributedString(imageItem.title, titleColor, fontFamily, titleFontSize);
                  imageToAdd.attributedCaptionSummary = _this.attributedString(imageItem.summary, summaryColor, fontFamily, summaryFontSize);
                  imageToAdd.attributedCaptionCredit = _this.attributedString(imageItem.credit, creditColor, fontFamily, creditFontSize);
              }
              else if (typeof imageItem === 'string') {
                  console.log("received image url:", imageItem);
                  var img = getUIImage(imageItem);
                  imageToAdd.image = img;
              }
              else {
                  console.log("ERROR: Passed object is not a image path/url or NYTPhotoItem object!", imageItem);
              }
              photosArray.addObject(imageToAdd);
          });
          _dataSource = new NYTPhotoViewerArrayDataSource({ photos: photosArray });
          this.nativeView = NYTPhotosViewController.alloc().initWithDataSourceInitialPhotoIndexDelegate(_dataSource, startIndex, null);
          if (options.ios.showShareButton == false) {
              this.nativeView.rightBarButtonItem = null;
          }
          frame.topmost().ios.controller.presentViewControllerAnimatedCompletion(this.nativeView, true, iosCompletionCallback);
          return new Promise(function (resolve) {
              _this._delegate = PhotoViewerDelegateImpl.initWithResolve(resolve);
              _this.nativeView.delegate = _this._delegate;
          });
      };
      PhotoViewer.prototype.attributedString = function (text, color, fontFamily, fontSize) {
          var _a;
          var attributeOptions = (_a = {},
              _a[NSForegroundColorAttributeName] = color,
              _a[NSFontAttributeName] = UIFont.fontWithNameSize(fontFamily, fontSize),
              _a);
          return NSAttributedString.alloc().initWithStringAttributes(text || "", attributeOptions);
      };
      return PhotoViewer;
  }());
  exports.PhotoViewer = PhotoViewer;
  function getImageData(imageURL) {
      var nsURL = NSURL.URLWithString(imageURL);
      return NSData.dataWithContentsOfURL(nsURL);
  }
  function getUIImage(imageURL) {
      if (utils_1.isFileOrResourcePath(imageURL)) {
          console.log("image is file or resource path: ", imageURL);
          return imageSource.fromFileOrResource(imageURL).ios;
      }
      else {
          console.log("URL: ", imageURL);
          var nsURL = NSURL.URLWithString(imageURL);
          var imageData = NSData.dataWithContentsOfURL(nsURL);
          return UIImage.imageWithData(imageData);
      }
  }
  function isNYTPhotoItem(item) {
      return typeof item.image === 'object' || typeof item.imageURL === 'string';
  }
  var NYTImage = NSObject.extend({
      get image() { return this.super.image; },
      set image(value) { this.super.image = value; },
      get imageData() { return this.super.imageData; },
      set imageData(value) { this.super.imageData = value; },
      get placeholderImage() { return this.super.placeholderImage; },
      set placeholderImage(value) { this.super.placeholderImage = value; },
      get attributedCaptionTitle() { return this.super.attributedCaptionTitle; },
      set attributedCaptionTitle(value) { this.super.attributedCaptionTitle = value; },
      get attributedCaptionSummary() { return this.super.attributedCaptionSummary; },
      set attributedCaptionSummary(value) { this.super.attributedCaptionSummary = value; },
      get attributedCaptionCredit() { return this.super.attributedCaptionCredit; },
      set attributedCaptionCredit(value) { this.super.attributedCaptionCredit = value; }
  }, {
      name: "NYTImage",
      protocols: [NYTPhoto]
  });
  var PhotoViewerDelegateImpl = (function (_super) {
      __extends(PhotoViewerDelegateImpl, _super);
      function PhotoViewerDelegateImpl() {
          return _super !== null && _super.apply(this, arguments) || this;
      }
      PhotoViewerDelegateImpl_1 = PhotoViewerDelegateImpl;
      PhotoViewerDelegateImpl.initWithResolve = function (resolve) {
          var delegate = PhotoViewerDelegateImpl_1.new();
          delegate._resolve = resolve;
          return delegate;
      };
      PhotoViewerDelegateImpl.prototype.photosViewControllerDidDismiss = function (photosViewController) {
          this._resolve();
      };
      var PhotoViewerDelegateImpl_1;
      PhotoViewerDelegateImpl = PhotoViewerDelegateImpl_1 = __decorate([
          ObjC(NYTPhotosViewControllerDelegate)
      ], PhotoViewerDelegateImpl);
      return PhotoViewerDelegateImpl;
  }(NSObject));
  //# sourceMappingURL=photoviewer.ios.js.map