import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import className from 'classnames';
import CaretComponent from '../../shared/components/caret';
import MiniCartSummary from './mini_cart_summary';
import MiniCartBoutique from './mini_cart_boutique';
import MiniCartTrunkshow from './mini_cart_trunkshow';
import AlertIcon from '@moda/icons/alert-16';
import './mini_cart_container.scss';

class MiniCartContainer extends PureComponent {
  static propTypes = {
    cart: PropTypes.object,
    showCorrectPrice: PropTypes.func,
    feature_flags: PropTypes.object,
    current_user_present: PropTypes.bool,
    proceedToCheckout: PropTypes.func,
    proceedToCheckoutAsGuest: PropTypes.func,
    showLoadingOverlay: PropTypes.func,
    disableDepositMessage: PropTypes.bool,
    trunkshow_deposit_rate: PropTypes.number,
    showMarkdownNotification: PropTypes.bool
  };
  constructor(props) {
    super(props);
  }

  render() {
    return (
      <div
        className={className({
          empty: this.props.cart && this.props.cart.cart_items_count == 0
        })}
      >
        <CaretComponent delay={false} show />
        <div className="mini-cart-container">
          {this.props.feature_flags['bag-markdown-notification'] &&
            this.props.showMarkdownNotification && (
              <div className="markdown-message-container">
                <AlertIcon className="markdown-notification-icon" />
                <span>Good news - New markdowns in your bag</span>
              </div>
            )}
          {this.props.cart && this.props.cart.cart_items_count != 0 ? (
            <div className="items">
              {this.props.cart &&
                (this.props.cart.unavailable_order_items.length > 0 ||
                  this.props.cart.ready_to_ship_order_items.length > 0) && (
                  <div className="boutique-items">
                    <div className="available-now-header">Available Now</div>
                    {this.props.cart.unavailable_order_items.length > 0 && (
                      <MiniCartBoutique
                        unavailable_order_items={
                          this.props.cart.unavailable_order_items
                        }
                        showCorrectPrice={this.props.showCorrectPrice}
                        feature_flags={this.props.feature_flags}
                      />
                    )}
                    {this.props.cart &&
                      this.props.cart.ready_to_ship_order_items.length > 0 && (
                        <MiniCartBoutique
                          ready_to_ship_order_items={
                            this.props.cart.ready_to_ship_order_items
                          }
                          showCorrectPrice={this.props.showCorrectPrice}
                          feature_flags={this.props.feature_flags}
                          showMarkdownNotification={
                            this.props.showMarkdownNotification
                          }
                        />
                      )}
                  </div>
                )}
              {this.props.cart && this.props.cart.on_order_items.length > 0 && (
                <div className="trunkshow-items">
                  <div className="preorder-header">Preorder</div>
                  <MiniCartTrunkshow
                    on_order_items={this.props.cart.on_order_items}
                    showCorrectPrice={this.props.showCorrectPrice}
                    feature_flags={this.props.feature_flags}
                    disableDepositMessage={this.props.disableDepositMessage}
                    trunkshow_deposit_rate={this.props.trunkshow_deposit_rate}
                  />
                </div>
              )}
            </div>
          ) : (
            <div className="empty-cart">
              There are currently no items in your bag.
            </div>
          )}
          {this.props.cart && this.props.cart.cart_items_count != 0 && (
            <MiniCartSummary
              cart={this.props.cart}
              showCorrectPrice={this.props.showCorrectPrice}
              feature_flags={this.props.feature_flags}
              current_user_present={this.props.current_user_present}
              proceedToCheckout={this.props.proceedToCheckout}
              proceedToCheckoutAsGuest={this.props.proceedToCheckoutAsGuest}
              showLoadingOverlay={this.props.showLoadingOverlay}
              disableDepositMessage={this.props.disableDepositMessage}
              trunkshow_deposit_rate={this.props.trunkshow_deposit_rate}
            />
          )}
        </div>
      </div>
    );
  }
}

export default MiniCartContainer;
