{"version":3,"file":"option-group.mjs","sources":["../../../../../../packages/components/select/src/option-group.vue"],"sourcesContent":["<template>\r\n  <ul v-show=\"visible\" class=\"sg-select-group__wrap\">\r\n    <li class=\"sg-select-group__title\">{{ label }}</li>\r\n    <li>\r\n      <ul class=\"sg-select-group\">\r\n        <slot></slot>\r\n      </ul>\r\n    </li>\r\n  </ul>\r\n</template>\r\n\r\n<script lang=\"ts\">\r\nimport {\r\n  defineComponent,\r\n  provide,\r\n  inject,\r\n  ref,\r\n  reactive,\r\n  toRefs,\r\n  getCurrentInstance,\r\n  onMounted,\r\n  watch,\r\n  toRaw,\r\n} from 'vue'\r\nimport { SelectGroupContextKey, SelectContextKey, SelectContext } from './token'\r\n\r\nexport default defineComponent({\r\n  name: 'SgOptionGroup',\r\n  componentName: 'SgOptionGroup',\r\n\r\n  props: {\r\n    label: String,\r\n    disabled: {\r\n      type: Boolean,\r\n      default: false,\r\n    },\r\n  },\r\n  setup(props) {\r\n    const visible = ref(true)\r\n    const instance = getCurrentInstance()\r\n    const children = ref([])\r\n\r\n    provide(\r\n      SelectGroupContextKey,\r\n      reactive({\r\n        ...toRefs(props),\r\n      })\r\n    )\r\n\r\n    const select = inject(SelectContextKey)\r\n\r\n    onMounted(() => {\r\n      instance ? children.value = flattedChildren(instance.subTree) : ''\r\n    })\r\n\r\n    // get all instances of options\r\n    const flattedChildren = (node) => {\r\n      const children = []\r\n      if (Array.isArray(node.children)) {\r\n        node.children.forEach((child) => {\r\n          if (\r\n            child.type &&\r\n            child.type.name === 'SgOption' &&\r\n            child.component &&\r\n            child.component.proxy\r\n          ) {\r\n            children.push(child.component.proxy as never)\r\n          } else if (child.children?.length) {\r\n            children.push(...flattedChildren(child))\r\n          }\r\n        })\r\n      }\r\n      return children\r\n    }\r\n\r\n    const { groupQueryChange } = toRaw(select as SelectContext)\r\n    watch(groupQueryChange, () => {\r\n      visible.value = children.value.some((option) => option['visible'] === true)\r\n    })\r\n\r\n    return {\r\n      visible,\r\n    }\r\n  },\r\n})\r\n</script>\r\n"],"names":["_withDirectives","_openBlock","_createElementBlock","_createElementVNode","_toDisplayString"],"mappings":";;;;AAIU,MAAA,UAAA,GAAA,EAAA,KAAA,EAAM,uBAAiB,EAAA,CAAA;;;SAF7B,WAAmD,CAAA,IAAA,EAAA,MAAA,EAAnD,QAAmD,MAAb,EAAA,KAAA,EAAA,QAAA,EAAA;SACtCA,cAIK,EAAAC,SAAA,EAAA,EAAAC,kBAAA,CAAA,IAAA,EAAA,UAAA,EAAA;AAAA,IAAAC,kBAAA,CAHH,IAEK,EAAA,UAAA,EAAAC,eAAA,CAAA,IAAA,CAAA,KAAA,CAAA,EAAA,CAAA,CAAA;AAAA,IADUD,kBAAA,CAAA,IAAA,EAAA,IAAA,EAAA;AAAA,MAAAA,kBAAA,CAAA,IAAA,EAAA,UAAA,EAAA;;;;;;;;;;;;"}