import React from 'react';
import OpenCard from "../../OpenCard";
import { PisellCheckboxGroup, PisellText } from '@pisell/materials';
import { locales } from '@pisell/utils';
import { useEventDetail } from "../../../../Sales";
import Decimal from 'decimal.js';
import PisellPriceText from "../../../../productSelect/components/pisellPriceText";
var BookingOptions = function BookingOptions(props) {
  var _detail$bookingOption, _detail$bookingOption2;
  var _useEventDetail = useEventDetail(),
    detail = _useEventDetail.detail,
    currentBookingOption = _useEventDetail.currentBookingOption,
    selectEventDetailBookingOptions = _useEventDetail.selectEventDetailBookingOptions;
  var onChange = function onChange(value, item) {
    var _props$onChangeBookin;
    selectEventDetailBookingOptions(value);
    props === null || props === void 0 || (_props$onChangeBookin = props.onChangeBookingOption) === null || _props$onChangeBookin === void 0 || _props$onChangeBookin.call(props, item);
  };
  return /*#__PURE__*/React.createElement(OpenCard, {
    title: locales.getText('pisell2.event.booking.options'),
    showBorder: true,
    showArrow: false,
    isClick: false,
    className: "detail-option-wrap"
  }, /*#__PURE__*/React.createElement(PisellCheckboxGroup, {
    mode: "single",
    iconPosition: (detail === null || detail === void 0 || (_detail$bookingOption = detail.bookingOptions) === null || _detail$bookingOption === void 0 ? void 0 : _detail$bookingOption.length) > 1 ? 'right' : 'hide',
    options: (detail === null || detail === void 0 ? void 0 : detail.bookingOptions) || [],
    optionClassName: "option-item ".concat((detail === null || detail === void 0 || (_detail$bookingOption2 = detail.bookingOptions) === null || _detail$bookingOption2 === void 0 ? void 0 : _detail$bookingOption2.length) > 1 ? 'option-item-pointer' : ''),
    value: currentBookingOption,
    renderOption: function renderOption(option) {
      var _ref = option._originData || {},
        price = _ref.price,
        is_bundle = _ref.is_bundle,
        minimum_markup_price = _ref.minimum_markup_price;
      if (!option._originData || !is_bundle) {
        return /*#__PURE__*/React.createElement("div", {
          className: "item"
        }, /*#__PURE__*/React.createElement("span", null, option.label), /*#__PURE__*/React.createElement(PisellText.Amount, {
          value: option.price,
          showCurrencySymbol: true,
          className: "price"
        }));
      }
      var _price = price;
      if (is_bundle) {
        _price = new Decimal(price).plus(new Decimal(minimum_markup_price)).toFixed(2);
      }
      return /*#__PURE__*/React.createElement("div", {
        className: "item"
      }, /*#__PURE__*/React.createElement("span", null, option.label), /*#__PURE__*/React.createElement(PisellPriceText, {
        className: "price",
        value: _price,
        isMini: true
      }));
    },
    onChange: onChange
  }));
};
export default BookingOptions;