<script>
export default {
    beforeCreate() {
        const id = this.$.uid || Math.floor(Math.random() * 1000);
        this.$__uniqueId = String(id).padStart(4, '0');
    },
    methods: {
        /**
         * Get a unique id derived from vue's unique component identifier (this.$.uid) for use when
         * an id is required for an inputs, labels, etc.
         *
         * @param {string} prefix = null
         * @returns {string}
         *
         * @example
         *      this.uniqueId('label') => 'label-0003'
         */

        uniqueId(prefix = null) {
            prefix = typeof prefix === 'string' ? prefix.trim() + '-' : '';
            return prefix + this.$__uniqueId;
        },
    },
};
</script>
