"use strict";

var _react = _interopRequireDefault(require("react"));
var _react2 = require("@storybook/react");
var _index = _interopRequireDefault(require("./index"));
var _storybookState = require("@sambego/storybook-state");
var _i18n = require("../../../../Framework/i18n");
var _blau = _interopRequireDefault(require("./res/blau.jpg"));
var _grau = _interopRequireDefault(require("./res/grau.jpg"));
var _rot = _interopRequireDefault(require("./res/rot.jpg"));
var _schwarz = _interopRequireDefault(require("./res/schwarz.jpg"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
var mockedAmountInputData = [{
  url: _blau["default"],
  title: (0, _i18n.t)('mockedData.blue'),
  isSizeButtonClosed: false,
  sizes: [{
    size: 'S',
    amount: 100,
    label: 'S',
    key: 'S'
  }, {
    size: 'M',
    amount: '',
    label: 'M',
    key: 'M'
  }, {
    size: 'L',
    amount: '',
    label: 'L',
    key: 'L'
  }, {
    size: 'XL',
    amount: '',
    label: 'XL',
    key: 'XL'
  }, {
    size: 'XXL',
    amount: '',
    label: 'XXL',
    key: 'XXL'
  }]
}, {
  url: _grau["default"],
  title: (0, _i18n.t)('mockedData.gray'),
  isSizeButtonClosed: false,
  sizes: [{
    size: 'S',
    amount: 100,
    label: 'S',
    key: 'S'
  }, {
    size: 'M',
    amount: '',
    label: 'M',
    key: 'M'
  }, {
    size: 'L',
    amount: '',
    label: 'L',
    key: 'L'
  }, {
    size: 'XL',
    amount: '',
    label: 'XL',
    key: 'XL'
  }, {
    size: 'XXL',
    amount: '',
    label: 'XXL',
    key: 'XXL'
  }]
}, {
  url: _rot["default"],
  title: (0, _i18n.t)('mockedData.red'),
  isSizeButtonClosed: false,
  sizes: [{
    size: 'S',
    amount: 100,
    label: 'S',
    key: 'S'
  }, {
    size: 'M',
    amount: '',
    label: 'M',
    key: 'M'
  }, {
    size: 'L',
    amount: '',
    label: 'L',
    key: 'L'
  }, {
    size: 'XL',
    amount: '',
    label: 'XL',
    key: 'XL'
  }, {
    size: 'XXL',
    amount: '',
    label: 'XXL',
    key: 'XXL'
  }]
}, {
  url: _schwarz["default"],
  title: (0, _i18n.t)('mockedData.black'),
  isSizeButtonClosed: false,
  sizes: [{
    size: 'S',
    amount: 100,
    label: 'S',
    key: 'S'
  }, {
    size: 'M',
    amount: '',
    label: 'M',
    key: 'M'
  }, {
    size: 'L',
    amount: '',
    label: 'L',
    key: 'L'
  }, {
    size: 'XL',
    amount: '',
    label: 'XL',
    key: 'XL'
  }, {
    size: 'XXL',
    amount: '',
    label: 'XXL',
    key: 'XXL'
  }]
}, {
  url: _blau["default"],
  title: (0, _i18n.t)('mockedData.blue') + '1',
  isSizeButtonClosed: false,
  sizes: [{
    size: 'S',
    amount: 100,
    label: 'S',
    key: 'S'
  }, {
    size: 'M',
    amount: '',
    label: 'M',
    key: 'M'
  }, {
    size: 'L',
    amount: '',
    label: 'L',
    key: 'L'
  }, {
    size: 'XL',
    amount: '',
    label: 'XL',
    key: 'XL'
  }, {
    size: 'XXL',
    amount: '',
    label: 'XXL',
    key: 'XXL'
  }]
}];
var OneProductVariantData = [{
  url: _schwarz["default"],
  title: (0, _i18n.t)('mockedData.black'),
  isSizeButtonClosed: true,
  sizes: [{
    size: 'One',
    amount: 100,
    label: (0, _i18n.t)('amountPrice.amount'),
    key: 'black'
  }]
}, {
  url: _rot["default"],
  title: (0, _i18n.t)('mockedData.red'),
  isSizeButtonClosed: true,
  sizes: [{
    size: 'One',
    amount: 100,
    label: (0, _i18n.t)('amountPrice.amount'),
    key: 'red'
  }]
}, {
  url: _blau["default"],
  title: (0, _i18n.t)('mockedData.blue'),
  isSizeButtonClosed: true,
  sizes: [{
    size: 'One',
    amount: 100,
    label: (0, _i18n.t)('amountPrice.amount'),
    key: 'blue'
  }]
}];
var store = new _storybookState.Store({
  amountData: mockedAmountInputData
});
var storeOneVariant = new _storybookState.Store({
  amountData: OneProductVariantData
});
var handleChange = function handleChange(store, state) {
  return function (variant, size, value) {
    var nextData = state.amountData.map(function (currentVariant) {
      if (variant.title === currentVariant.title) {
        return _objectSpread(_objectSpread({}, currentVariant), {}, {
          sizes: currentVariant.sizes.map(function (currentSize) {
            return size.key === currentSize.key ? _objectSpread(_objectSpread({}, currentSize), {}, {
              amount: value
            }) : currentSize;
          })
        });
      }
      return currentVariant;
    });
    store.set({
      amountData: nextData
    });
  };
};
var handleOpenSizeClick = function handleOpenSizeClick(amountData) {
  return function (title, isSizeButtonClosed) {
    var nextData = amountData.map(function (currentElement) {
      if (currentElement.title === title) {
        return _objectSpread(_objectSpread({}, currentElement), {}, {
          isSizeButtonClosed: isSizeButtonClosed
        });
      } else {
        return _objectSpread(_objectSpread({}, currentElement), {}, {
          isSizeButtonClosed: false
        });
      }
      //currentElement;
    });

    store.set({
      amountData: nextData
    });
  };
};
(0, _react2.storiesOf)('ProductVariant', module).add('with label', function () {
  return /*#__PURE__*/_react["default"].createElement(_storybookState.State, {
    store: store
  }, function (state) {
    return /*#__PURE__*/_react["default"].createElement(_index["default"], {
      header: "Produktvarianten",
      handleChange: handleChange(store, state),
      amountData: state.amountData,
      buttonLabel: (0, _i18n.t)('mockedData.selectSize'),
      amountLabel: (0, _i18n.t)('amountPrice.amount'),
      handleOpenSizeClick: handleOpenSizeClick(state.amountData)
    });
  });
}).add('with one variant', function () {
  return /*#__PURE__*/_react["default"].createElement(_storybookState.State, {
    store: storeOneVariant
  }, function (state) {
    return /*#__PURE__*/_react["default"].createElement(_index["default"], {
      header: "Produktvarianten",
      handleChange: handleChange(storeOneVariant, state),
      amountData: state.amountData,
      amountLabel: (0, _i18n.t)('amountPrice.amount')
    });
  });
});