"use strict";

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

var _preact = require("preact");

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

const cardStyles3D = {
  transition: '0.6s',
  transformStyle: 'preserve-3d',
  webkitTransformStyle: 'preserve-3d',
  transformOrigin: 'center',
  webkitTransformOrigin: 'center'
};
const cardFaceStyles3D = {
  backfaceVisibility: 'hidden',
  webkitBackfaceVisibility: 'hidden'
};
const cardFaceStyleBack = {
  position: 'absolute',
  width: '100%',
  height: '100%',
  top: '0',
  left: '0'
};

const cardFaceStyleFront = _objectSpread(_objectSpread({}, cardFaceStyleBack), {}, {
  // this maintains the height of the card while letting it be dynamic
  position: 'relative'
});

const FlipContainer = (_ref) => {
  let {
    front,
    back,
    flipped,
    height,
    width,
    className,
    style,
    direction = 'vertical',
    perspective = '100px',
    is3D = true
  } = _ref,
      rest = _objectWithoutProperties(_ref, ["front", "back", "flipped", "height", "width", "className", "style", "direction", "perspective", "is3D"]);

  const axis = direction === 'vertical' ? 'X' : 'Y';
  const rotateZero = "";
  const rotateFlipped = "rotate".concat(axis, "(180deg)");
  return (0, _preact.h)("div", _extends({
    "data-comp": "scene"
  }, rest, {
    className: className,
    style: _objectSpread({
      perspective: is3D ? perspective : null,
      width,
      height
    }, style || {})
  }), (0, _preact.h)("div", {
    "data-comp": "card",
    style: _objectSpread(_objectSpread({}, is3D ? _objectSpread(_objectSpread({}, cardStyles3D), {}, {
      transform: flipped ? rotateFlipped : '',
      webkitTransform: flipped ? rotateFlipped : ''
    }) : {}), {}, {
      position: 'relative',
      width: '100%',
      height: '100%'
    })
  }, is3D && (0, _preact.h)("div", {
    "data-comp": "front",
    "data-state": flipped ? 'hidden' : 'visible',
    style: _objectSpread(_objectSpread(_objectSpread({}, cardFaceStyleFront), cardFaceStyles3D), {}, {
      transform: rotateZero,
      webkitTransform: rotateZero
    })
  }, front), is3D && (0, _preact.h)("div", {
    "data-comp": "back",
    "data-state": flipped ? 'visible' : 'hidden',
    style: _objectSpread(_objectSpread(_objectSpread({}, cardFaceStyleBack), cardFaceStyles3D), {}, {
      transform: rotateFlipped,
      webkitTransform: rotateFlipped
    })
  }, back), !is3D && (0, _preact.h)("div", {
    "data-comp": "front",
    "data-state": flipped ? 'hidden' : 'visible',
    className: flipped ? 'hidden' : null,
    style: cardFaceStyleFront
  }, front), !is3D && (0, _preact.h)("div", {
    "data-comp": "back",
    "data-state": flipped ? 'visible' : 'hidden',
    className: flipped ? null : 'hidden',
    style: cardFaceStyleBack
  }, back)));
};

exports.FlipContainer = FlipContainer;