"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useSwitch = exports.useButton = void 0;

// const isTouchDevice = ()=>{
//     return ('ontouchstart' in document.documentElement);
//     //return ("ontouchstart" in window || window.DocumentTouch && document instanceof DocumentTouch);
// }
var eventsHandling = function eventsHandling(events) {
  var onClick = events.onClick,
      onMouseDown = events.onMouseDown,
      onMouseUp = events.onMouseUp,
      onMouseMove = events.onMouseMove,
      onMouseOut = events.onMouseOut;
  var convertEvents = {};

  if ('ontouchstart' in document.documentElement && (onClick || onMouseDown || onMouseUp || onMouseMove || onMouseOut)) {
    if (onClick) {
      convertEvents.onPointerUp = onClick;
    }

    if (onMouseDown) {
      convertEvents.onPointerDown = onMouseDown;
    }

    if (onMouseUp) {
      convertEvents.onPointerUp = onMouseUp;
    }

    if (onMouseMove) {
      convertEvents.onTouchMove = onMouseMove;
    }

    if (onMouseOut) {
      convertEvents.onTouchOut = onMouseOut;
    }

    return Object.assign({}, events, convertEvents);
  } else {
    return events;
  }
};

var useButton = function useButton(prop) {
  var _ref = prop || {},
      tagAttributeProps = _ref.tagAttributeProps,
      disabled = _ref.disabled,
      text = _ref.text,
      elementType = _ref.elementType,
      ariaHasPopup = _ref.ariaHasPopup,
      ariaExpanded = _ref.ariaExpanded,
      ariaControls = _ref.ariaControls,
      ariaPressed = _ref.ariaPressed,
      ariaSelected = _ref.ariaSelected,
      ariaLabel = _ref.ariaLabel,
      ariaLabelledby = _ref.ariaLabelledby,
      autoFocus = _ref.autoFocus,
      focusClass = _ref.focusClass,
      onClick = _ref.onClick;

  var eventList = eventsHandling(Object.assign(tagAttributeProps, {
    onClick: onClick
  }));
  var additionalProps = {
    role: 'button',
    'aria-disabled': !disabled ? undefined : disabled,
    'aria-haspopup': ariaSelected,
    'aria-expanded': ariaExpanded,
    'aria-controls': ariaControls,
    'aria-pressed': ariaPressed,
    'aria-selected': ariaSelected,
    'aria-label': ariaLabel || text,
    'aria-labelledby': ariaLabelledby,
    'data-aria-autofocus': autoFocus || undefined,
    'data-aria-focusstyle': focusClass
  };
  return {
    buttonProps: Object.assign(additionalProps, eventList)
  };
};

exports.useButton = useButton;

var useSwitch = function useSwitch(prop) {
  var _ref2 = prop || {},
      tagAttributeProps = _ref2.tagAttributeProps,
      disabled = _ref2.disabled,
      label = _ref2.label,
      checked = _ref2.checked,
      onToggle = _ref2.onToggle;

  var eventList = eventsHandling(Object.assign(tagAttributeProps, {
    onClick: onToggle
  }));
  var additionalProps = {
    role: 'switch',
    'aria-disabled': !disabled ? undefined : disabled,
    'aria-label': label,
    'aria-labelledby': label,
    'aria-checked': checked
  };
  return {
    switchProps: Object.assign(additionalProps, eventList)
  };
};

exports.useSwitch = useSwitch;
var eventsObj = {
  'onMouseMove': 'onTouchMove',

  /* not working touch device*/
  'onMouseOut': 'onTouchOut',

  /* not working touch device*/
  'onMouseDown': 'onPointerDown',

  /* not working touch device*/
  'onMouseUp': 'onPointerUp'
  /* not working touch device*/

}; // components : {
//     Avatar : {
//         onClick : onPointer
//     },
//    Button : {
//    },
//    ...
// }