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;AA1MM,CAHoB,CAAtB;kBAgNQ,cAAc,MAAd,CAAqB;AAClC,UAAM,cAD4B;AAGlC,WAHkC,qBAG3B;AACL,eAAO;AACL,uBAAW;AADN,SAAP;AAGD;AAPiC,CAArB,C","sourcesContent":["// Styles\nimport '../../stylus/components/_item-group.styl'\n\n// Mixins\nimport Groupable from '../../mixins/groupable'\nimport Proxyable from '../../mixins/proxyable'\nimport Themeable from '../../mixins/themeable'\n\n// Utilities\nimport mixins from '../../util/mixins'\nimport { consoleWarn } from '../../util/console'\n\n// Types\nimport { VNode } from 'vue/types'\n\ntype GroupableInstance = InstanceType & { value?: any }\n\nexport const BaseItemGroup = mixins(\n Proxyable,\n Themeable\n).extend({\n name: 'base-item-group',\n\n props: {\n activeClass: {\n type: String,\n default: 'v-item--active'\n },\n mandatory: Boolean,\n max: {\n type: [Number, String],\n default: null\n },\n multiple: Boolean\n },\n\n data () {\n return {\n // As long as a value is defined, show it\n // Otherwise, check if multiple\n // to determine which default to provide\n internalLazyValue: this.value !== undefined\n ? this.value\n : this.multiple ? [] : undefined,\n items: [] as GroupableInstance[]\n }\n },\n\n computed: {\n classes (): Record {\n return {\n ...this.themeClasses\n }\n },\n selectedItems (): GroupableInstance[] {\n return this.items.filter((item, index) => {\n return this.toggleMethod(this.getValue(item, index))\n })\n },\n selectedValues (): any[] {\n return Array.isArray(this.internalValue)\n ? this.internalValue\n : [this.internalValue]\n },\n toggleMethod (): (v: any) => boolean {\n if (!this.multiple) {\n return (v: any) => this.internalValue === v\n }\n\n const internalValue = this.internalValue\n if (Array.isArray(internalValue)) {\n return (v: any) => internalValue.includes(v)\n }\n\n return () => false\n }\n },\n\n watch: {\n internalValue () {\n // https://github.com/vuetifyjs/vuetify/issues/5352\n this.$nextTick(this.updateItemsState)\n }\n },\n\n created () {\n if (this.multiple && !Array.isArray(this.internalValue)) {\n consoleWarn('Model must be bound to an array if the multiple property is true.', this)\n }\n },\n\n methods: {\n getValue (item: GroupableInstance, i: number): unknown {\n return item.value == null || item.value === ''\n ? i\n : item.value\n },\n onClick (item: GroupableInstance, index: number) {\n this.updateInternalValue(\n this.getValue(item, index)\n )\n },\n register (item: GroupableInstance) {\n const index = this.items.push(item) - 1\n\n item.$on('change', () => this.onClick(item, index))\n\n // If no value provided and mandatory,\n // assign first registered item\n if (this.mandatory && this.internalLazyValue == null) {\n this.updateMandatory()\n }\n\n this.updateItem(item, index)\n },\n unregister (item: GroupableInstance) {\n if (this._isDestroyed) return\n\n const index = this.items.indexOf(item)\n const value = this.getValue(item, index)\n\n this.items.splice(index, 1)\n\n const valueIndex = this.selectedValues.indexOf(value)\n\n // Items is not selected, do nothing\n if (valueIndex < 0) return\n\n // If not mandatory, use regular update process\n if (!this.mandatory) {\n return this.updateInternalValue(value)\n }\n\n // Remove the value\n if (this.multiple && Array.isArray(this.internalValue)) {\n this.internalValue = this.internalValue.filter(v => v !== value)\n } else {\n this.internalValue = undefined\n }\n\n // If mandatory and we have no selection\n // add the last item as value\n /* istanbul ignore else */\n if (!this.selectedItems.length) {\n this.updateMandatory(true)\n }\n },\n updateItem (item: GroupableInstance, index: number) {\n const value = this.getValue(item, index)\n\n item.isActive = this.toggleMethod(value)\n },\n updateItemsState () {\n if (this.mandatory &&\n !this.selectedItems.length\n ) {\n return this.updateMandatory()\n }\n\n // TODO: Make this smarter so it\n // doesn't have to iterate every\n // child in an update\n this.items.forEach(this.updateItem)\n },\n updateInternalValue (value: any) {\n this.multiple\n ? this.updateMultiple(value)\n : this.updateSingle(value)\n },\n updateMandatory (last?: boolean) {\n if (!this.items.length) return\n\n const index = last ? this.items.length - 1 : 0\n\n this.updateInternalValue(\n this.getValue(this.items[index], index)\n )\n },\n updateMultiple (value: any) {\n const defaultValue = Array.isArray(this.internalValue)\n ? this.internalValue\n : []\n const internalValue = defaultValue.slice()\n const index = internalValue.findIndex(val => val === value)\n\n if (\n this.mandatory &&\n // Item already exists\n index > -1 &&\n // value would be reduced below min\n internalValue.length - 1 < 1\n ) return\n\n if (\n // Max is set\n this.max != null &&\n // Item doesn't exist\n index < 0 &&\n // value would be increased above max\n internalValue.length + 1 > this.max\n ) return\n\n index > -1\n ? internalValue.splice(index, 1)\n : internalValue.push(value)\n\n this.internalValue = internalValue\n },\n updateSingle (value: any) {\n const isSame = value === this.internalValue\n\n if (this.mandatory && isSame) return\n\n this.internalValue = isSame ? undefined : value\n }\n },\n\n render (h): VNode {\n return h('div', {\n staticClass: 'v-item-group',\n class: this.classes\n }, this.$slots.default)\n }\n})\n\nexport default BaseItemGroup.extend({\n name: 'v-item-group',\n\n provide (): object {\n return {\n itemGroup: this\n }\n }\n})\n"],"sourceRoot":""}