<commit_before><template>
    <button v-bind="conditionalLinkProps"
            :is="componentType"
            :class="classList"
            :data-toggle="isToggle ? 'button' : null"
            :aria-pressed="ariaPressed"
            :type="btnType"
            :disabled="disabled"
            :tabindex="(disabled && componentType !== 'button') ? '-1' : null"
            @click="onClick">
        <slot></slot>
    </button>
</template>

<script>
import bLink from './link.vue';
import { omitLinkProps, props as originalLinkProps, computed } from '../mixins/link';
import { assign } from '../utils/object';

// focus handler for data-toggle="button"
function handleToggleFocus(evt) {
    const el = evt.target;
    if (el && el.classList.contains('btn') && el.getAttribute('data-toggle') === 'button') {
        if (evt.type === 'focusin') {
            el.classList.add('focus');
        } else if (evt.type === 'focusout') {
            el.classList.remove('focus');
        }
    }
}

// Add our data-toggle="button" focus handler
if (typeof document !== 'undefined') {
    document.addEventListener('focusin', handleToggleFocus, false);
    document.addEventListener('focusout', handleToggleFocus, false);
}

// Grab a fresh object of link props (omitLinkProps does this)
// less the 'href' and 'to' props
// that we will reconstruct without any defaults
// so our computed 'componentType' functions properly
const linkProps = assign(omitLinkProps('href', 'to'), {
    href: { type: originalLinkProps.href.type },
    to: { type: originalLinkProps.to.type }
});

export default {
    components: { bLink },
    computed: {
        linkProps: computed.linkProps,
        classList() {
            return [
                'btn',
                this.btnVariant,
                this.btnSize,
                this.btnBlock,
                this.btnDisabled,
                this.btnPressed
            ];
        },
        componentType() {
            return (this.href || this.to) ? 'b-link' : 'button';
        },
        btnBlock() {
            return this.block ? `btn-block` : '';
        },
        btnVariant() {
            return this.variant ? `btn-${this.variant}` : `btn-secondary`;
        },
        btnSize() {
            return this.size ? `btn-${this.size}` : '';
        },
        btnDisabled() {
            return this.disabled ? 'disabled' : '';
        },
        btnType() {
            return (this.href || this.to) ? null : this.type;
        },
        isToggle() {
            return this.pressed === true || this.pressed === false;
        },
        btnPressed() {
            return this.pressed ? 'active' : '';
        },
        ariaPressed() {
            if (this.isToggle) {
                // Add aria-pressed state
                return this.pressed ? 'true' : 'false';
            }
            // Remove aria-pressed attribute
            return null;
        },
        conditionalLinkProps() {
            return this.componentType === 'button' ? {} : this.linkProps;
        }
    },<commit_msg>fix(button): Minor code update<commit_after><template>
    <button v-bind="conditionalLinkProps"
            :is="componentType"
            :class="classList"
            :data-toggle="isToggle ? 'button' : null"
            :aria-pressed="ariaPressed"
            :type="btnType"
            :disabled="disabled"
            :tabindex="(disabled && componentType !== 'button') ? '-1' : null"
            @click="onClick">
        <slot></slot>
    </button>
</template>

<script>
import bLink from './link.vue';
import { omitLinkProps, props as originalLinkProps, computed } from '../mixins/link';
import { assign } from '../utils/object';

// focus handler for data-toggle="button"
function handleToggleFocus(evt) {
    const el = evt.target;
    if (el && el.classList.contains('btn') && el.getAttribute('data-toggle') === 'button') {
        if (evt.type === 'focusin') {
            el.classList.add('focus');
        } else if (evt.type === 'focusout') {
            el.classList.remove('focus');
        }
    }
}

// Add our data-toggle="button" focus handler
if (typeof document !== 'undefined') {
    document.addEventListener('focusin', handleToggleFocus, false);
    document.addEventListener('focusout', handleToggleFocus, false);
}

// Grab a fresh object of link props (omitLinkProps does this)
// less the 'href' and 'to' props
// that we will reconstruct without any defaults
// so our computed 'componentType' functions properly
const linkProps = assign(omitLinkProps('href', 'to'), {
    href: { type: originalLinkProps.href.type },
    to: { type: originalLinkProps.to.type }
});

export default {
    components: { bLink },
    computed: {
        linkProps: computed.linkProps,
        classList() {
            return [
                'btn',
                this.btnVariant,
                this.btnSize,
                this.btnBlock,
                this.btnDisabled,
                this.btnPressed
            ];
        },
        componentType() {
            return (this.href || this.to) ? 'b-link' : 'button';
        },
        btnBlock() {
            return this.block ? 'btn-block' : '';
        },
        btnVariant() {
            return this.variant ? `btn-${this.variant}` : `btn-secondary`;
        },
        btnSize() {
            return this.size ? `btn-${this.size}` : '';
        },
        btnDisabled() {
            return this.disabled ? 'disabled' : '';
        },
        btnType() {
            return (this.href || this.to) ? null : this.type;
        },
        isToggle() {
            return this.pressed === true || this.pressed === false;
        },
        btnPressed() {
            return this.pressed ? 'active' : '';
        },
        ariaPressed() {
            if (this.isToggle) {
                // Add aria-pressed state
                return this.pressed ? 'true' : 'false';
            }
            // Remove aria-pressed attribute
            return null;
        },
        conditionalLinkProps() {
            return this.componentType === 'button' ? {} : this.linkProps;
        }
    },
{'fraction_non_alphanumeric': 0.14687142623754287, 'fraction_numerical': 0.00032674399607907203, 'mean_word_length': 1.8554104477611941, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5254156', 'n_tokens_mistral': 1675, 'n_tokens_neox': 1670, 'n_words': 379}