"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.WithHideLabel = exports.WithDefaultChecked = exports.WithCheckedControlledBehaviour = exports.WithAutoFocus = exports.WithAnErrorIfNotChecked = exports.WithAllActions = exports.RequiredStory = exports.OnAColouredBackground = exports.InAGroupWithTooltipPositionTop = exports.InAGroupWithTooltip = exports.InAGroupWithError = exports.InAGroupWithCustomLabel = exports.InAGroup = exports.DisabledStory = exports.Default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _styledComponents = _interopRequireDefault(require("styled-components"));
var _addonActions = require("@storybook/addon-actions");
var _ = require("../../..");
var _Display = require("../../../common/Display");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
var handlers = (0, _addonActions.actions)('onBlur', 'onClick', 'onFocus', 'onKeyDown', 'onKeyUp', 'onKeyPress', 'onChange');
var StyledRadioLabel = _styledComponents.default.label.withConfig({
  displayName: "Radiostories__StyledRadioLabel",
  componentId: "sc-4carwh-0"
})(["display:flex;justify-content:center;align-items:center;width:52px;height:52px;background-color:", ";&:hover{cursor:pointer;", "}", ""], function (p) {
  return p.theme.color.background;
}, function (p) {
  return !p.checked && "background-color: ".concat(p.theme.color.cta, "; color: white");
}, function (p) {
  return p.checked && "background-color: ".concat(p.theme.color.cta, "; color: white");
});
var _default = exports.default = {
  title: 'Molecules / Input / Radio',
  parameters: {
    component: _.Input.Radio
  }
};
var Default = exports.Default = {
  render: function render() {
    return _react.default.createElement(_.Input.Radio, {
      name: "example",
      value: "green",
      label: "Green"
    });
  }
};
var WithDefaultChecked = exports.WithDefaultChecked = {
  render: function render() {
    return _react.default.createElement(_.Input.Radio, {
      name: "example",
      value: "green",
      label: "Green",
      defaultChecked: true
    });
  },
  name: 'With default checked'
};
var WithCheckedControlledBehaviour = exports.WithCheckedControlledBehaviour = {
  render: function render() {
    var Component = function Component() {
      var _useState = (0, _react.useState)(false),
        _useState2 = _slicedToArray(_useState, 2),
        checked = _useState2[0],
        setChecked = _useState2[1];
      var toggleCheckbox = function toggleCheckbox() {
        return setChecked(!checked);
      };
      return _react.default.createElement(_react.default.Fragment, null, _react.default.createElement(_.Input.Radio, {
        name: "example",
        value: "green",
        label: "Green",
        checked: checked,
        onChange: toggleCheckbox
      }), _react.default.createElement("button", {
        type: "button",
        onClick: toggleCheckbox
      }, "Toggle Checkbox"));
    };
    return _react.default.createElement(Component, null);
  },
  name: 'With checked (Controlled behaviour)'
};
var RequiredStory = exports.RequiredStory = {
  render: function render() {
    return _react.default.createElement(_Display.Display, {
      title: "Required",
      items: [{
        component: _react.default.createElement(_.Input.Radio, {
          name: "example",
          value: "green",
          label: "Green",
          required: true
        }),
        title: 'Default (without star)'
      }, {
        component: _react.default.createElement(_.Input.Radio, {
          name: "example",
          value: "green",
          label: "Green",
          required: true,
          visuallyEmphasiseRequired: true
        }),
        title: 'With star'
      }]
    });
  },
  name: 'Required'
};
var WithAnErrorIfNotChecked = exports.WithAnErrorIfNotChecked = {
  render: function render() {
    var Component = function Component() {
      var _useState3 = (0, _react.useState)(false),
        _useState4 = _slicedToArray(_useState3, 2),
        checked = _useState4[0],
        setChecked = _useState4[1];
      var toggleCheckbox = function toggleCheckbox() {
        return setChecked(!checked);
      };
      return _react.default.createElement(_.Input.Radio, _extends({
        name: "example",
        value: "green",
        label: "Green",
        required: true,
        onChange: toggleCheckbox
      }, !checked ? {
        error: 'This field is required'
      } : {}));
    };
    return _react.default.createElement(Component, null);
  },
  name: 'With an error if not checked'
};
var InAGroup = exports.InAGroup = {
  render: function render() {
    return _react.default.createElement(_.FormField, {
      label: "Colors",
      group: true
    }, _react.default.createElement(_.Flexbox, {
      container: true,
      gap: 5
    }, _react.default.createElement(_.Input.Radio, {
      name: "example",
      value: "green",
      label: "Green"
    }), _react.default.createElement(_.Input.Radio, {
      name: "example",
      value: "blue",
      label: "Blue"
    }), _react.default.createElement(_.Input.Radio, {
      name: "example",
      value: "yellow",
      label: "Yellow"
    })));
  },
  name: 'In a group'
};
var InAGroupWithTooltip = exports.InAGroupWithTooltip = {
  render: function render() {
    return _react.default.createElement(_.FormField, {
      label: "Colors",
      labelTooltip: "Checkbox tooltip",
      group: true
    }, _react.default.createElement(_.Flexbox, {
      container: true,
      gap: 5
    }, _react.default.createElement(_.Input.Radio, {
      name: "example",
      value: "green",
      label: "Green"
    }), _react.default.createElement(_.Input.Radio, {
      name: "example",
      value: "blue",
      label: "Blue"
    }), _react.default.createElement(_.Input.Radio, {
      name: "example",
      value: "yellow",
      label: "Yellow"
    })));
  },
  name: 'In a group with tooltip'
};
var InAGroupWithTooltipPositionTop = exports.InAGroupWithTooltipPositionTop = {
  render: function render() {
    return _react.default.createElement(_react.default.Fragment, null, _react.default.createElement("br", null), _react.default.createElement("br", null), _react.default.createElement(_.FormField, {
      label: "Colors",
      labelTooltip: "Checkbox tooltip",
      labelTooltipPosition: "top",
      group: true
    }, _react.default.createElement(_.Flexbox, {
      container: true,
      gap: 5
    }, _react.default.createElement(_.Input.Radio, {
      name: "example",
      value: "green",
      label: "Green"
    }), _react.default.createElement(_.Input.Radio, {
      name: "example",
      value: "blue",
      label: "Blue"
    }), _react.default.createElement(_.Input.Radio, {
      name: "example",
      value: "yellow",
      label: "Yellow"
    }))));
  },
  name: 'In a group with tooltip (position top)'
};
var InAGroupWithError = exports.InAGroupWithError = {
  render: function render() {
    var Component = function Component() {
      var _useState5 = (0, _react.useState)(false),
        _useState6 = _slicedToArray(_useState5, 2),
        oneChecked = _useState6[0],
        setOneChecked = _useState6[1];
      var _useState7 = (0, _react.useState)(false),
        _useState8 = _slicedToArray(_useState7, 2),
        twoChecked = _useState8[0],
        setTwoChecked = _useState8[1];
      var _useState9 = (0, _react.useState)(false),
        _useState10 = _slicedToArray(_useState9, 2),
        threeChecked = _useState10[0],
        setThreeChecked = _useState10[1];
      var hasGroupError = !oneChecked && !twoChecked && !threeChecked;
      return _react.default.createElement(_.FormField, _extends({
        label: "Colors",
        group: true
      }, hasGroupError ? {
        error: 'This field is required'
      } : {}), _react.default.createElement(_.Flexbox, {
        container: true,
        gap: 5
      }, _react.default.createElement(_.Input.Radio, {
        name: "example",
        value: "green",
        label: "Green",
        hasError: hasGroupError,
        onChange: function onChange() {
          return setOneChecked(!oneChecked);
        },
        required: true
      }), _react.default.createElement(_.Input.Radio, {
        name: "example",
        value: "blue",
        label: "Blue",
        hasError: hasGroupError,
        onChange: function onChange() {
          return setTwoChecked(!twoChecked);
        },
        required: true
      }), _react.default.createElement(_.Input.Radio, {
        name: "example",
        value: "yellow",
        label: "Yellow",
        hasError: hasGroupError,
        onChange: function onChange() {
          return setThreeChecked(!threeChecked);
        },
        required: true
      })));
    };
    return _react.default.createElement(Component, null);
  },
  name: 'In a group with error'
};
var DisabledStory = exports.DisabledStory = {
  render: function render() {
    return _react.default.createElement(_Display.Display, {
      title: "Disabled",
      items: [{
        component: _react.default.createElement(_.Input.Radio, {
          name: "example",
          value: "green",
          label: "Green",
          defaultChecked: true,
          disabled: true
        }),
        title: 'Checked'
      }, {
        component: _react.default.createElement(_.Input.Radio, {
          name: "example",
          value: "blue",
          label: "Blue",
          disabled: true
        }),
        title: 'Not Checked'
      }]
    });
  },
  name: 'Disabled'
};
var WithAutoFocus = exports.WithAutoFocus = {
  render: function render() {
    return _react.default.createElement(_.Input.Radio, {
      name: "example",
      value: "green",
      label: "Green",
      autoFocus: true
    });
  },
  name: 'With auto focus'
};
var WithAllActions = exports.WithAllActions = {
  render: function render() {
    return _react.default.createElement(_.Input.Radio, _extends({
      name: "example6",
      value: "green",
      label: "Green"
    }, handlers));
  },
  name: 'With all actions'
};
var OnAColouredBackground = exports.OnAColouredBackground = {
  render: function render() {
    return _react.default.createElement(_.Box, {
      p: 5,
      backgroundColor: function backgroundColor(t) {
        return t.color.disabledBackground;
      }
    }, _react.default.createElement(_.Input.Radio, {
      name: "background",
      value: "background",
      label: "On a colored background"
    }));
  },
  name: 'On a coloured background'
};
var InAGroupWithCustomLabel = exports.InAGroupWithCustomLabel = {
  render: function render() {
    return _react.default.createElement(_.FormField, {
      label: "Colors",
      labelTooltip: "Checkbox tooltip",
      group: true
    }, _react.default.createElement(_.Flexbox, {
      container: true,
      gap: 5
    }, _react.default.createElement(_.Input.Radio, {
      id: "Green",
      name: "example",
      value: "green",
      label: "Green",
      noRadioCircle: true
    }, _react.default.createElement(StyledRadioLabel, {
      htmlFor: "Green",
      checked: true
    }, "Green")), _react.default.createElement(_.Input.Radio, {
      id: "Blue",
      name: "example",
      value: "blue",
      label: "Blue",
      noRadioCircle: true
    }, _react.default.createElement(StyledRadioLabel, {
      htmlFor: "Blue",
      checked: false
    }, "Blue")), _react.default.createElement(_.Input.Radio, {
      id: "Yellow",
      name: "example",
      value: "yellow",
      label: "Yellow",
      noRadioCircle: true
    }, _react.default.createElement(StyledRadioLabel, {
      htmlFor: "Yellow",
      checked: false
    }, "Yellow"))));
  },
  name: 'In a group with custom label'
};
var WithHideLabel = exports.WithHideLabel = {
  render: function render() {
    return _react.default.createElement(_.Input.Radio, {
      name: "example",
      value: "green",
      hideLabel: true,
      label: "This label is hidden"
    });
  }
};