{"ast":null,"code":"import _slicedToArray from \"@babel/runtime/helpers/slicedToArray\";\nimport { useMemo, useState } from \"react\";\nimport { useControlledState } from \"@react-stately/utils\";\nvar $eaf77ba5e143129c6bb329a6e66020d3$var$instance = Math.round(Math.random() * 10000000000);\nvar $eaf77ba5e143129c6bb329a6e66020d3$var$i = 0;\nexport function useRadioGroupState(props) {\n  var name = useMemo(function () {\n    return props.name || \"radio-group-\" + $eaf77ba5e143129c6bb329a6e66020d3$var$instance + \"-\" + ++$eaf77ba5e143129c6bb329a6e66020d3$var$i;\n  }, [props.name]);\n\n  var _useControlledState = useControlledState(props.value, props.defaultValue, props.onChange),\n      _useControlledState2 = _slicedToArray(_useControlledState, 2),\n      selectedValue = _useControlledState2[0],\n      setSelected = _useControlledState2[1];\n\n  var _useState = useState(null),\n      _useState2 = _slicedToArray(_useState, 2),\n      lastFocusedValue = _useState2[0],\n      setLastFocusedValue = _useState2[1];\n\n  var setSelectedValue = function setSelectedValue(value) {\n    if (!props.isReadOnly) {\n      setSelected(value);\n    }\n  };\n\n  return {\n    name: name,\n    selectedValue: selectedValue,\n    setSelectedValue: setSelectedValue,\n    lastFocusedValue: lastFocusedValue,\n    setLastFocusedValue: setLastFocusedValue\n  };\n}","map":{"version":3,"sources":["packages/@react-stately/radio/src/useRadioGroupState.ts"],"names":["instance","Math","i","name","useMemo","props","useControlledState","useState","setSelectedValue","value","setSelected","selectedValue","lastFocusedValue","setLastFocusedValue"],"mappings":";;;AAqCA,IAAIA,8CAAQ,GAAGC,IAAI,CAAJA,KAAAA,CAAWA,IAAI,CAAJA,MAAAA,KAA1B,WAAeA,CAAf;AACA,IAAIC,uCAAC,GAAL,CAAA;OAMO,SAAA,kBAAA,CAAA,KAAA,EAAsE;AAE3E,MAAIC,IAAI,GAAGC,OAAO,CAAC;AAAA,WAAMC,KAAK,CAALA,IAAAA,IAAAA,iBAAAA,8CAAAA,GAAAA,GAAAA,GAAyC,EAAhD,uCAAC;AAAA,GAAD,EAAuD,CAACA,KAAK,CAA/E,IAAyE,CAAvD,CAAlB;;AAF2E,4BAGxCC,kBAAkB,CAACD,KAAK,CAAN,KAAA,EAAcA,KAAK,CAAnB,YAAA,EAAkCA,KAAK,CAA5F,QAAqD,CAHsB;AAAA;AAAA,MAGvE,aAHuE;AAAA,MAGvE,WAHuE;;AAAA,kBAI7BE,QAAQ,CAAtD,IAAsD,CAJqB;AAAA;AAAA,MAIvE,gBAJuE;AAAA,MAIvE,mBAJuE;;AAM3E,MAAIC,gBAAgB,GAAIC,SAApBD,gBAAoBC,CAAAA,KAAD,EAAW;AAChC,QAAI,CAACJ,KAAK,CAAV,UAAA,EAAuB;AACrBK,MAAAA,WAAW,CAAXA,KAAW,CAAXA;AACD;AAHH,GAAA;;AAMA,SAAO;AACLP,IAAAA,IADK,EACLA,IADK;AAELQ,IAAAA,aAFK,EAELA,aAFK;AAGLH,IAAAA,gBAHK,EAGLA,gBAHK;AAILI,IAAAA,gBAJK,EAILA,gBAJK;AAKLC,IAAAA,mBAAAA,EAAAA;AALK,GAAP;AAOD","sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {RadioGroupProps} from '@react-types/radio';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, useState} from 'react';\n\nexport interface RadioGroupState {\n  /**\n   * The name for the group, used for native form submission.\n   * @deprecated\n   * @private\n   */\n  readonly name: string,\n\n  /** The currently selected value. */\n  readonly selectedValue: string | null,\n\n  /** Sets the selected value. */\n  setSelectedValue(value: string): void,\n\n  /** The value of the last focused radio. */\n  readonly lastFocusedValue: string | null,\n\n  /** Sets the last focused value. */\n  setLastFocusedValue(value: string): void\n}\n\nlet instance = Math.round(Math.random() * 10000000000);\nlet i = 0;\n\n/**\n * Provides state management for a radio group component. Provides a name for the group,\n * and manages selection and focus state.\n */\nexport function useRadioGroupState(props: RadioGroupProps): RadioGroupState  {\n  // Preserved here for backward compatibility. React Aria now generates the name instead of stately.\n  let name = useMemo(() => props.name || `radio-group-${instance}-${++i}`, [props.name]);\n  let [selectedValue, setSelected] = useControlledState(props.value, props.defaultValue, props.onChange);\n  let [lastFocusedValue, setLastFocusedValue] = useState(null);\n\n  let setSelectedValue = (value) => {\n    if (!props.isReadOnly) {\n      setSelected(value);\n    }\n  };\n\n  return {\n    name,\n    selectedValue,\n    setSelectedValue,\n    lastFocusedValue,\n    setLastFocusedValue\n  };\n}\n"]},"metadata":{},"sourceType":"module"}