"use strict";

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

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

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

var _randomstring = _interopRequireDefault(require("randomstring"));

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 _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,
      className = _ref2.className,
      dataQa = _ref2['data-qa'],
      dataCy = _ref2['data-cy'],
      id = _ref2.id,
      stackeeProps = _objectWithoutProperties(_ref2, ["selected", "onClick", "required", "label", "disabled", "spacing", "className", "data-qa", "data-cy", "id"]);

  var randomIdentifier = _randomstring["default"].generate({
    length: 7,
    charset: 'alphabetic'
  });

  return /*#__PURE__*/_react["default"].createElement(Wrapper, _extends({
    spacing: spacing
  }, stackeeProps, {
    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
  }, /*#__PURE__*/_react["default"].createElement(InvisibleInput, {
    id: randomIdentifier,
    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';