'use strict';

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }

require('./_commonjsHelpers-06173234.js');
require('./_to-object-329a650b.js');
require('./_object-pie-68c5bcbc.js');
var _extends = require('./extends-60837c34.js');
var React = require('react');
var React__default = _interopDefault(React);
require('prop-types');
var Container = _interopDefault(require('react-bootstrap/Container'));
var Row = _interopDefault(require('react-bootstrap/Row'));
var Col = _interopDefault(require('react-bootstrap/Col'));
var Card = _interopDefault(require('react-bootstrap/Card'));
require('react-dom');
var index$1 = require('./index-be0c82be.js');
var index$2 = require('./index-da796b8c.js');
var BlockContent = require('./BlockContent-091a991f.js');
var reactSocialIcons = require('./react-social-icons-f7f48f71.js');

var TaxonomyCard = function TaxonomyCard(props) {
  // setting default value for imageHeight
  var columns = props.columns,
      variant = props.variant,
      _props$icon = props.icon,
      icon = _props$icon === undefined ? false : _props$icon,
      data = props.dataRecord,
      defaultImage = props.defaultImage,
      client = props.client,
      _props$imageHeight = props.imageHeight,
      imageHeight = _props$imageHeight === undefined ? 270 : _props$imageHeight,
      imageWidth = props.imageWidth,
      getSerializers = props.getSerializers;

  var builder = index$1.imageUrlBuilder(client);

  var urlFor = function urlFor(source) {
    return builder.image(source).auto('format');
  };

  var renderCardImage = function renderCardImage(row) {
    var url = urlFor(row.thumbnail);
    if (imageHeight) url = url.height(imageHeight);
    if (imageWidth) url = url.width(imageWidth);
    return url.url();
  };

  var mode = variant && variant === 'bottom' ? 'column-reverse' : 'column';

  var itemCounter = 0;
  var lgVar = 12;

  return React__default.createElement(
    'div',
    { className: 'contentDeck' },
    React__default.createElement(
      Container,
      null,
      React__default.createElement(
        Row,
        null,
        data && data.map(function (row, index) {
          if (columns === 'rotate' && itemCounter % 3 === 0) {
            lgVar = 12;
          } else if (columns && columns !== 'rotate') {
            lgVar = Math.floor(12 / columns);
          } else {
            lgVar = 6;
          }
          var thumbnailURL = row.thumbnail && row.thumbnail.asset ? renderCardImage(row) : defaultImage;
          var address1 = row.address1,
              address2 = row.address2,
              city = row.city,
              zip = row.zip,
              state = row.state,
              country = row.country,
              company = row.company,
              website = row.website,
              email = row.email,
              extraURL1 = row.extraURL1,
              extraURL2 = row.extraURL2,
              extraURL3 = row.extraURL3,
              extraURL4 = row.extraURL4,
              linkedIn = row.linkedIn,
              twitter = row.twitter,
              facebook = row.facebook;

          var socialLinks = [linkedIn, twitter, facebook];
          var address = [address1, address2, city, state, zip, country];
          var companyDetails = [];
          company && companyDetails.push({ key: 'company', value: company });
          website && companyDetails.push({ key: 'url', value: website });
          email && companyDetails.push({ key: 'email', value: email });
          extraURL1 && companyDetails.push({ key: 'url', value: extraURL1 });
          extraURL2 && companyDetails.push({ key: 'url', value: extraURL2 });
          extraURL3 && companyDetails.push({ key: 'url', value: extraURL3 });
          extraURL4 && companyDetails.push({ key: 'url', value: extraURL4 });
          return React__default.createElement(
            Col,
            { key: itemCounter, md: 12, lg: lgVar, counter: itemCounter++, style: { display: 'flex', flex: '1 0 auto' } },
            React__default.createElement(
              Card,
              { className: 'taxonomy-card', style: { flexDirection: mode, position: 'relative', overflow: 'hidden' } },
              React__default.createElement(
                Card.Body,
                null,
                React__default.createElement(
                  Row,
                  null,
                  thumbnailURL && React__default.createElement(
                    Col,
                    null,
                    React__default.createElement(
                      index$2.LazyLoad,
                      { height: imageHeight },
                      row && row.thumbnail && React__default.createElement(
                        'figure',
                        null,
                        row.thumbnail.link ? React__default.createElement(
                          'a',
                          { href: row.thumbnail.link, target: row.thumbnail.blank ? '_blank' : '_self' },
                          React__default.createElement(Card.Img, { variant: 'top', src: thumbnailURL, alt: row.thumbnail.alt ? row.thumbnail.alt : 'profile image' })
                        ) : React__default.createElement(Card.Img, { variant: 'top', src: thumbnailURL, alt: row.thumbnail.alt ? row.thumbnail.alt : 'profile image' }),
                        row && row.thumbnail && row.thumbnail.caption && React__default.createElement(
                          'figcaption',
                          null,
                          row.thumbnail.caption
                        )
                      )
                    )
                  ),
                  React__default.createElement(
                    Col,
                    null,
                    React__default.createElement(
                      Row,
                      { className: 'details-content-wrapper' },
                      React__default.createElement(
                        'div',
                        { className: 'details-content-inner-wrapper' },
                        (address && address.length > 0 || companyDetails && companyDetails.length > 0) && React__default.createElement(
                          'div',
                          { className: 'details-wrapper' },
                          companyDetails && companyDetails.length > 0 && React__default.createElement(
                            'div',
                            { className: 'company-wrapper' },
                            companyDetails.map(function (field, index) {
                              if (field.value && field.key === 'company') {
                                return React__default.createElement(
                                  'p',
                                  { className: 'details-field', key: index },
                                  field.value
                                );
                              } else if (field.value && field.key === 'url') {
                                return React__default.createElement(
                                  'a',
                                  { className: 'details-field', href: field.value, key: index },
                                  field.value
                                );
                              }
                              // else if (field.value && field.key === 'email') {
                              //   return (
                              //     <a className='details-field' href={`mailto:${field.value}`} key={index}>
                              //       {field.value}
                              //     </a>
                              //   )
                              // }
                            })
                          ),
                          address && address.length > 0 && React__default.createElement(
                            'div',
                            { className: 'address-wrapper' },
                            address.map(function (field, index) {
                              if (field) {
                                return React__default.createElement(
                                  'p',
                                  { className: 'details-field', key: index },
                                  field
                                );
                              }
                            })
                          ),
                          React__default.createElement(
                            'style',
                            { jsx: 'true' },
                            '\n                                    .details-content-wrapper,\n                                    .details-content-inner-wrapper {\n                                      width: 100%;\n                                    }\n                                    .details-wrapper .details-field {\n                                      margin: 0px;\n                                      display: block;\n                                      font-size: 1rem;\n                                      margin-bottom: 3px;\n                                    }\n                                    .details-wrapper .company-wrapper {\n                                      margin-right: 20px;\n                                      display: inline-block;\n                                      width: 50%;\n                                      vertical-align: top;\n                                    }\n                                    .details-wrapper .address-wrapper {\n                                      width: 45%;\n                                      display: inline-block;\n                                    }\n                                  '
                          )
                        ),
                        socialLinks && socialLinks.length && React__default.createElement(
                          'div',
                          { className: 'social-icons' },
                          socialLinks.map(function (url, index) {
                            if (url && url.length) {
                              return React__default.createElement(reactSocialIcons.reactSocialIcons_1, {
                                target: '_blank',
                                rel: 'noopener noreferrer',
                                key: index,
                                index: index,
                                url: url,
                                style: { width: 30, height: 30, marginRight: 10 }
                              });
                            }
                          }),
                          React__default.createElement(
                            'style',
                            { jsx: 'true' },
                            '\n                                    .social-icons {\n                                      margin-top: 0px;\n                                      margin-bottom: 10px;\n                                    }\n                                  '
                          )
                        ),
                        React__default.createElement(
                          Card.Text,
                          null,
                          React__default.createElement(BlockContent.BlockContent, _extends._extends({ blocks: row.summary, serializers: getSerializers }, client.config()))
                        )
                      )
                    )
                  )
                ),
                icon && React__default.createElement(
                  'span',
                  {
                    className: 'taxonomy-icon',
                    style: {
                      position: 'absolute',
                      right: '20px',
                      top: '50%',
                      transform: 'translateY(-50%) translateX(50px)',
                      transition: 'all .25s',
                      pointerEvents: 'none'
                    } },
                  '\u2192'
                )
              )
            )
          );
        })
      )
    ),
    icon && React__default.createElement(
      'style',
      { jsx: 'true' },
      '\n          .taxonomy-card:hover .taxonomy-icon {\n            transform: translateY(-50%) scale(1.5) translateX(0) !important;\n          }\n        '
    )
  );
};

module.exports = TaxonomyCard;
