"use strict";

exports.__esModule = true;
exports.UPLOAD_THROTTLE = void 0;
exports.chooseImageForWechat = chooseImageForWechat;
exports.createFileItem = createFileItem;
var _utils = require("../utils");
var UPLOAD_THROTTLE = 800;
exports.UPLOAD_THROTTLE = UPLOAD_THROTTLE;
function createFileItem(url, file) {
  var id = Math.ceil(Math.random() * 1e7);
  var isImage = _utils.isMiniappPlatform || url.startsWith('data:image/');
  return {
    uid: "file_" + id,
    name: 'file',
    state: 'selected',
    response: {},
    url: '',
    percent: 0,
    isImage: isImage,
    file: _utils.isStrictMiniApp ? url : file || url,
    dataURL: url
  };
}
function chooseImageForWechat(options) {
  return new Promise(function (resolve, reject) {
    var _options$count = options.count,
      count = _options$count === void 0 ? 1 : _options$count,
      _options$mediaType = options.mediaType,
      mediaType = _options$mediaType === void 0 ? ['video', 'image'] : _options$mediaType,
      _options$sourceType = options.sourceType,
      sourceType = _options$sourceType === void 0 ? ['camera', 'album'] : _options$sourceType,
      _options$maxDuration = options.maxDuration,
      maxDuration = _options$maxDuration === void 0 ? 30 : _options$maxDuration,
      sizeType = options.sizeType;
    wx.chooseMedia({
      sourceType: sourceType,
      count: count,
      maxDuration: maxDuration,
      mediaType: mediaType,
      sizeType: sizeType,
      success: function success(res) {
        var data = [];
        var previewImgs = [];
        if (res.tempFilePaths) {
          data = res.dataPaths;
        } else if (Array.isArray(res.tempFiles)) {
          data = res.tempFiles.map(function (item) {
            return item.tempFilePath || '';
          });
          previewImgs = res.tempFiles.map(function (item) {
            return item.thumbTempFilePath || '';
          });
        }
        resolve(Object.assign({}, {
          data: data,
          previewImgs: previewImgs,
          tempFilePaths: data
        }, res));
      },
      fail: function fail(e) {
        reject(e);
      }
    });
  });
}