"use strict";

var __assign = void 0 && (void 0).__assign || function () {
  __assign = Object.assign || function (t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];

      for (var p in s) {
        if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
      }
    }

    return t;
  };

  return __assign.apply(this, arguments);
};

var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
  if (k2 === undefined) k2 = k;
  Object.defineProperty(o, k2, {
    enumerable: true,
    get: function get() {
      return m[k];
    }
  });
} : function (o, m, k, k2) {
  if (k2 === undefined) k2 = k;
  o[k2] = m[k];
});

var __setModuleDefault = void 0 && (void 0).__setModuleDefault || (Object.create ? function (o, v) {
  Object.defineProperty(o, "default", {
    enumerable: true,
    value: v
  });
} : function (o, v) {
  o["default"] = v;
});

var __importStar = void 0 && (void 0).__importStar || function (mod) {
  if (mod && mod.__esModule) return mod;
  var result = {};
  if (mod != null) for (var k in mod) {
    if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  }

  __setModuleDefault(result, mod);

  return result;
};

var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
  return mod && mod.__esModule ? mod : {
    "default": mod
  };
};

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.pdfTypes = exports.videoTypes = exports.imgTypes = void 0;

var jsx_runtime_1 = require("react/jsx-runtime");

var react_1 = __importDefault(require("react"));

require("./index.css");

var dialog_1 = require("../dialog");

var preview_list_1 = __importStar(require("../preview-list"));

var themes_1 = require("../style/themes");

var video_cam_dark_svg_1 = __importDefault(require("../map-info-window/asserts/video-cam-dark.svg"));

var video_cam_light_svg_1 = __importDefault(require("../map-info-window/asserts/video-cam-light.svg"));

var pdf_svg_1 = __importDefault(require("../map-info-window/asserts/pdf.svg"));

var ahooks_1 = require("ahooks");

exports.imgTypes = ['png', 'jpg', 'jpeg', 'webp', 'avif'];
exports.videoTypes = ['mp4', 'flv', '3gp', 'mpeg', 'ogg', 'webm'];
exports.pdfTypes = ['pdf', 'PDF'];
var prefixCls = 'dmc';

var Player = function Player(props) {
  var url = props.url,
      prefixCls = props.prefixCls;
  var ref = react_1["default"].useRef(null);
  ahooks_1.useMount(function () {
    Promise.resolve().then(function () {
      return __importStar(require('xgplayer'));
    }).then(function (_a) {
      var Player = _a["default"];
      new Player({
        el: ref.current,
        autoplay: true,
        url: url,
        fitVideoSize: 'auto'
      });
    });
  });
  return jsx_runtime_1.jsx("div", __assign({
    className: prefixCls + "-video-content"
  }, {
    children: jsx_runtime_1.jsx("div", {
      ref: ref
    }, void 0)
  }), void 0);
};

var RenderCell = function RenderCell(props) {
  var _a, _b, _c, _d;

  var theme = themes_1.getTheme() || 'dark';
  var img = video_cam_dark_svg_1["default"];

  if (exports.imgTypes.includes((_a = props === null || props === void 0 ? void 0 : props.item) === null || _a === void 0 ? void 0 : _a.type)) {
    img = (_b = props === null || props === void 0 ? void 0 : props.item) === null || _b === void 0 ? void 0 : _b.value;
  } else if (exports.videoTypes.includes((_c = props === null || props === void 0 ? void 0 : props.item) === null || _c === void 0 ? void 0 : _c.type)) {
    img = theme === 'dark' ? video_cam_dark_svg_1["default"] : video_cam_light_svg_1["default"];
  } else if (exports.pdfTypes.includes((_d = props === null || props === void 0 ? void 0 : props.item) === null || _d === void 0 ? void 0 : _d.type)) {
    img = pdf_svg_1["default"];
  }

  return jsx_runtime_1.jsx("div", {
    className: prefixCls + "-media-preview-list-item",
    style: {
      backgroundPosition: 'center',
      backgroundSize: 'contain',
      backgroundRepeat: 'no-repeat',
      backgroundImage: "url(" + img + ")",
      height: '100%'
    }
  }, void 0);
};

var RenderPreview = function RenderPreview(props) {
  var _a, _b, _c, _d, _e, _f;

  var _element = jsx_runtime_1.jsxs("div", {
    children: [" ", (_a = props === null || props === void 0 ? void 0 : props.item) === null || _a === void 0 ? void 0 : _a.name]
  }, void 0);

  var element = jsx_runtime_1.jsxs("div", __assign({
    className: prefixCls + "-media-preview-item"
  }, {
    children: [_element, jsx_runtime_1.jsx("div", {
      style: {
        width: '100%',
        height: 'calc(100% - 20px)',
        backgroundPosition: 'center',
        backgroundSize: 'contain',
        backgroundRepeat: 'no-repeat',
        backgroundImage: "url(" + ((_b = props === null || props === void 0 ? void 0 : props.item) === null || _b === void 0 ? void 0 : _b.value) + ")"
      }
    }, void 0)]
  }), void 0);

  if (exports.videoTypes.includes((_c = props === null || props === void 0 ? void 0 : props.item) === null || _c === void 0 ? void 0 : _c.type)) {
    element = jsx_runtime_1.jsxs("div", __assign({
      className: prefixCls + "-media-preview-item"
    }, {
      children: [_element, jsx_runtime_1.jsx(Player, {
        url: (_d = props === null || props === void 0 ? void 0 : props.item) === null || _d === void 0 ? void 0 : _d.value,
        id: 'video_' + Math.random(),
        prefixCls: prefixCls
      }, void 0)]
    }), void 0);
  }

  if (exports.pdfTypes.includes((_e = props === null || props === void 0 ? void 0 : props.item) === null || _e === void 0 ? void 0 : _e.type)) {
    element = jsx_runtime_1.jsxs("div", __assign({
      className: prefixCls + "-media-preview-item"
    }, {
      children: [_element, jsx_runtime_1.jsx("iframe", {
        title: '',
        src: (_f = props === null || props === void 0 ? void 0 : props.item) === null || _f === void 0 ? void 0 : _f.value,
        width: "100%",
        height: "100%"
      }, void 0)]
    }), void 0);
  }

  return element;
};

var openMediaPreviewDialog = function openMediaPreviewDialog(props) {
  var _a = props.list,
      list = _a === void 0 ? [] : _a,
      getPreviewPopupContainer = props.getPreviewPopupContainer,
      _b = props.defaultSelectIndex,
      defaultSelectIndex = _b === void 0 ? 0 : _b;
  dialog_1.dialogApi.open({
    closable: true,
    maskClosable: true,
    mask: true,
    wrapClassName: prefixCls + "-media-preview",
    style: {
      width: '100vw',
      height: '100vh',
      margin: 0
    },
    getContainer: getPreviewPopupContainer,
    footer: function footer() {
      return null;
    }
  }, function (onClose) {
    return jsx_runtime_1.jsx(preview_list_1["default"], {
      title: "preview",
      defaultSelectIndex: defaultSelectIndex,
      handleClose: onClose,
      showEdit: false,
      list: list,
      type: preview_list_1.PreviewType.normal,
      RenderCell: RenderCell,
      RenderPreview: RenderPreview
    }, void 0);
  });
};

exports["default"] = openMediaPreviewDialog;

