function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
import React, { Component } from 'react';
import { Image, StyleSheet, Dimensions, TouchableOpacity, View } from 'react-native';
import PropTypes from 'prop-types';
import colors from "../../Styles";
import FastImage from 'react-native-fast-image';
import { MText as Text } from '../../components';
const styles = StyleSheet.create({
  marker: {
    position: 'absolute',
    top: 10,
    right: 10,
    backgroundColor: 'transparent',
    width: 20,
    height: 20,
    borderWidth: 2,
    borderRadius: 10,
    borderColor: colors.primary
  }
});
class ImageItem extends Component {
  constructor() {
    super(...arguments);
    _defineProperty(this, "arrayObjectIndexOf", (array, property, value) => array.map(o => o[property]).indexOf(value));
  }
  componentWillMount() {
    let {
      width
    } = Dimensions.get('window');
    const {
      imageMargin,
      imagesPerRow,
      containerWidth
    } = this.props;
    if (typeof containerWidth !== 'undefined') {
      width = containerWidth;
    }
    this.imageSize = (width - (imagesPerRow + 1) * imageMargin) / imagesPerRow;
  }
  handleClick(item) {
    this.props.onClick(item);
  }
  fancyTimeFormat(duration) {
    try {
      // Hours, minutes and seconds
      const hrs = ~~(duration / 3600);
      const mins = ~~(duration % 3600 / 60);
      const secs = ~~duration % 60;

      // Output like "1:01" or "4:03:59" or "123:03:59"
      let ret = "";
      if (hrs > 0) {
        ret += "" + hrs + ":" + (mins < 10 ? "0" : "");
      }
      ret += "" + mins + ":" + (secs < 10 ? "0" : "");
      ret += "" + secs;
      return ret;
    } catch (e) {
      return '';
    }
  }
  render() {
    const {
      item,
      selected,
      selectedMarker,
      imageMargin,
      selectedList
    } = this.props;
    const {
      image
    } = item.node;
    const indexSelected = this.arrayObjectIndexOf(selectedList ? selectedList : [], 'uri', image.uri);
    const marker = /*#__PURE__*/React.createElement(View, {
      style: [styles.marker, {
        width: 20,
        height: 20,
        backgroundColor: selected ? colors.primary : 'transparent'
      }]
    }, selected && /*#__PURE__*/React.createElement(Text, {
      style: {
        fontWeight: '600',
        fontSize: 15,
        color: 'white',
        marginTop: -4,
        textAlign: 'center'
      }
    }, indexSelected + 1));
    return /*#__PURE__*/React.createElement(TouchableOpacity, {
      style: {
        marginBottom: imageMargin,
        marginRight: imageMargin
      },
      onPress: () => this.handleClick(image)
    }, /*#__PURE__*/React.createElement(Image, {
      source: {
        uri: image.uri
      },
      style: {
        height: this.imageSize,
        width: this.imageSize,
        backgroundColor: 'grey'
      }
    }), marker, (item.node.type === 'video' || image.playableDuration !== null && image.playableDuration > 0) && /*#__PURE__*/React.createElement(Text, {
      style: {
        position: 'absolute',
        fontSize: 12,
        color: '#fffffffa',
        bottom: 10,
        right: 8
      }
    }, this.fancyTimeFormat(image.playableDuration)));
  }
}
ImageItem.defaultProps = {
  item: {},
  selected: false
};
ImageItem.propTypes = {
  item: PropTypes.object,
  selected: PropTypes.bool,
  selectedMarker: PropTypes.element,
  imageMargin: PropTypes.number,
  imagesPerRow: PropTypes.number,
  onClick: PropTypes.func
};
export default ImageItem;
//# sourceMappingURL=ImageItem.js.map