import { extends as _extends, objectWithoutProperties as _objectWithoutProperties } from '../../../../_virtual/_rollupPluginBabelHelpers.js';
import { jsx } from '@emotion/core';
import React__default from 'react';
import _pt from 'prop-types';
import { getErrorAriaLiveAttribute, getHintId, getErrorId } from '../utils/index.esm.js';

var FormFieldSkeletonContext = React__default.createContext({
  id: "",
  hasHint: undefined,
  hasError: undefined,
  meta: {
    hintId: undefined,
    errorId: undefined,
    controlDescribedBy: undefined
  }
});

function FormFieldSkeletonProvider(_ref) {
  var id = _ref.id,
      hasError = _ref.hasError,
      hasHint = _ref.hasHint,
      children = _ref.children;
  var fieldContext = React__default.useMemo(function () {
    var hintId = getHintId(id);
    var errorId = getErrorId(id);
    var controlDescribedBy = [hasError && errorId, hasHint && hintId].filter(function (describedBy) {
      return describedBy;
    }).join(" ") || undefined;
    return {
      id: id,
      hasError: hasError,
      hasHint: hasHint,
      meta: {
        hintId: hintId,
        errorId: errorId,
        controlDescribedBy: controlDescribedBy
      }
    };
  }, [id, hasError, hasHint]);
  return jsx(FormFieldSkeletonContext.Provider, {
    value: fieldContext
  }, children);
}

FormFieldSkeletonProvider.propTypes = {
  id: _pt.string.isRequired,
  hasHint: _pt.bool,
  hasError: _pt.bool,
  children: _pt.node
};
var FormFieldSkeletonLabel = function FormFieldSkeletonLabel(props) {
  var _useFormFieldSkeleton = useFormFieldSkeleton(),
      id = _useFormFieldSkeleton.id;

  return jsx("label", _extends({
    htmlFor: id
  }, props));
};
var FormFieldSkeletonHint = function FormFieldSkeletonHint(_ref2) {
  var children = _ref2.children,
      rest = _objectWithoutProperties(_ref2, ["children"]);

  var _useFormFieldSkeleton2 = useFormFieldSkeleton(),
      hasHint = _useFormFieldSkeleton2.hasHint,
      meta = _useFormFieldSkeleton2.meta;

  return jsx("div", _extends({
    id: meta.hintId
  }, rest), hasHint ? children : null);
};
var FormFieldSkeletonError = function FormFieldSkeletonError(_ref3) {
  var children = _ref3.children,
      validationMode = _ref3.validationMode,
      rest = _objectWithoutProperties(_ref3, ["children", "validationMode"]);

  var _useFormFieldSkeleton3 = useFormFieldSkeleton(),
      hasError = _useFormFieldSkeleton3.hasError,
      meta = _useFormFieldSkeleton3.meta;

  return jsx("div", _extends({
    id: meta.errorId,
    "aria-live": getErrorAriaLiveAttribute(validationMode)
  }, rest), hasError ? children : null);
};
function FormFieldSkeleton(props) {
  return jsx(FormFieldSkeletonProvider, props);
}
FormFieldSkeleton.propTypes = {
  id: _pt.string.isRequired,
  hasHint: _pt.bool,
  hasError: _pt.bool,
  children: _pt.node
};
function useFormFieldSkeleton() {
  return React__default.useContext(FormFieldSkeletonContext);
}
FormFieldSkeletonLabel.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "FormFieldSkeletonLabel"
};

if (typeof STORYBOOK_REACT_CLASSES !== "undefined") {
  STORYBOOK_REACT_CLASSES["src/components/form-skeletons/components/FormFieldSkeleton.tsx"] = {
    name: "FormFieldSkeletonLabel",
    docgenInfo: FormFieldSkeletonLabel.__docgenInfo,
    path: "src/components/form-skeletons/components/FormFieldSkeleton.tsx"
  };
}

FormFieldSkeletonHint.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "FormFieldSkeletonHint"
};

if (typeof STORYBOOK_REACT_CLASSES !== "undefined") {
  STORYBOOK_REACT_CLASSES["src/components/form-skeletons/components/FormFieldSkeleton.tsx"] = {
    name: "FormFieldSkeletonHint",
    docgenInfo: FormFieldSkeletonHint.__docgenInfo,
    path: "src/components/form-skeletons/components/FormFieldSkeleton.tsx"
  };
}

FormFieldSkeletonError.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "FormFieldSkeletonError"
};

if (typeof STORYBOOK_REACT_CLASSES !== "undefined") {
  STORYBOOK_REACT_CLASSES["src/components/form-skeletons/components/FormFieldSkeleton.tsx"] = {
    name: "FormFieldSkeletonError",
    docgenInfo: FormFieldSkeletonError.__docgenInfo,
    path: "src/components/form-skeletons/components/FormFieldSkeleton.tsx"
  };
}

FormFieldSkeleton.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "FormFieldSkeleton",
  "props": {
    "id": {
      "required": true,
      "tsType": {
        "name": "string"
      },
      "description": ""
    },
    "hasHint": {
      "required": false,
      "tsType": {
        "name": "boolean"
      },
      "description": ""
    },
    "hasError": {
      "required": false,
      "tsType": {
        "name": "boolean"
      },
      "description": ""
    },
    "children": {
      "required": false,
      "tsType": {
        "name": "ReactReactNode",
        "raw": "React.ReactNode"
      },
      "description": ""
    }
  }
};

if (typeof STORYBOOK_REACT_CLASSES !== "undefined") {
  STORYBOOK_REACT_CLASSES["src/components/form-skeletons/components/FormFieldSkeleton.tsx"] = {
    name: "FormFieldSkeleton",
    docgenInfo: FormFieldSkeleton.__docgenInfo,
    path: "src/components/form-skeletons/components/FormFieldSkeleton.tsx"
  };
}

export { FormFieldSkeleton, FormFieldSkeletonError, FormFieldSkeletonHint, FormFieldSkeletonLabel, useFormFieldSkeleton };
//# sourceMappingURL=FormFieldSkeleton.esm.js.map
