"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

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

var _react = _interopRequireWildcard(require("react"));

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _uuid = require("uuid");

var _primitives = require("../../../primitives");

var _typography = require("../../../mixins/typography");

var _branding = require("../../../mixins/branding");

var _checkbox = require("../../icon/checkbox");

var _focus = require("../../../mixins/focus");

var _spacing = require("../../../mixins/spacing");

var _stackee = require("../../../mixins/stackee");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

var ClickableBox = (0, _styledComponents["default"])(_primitives.Box).withConfig({
  displayName: "ClickableBox",
  componentId: "sc-1rknd2d-0"
})(["cursor:pointer;position:relative;", " &:focus-within{box-shadow:", ",", " ", ";}border-radius:", ";"], (0, _focus.getBaseFocusState)({
  hoverTransition: false,
  activeTransition: false
}), _focus.focusedBoxShadow, _focus.focusedBorderShadow, _focus.focusedBorderColor, _focus.focusedBorderRadius);
ClickableBox.displayName = 'ClickableBox';

var CheckboxContainer = _styledComponents["default"].div.withConfig({
  displayName: "CheckboxContainer",
  componentId: "sc-1rknd2d-1"
})(["position:absolute;left:-10px;top:2px;"]);

var Label = _styledComponents["default"].label.attrs(function () {
  return {
    fontSize: 'f1'
  };
}).withConfig({
  displayName: "Label",
  componentId: "sc-1rknd2d-2"
})(["color:", ";cursor:pointer;font-size:", ";font-family:", ";font-weight:", ";display:flex;align-items:center;-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;margin-left:34px;margin-top:14px;margin-bottom:14px;z-index:-1;"], function (_ref) {
  var _theme$defaultTextCol;

  var theme = _ref.theme;
  return (0, _branding.getPaletteColor)((_theme$defaultTextCol = theme.defaultTextColor) !== null && _theme$defaultTextCol !== void 0 ? _theme$defaultTextCol : 'greyscale-black');
}, _typography.getFontSize, _typography.getFontFamily, _typography.getFontWeight);

var Wrapper = _styledComponents["default"].div.withConfig({
  displayName: "Wrapper",
  componentId: "sc-1rknd2d-3"
})(["transform:scale(1);&&&{", ";}", ";"], _spacing.getSpacingRules, _stackee.getStackeeRules);

var InvisibleInput = _styledComponents["default"].input.withConfig({
  displayName: "InvisibleInput",
  componentId: "sc-1rknd2d-4"
})(["height:0;width:0;margin:0;padding:0;opacity:0;"]);

var CheckboxStandalone = function CheckboxStandalone(_ref2) {
  var selected = _ref2.selected,
      onClick = _ref2.onClick,
      required = _ref2.required,
      label = _ref2.label,
      _ref2$disabled = _ref2.disabled,
      disabled = _ref2$disabled === void 0 ? false : _ref2$disabled,
      spacing = _ref2.spacing,
      onBlur = _ref2.onBlur,
      onFocus = _ref2.onFocus,
      className = _ref2.className,
      dataQa = _ref2['data-qa'],
      dataCy = _ref2['data-cy'],
      id = _ref2.id,
      name = _ref2.name,
      props = _objectWithoutProperties(_ref2, ["selected", "onClick", "required", "label", "disabled", "spacing", "onBlur", "onFocus", "className", "data-qa", "data-cy", "id", "name"]);

  var randomIdentifier = (0, _react.useMemo)(function () {
    return (0, _uuid.v4)();
  }, []);
  return /*#__PURE__*/_react["default"].createElement(Wrapper, _extends({
    spacing: spacing
  }, props, {
    className: className,
    "data-cy": dataCy,
    "data-qa": dataQa,
    id: id
  }), /*#__PURE__*/_react["default"].createElement(ClickableBox, {
    stacked: "row",
    align: "center",
    selected: selected,
    onClick: disabled ? undefined : onClick,
    onFocus: onFocus,
    onBlur: onBlur
  }, /*#__PURE__*/_react["default"].createElement(InvisibleInput, {
    id: randomIdentifier,
    name: name,
    type: "checkbox",
    checked: selected,
    required: required,
    readOnly: true,
    disabled: disabled
  }), /*#__PURE__*/_react["default"].createElement(Label, {
    htmlFor: randomIdentifier
  }, label), /*#__PURE__*/_react["default"].createElement(CheckboxContainer, null, /*#__PURE__*/_react["default"].createElement(_checkbox.Checkbox, {
    selected: selected
  }))));
};

exports.CheckboxStandalone = CheckboxStandalone;
CheckboxStandalone.displayName = 'CheckboxStandalone';