import './_commonjsHelpers-0c4b6f40.js';
import React__default from 'react';
import './index-73819142.js';
import urlFor from './urlFor.js';
import { m as main_36 } from './main-e4a934b2.js';
import Carousel from 'react-bootstrap/Carousel';

//Feature query to be used
// const featureQuery = `*[_type == 'feature' && is_active == true && feature_url == "/"] | order(_updatedAt asc)[0..5]{
//     ...,
//      feature_img { asset-> {url} }
//    }`

//Update*  Added control toggle for features.  Will default to off -
//<Feature controls dataset={props.features} /></div>

var Feature = function Feature(props) {
  var dataset = props.dataset;
  var _props$controls = props.controls,
      controls = _props$controls === undefined ? false : _props$controls,
      client = props.client;


  var checkUrlIsExternal = function checkUrlIsExternal(url) {
    if (/(http|https?)([^\s]+)/g.test(url)) {
      return true;
    }
    return false;
  };

  //image width updated.
  var imageWidth = 450;
  if (main_36) {
    imageWidth = 225;
  }

  var renderUrl = function renderUrl(feature_link, feature_title, feature_body) {
    if (checkUrlIsExternal(feature_link)) {
      return React__default.createElement(
        React__default.Fragment,
        null,
        React__default.createElement(
          'a',
          { href: feature_link, target: '_blank' },
          React__default.createElement(
            'h3',
            { style: { color: 'white' } },
            feature_title
          ),
          React__default.createElement(
            'p',
            { style: { color: '#eee' } },
            feature_body
          )
        )
      );
    }

    return React__default.createElement(
      'a',
      { href: feature_link },
      React__default.createElement(
        'h3',
        { style: { color: 'white' } },
        feature_title
      ),
      React__default.createElement(
        'p',
        { style: { color: '#eee' } },
        feature_body
      )
    );
  };

  return React__default.createElement(
    'div',
    null,
    React__default.createElement(
      Carousel,
      { touch: true, controls: controls },
      dataset.map(function (feature, index) {
        var feature_title = feature.feature_title,
            feature_body = feature.feature_body,
            feature_img = feature.feature_img,
            feature_alt = feature.feature_alt,
            feature_link = feature.feature_link;

        return React__default.createElement(
          Carousel.Item,
          { key: index, style: { background: 'var(--primary)' } },
          React__default.createElement('img', {
            style: { maxHeight: '375px', minHeight: '300px', objectFit: 'cover', paddingLeft: '50%' },
            className: 'd-block w-100',
            src: urlFor({ client: client, source: feature_img, imageWidth: imageWidth }),
            alt: feature_alt
          }),
          React__default.createElement(
            Carousel.Caption,
            {
              style: { paddingRight: '50%', left: '3rem', right: '3rem', top: '0', height: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center' } },
            renderUrl(feature_link, feature_title, feature_body)
          )
        );
      })
    )
  );
};

export default Feature;
