<template>
    <view>
        <button
            :id="id"
            :data-detail="dataset"
            :class="
                'custom-class ' +
                utils.bem('button', [type, size, { block, round, plain, square, loading, disabled, hairline, unclickable: disabled || loading }]) +
                ' ' +
                (hairline ? 'van-hairline--surround' : '')
            "
            hover-class="van-button--active hover-class"
            :lang="lang"
            :form-type="formType"
            :style="baseStyle + ' ' + customStyle"
            :open-type="disabled ? '' : openType"
            :business-id="businessId"
            :session-from="sessionFrom"
            :send-message-title="sendMessageTitle"
            :send-message-path="sendMessagePath"
            :send-message-img="sendMessageImg"
            :show-message-card="showMessageCard"
            :app-parameter="appParameter"
            :aria-label="ariaLabel"
            @tap="parseEventDynamicCode($event, !disabled ? 'onClick' : 'noop')"
            @getuserinfo="bindGetUserInfo"
            @contact="bindContact"
            @getphonenumber="bindGetPhoneNumber"
            @error="bindError"
            @launchapp="bindLaunchApp"
            @opensetting="bindOpenSetting"
        >
            <block v-if="loading">
                <van-loading custom-class="loading-class" :size="loadingSize" :type="loadingType" :color="loadingColor(type, color, plain)" />
                <view v-if="loadingText" class="van-button__loading-text">
                    {{ loadingText }}
                </view>
            </block>
            <block v-else>
                <van-icon v-if="icon" size="1.2em" :name="icon" :class-prefix="classPrefix" class="van-button__icon" custom-style="line-height: inherit;" />
                <view class="van-button__text">
                    <slot />
                </view>
            </block>
        </button>
    </view>
</template>
<script module="utils" lang="wxs" src="@/miniprogram_npm/@vant/weapp/wxs/utils.wxs"></script>
<script module="loadingColor" lang="wxs">
function get(type, color,plain) {
  if(plain) {
    return color ? color: '#c9c9c9';
  }

  if(type === 'default') {
    return '#c9c9c9';
  }
  return 'white';
}

module.exports = get;
</script>
<script>
'use strict';
Object.defineProperty(exports, '__esModule', {
    value: true
});
var component_1 = require('../common/component');
var button_1 = require('../mixins/button');
var open_type_1 = require('../mixins/open-type');
var version_1 = require('../common/version');
var mixins = [button_1.button, open_type_1.openType];
if (version_1.canIUseFormFieldButton()) {
    mixins.push('wx://form-field-button');
}
component_1.VantComponent({
    mixins: mixins,
    classes: ['hover-class', 'loading-class'],
    data: {
        baseStyle: ''
    },
    props: {
        formType: String,
        icon: String,
        classPrefix: {
            type: String,
            value: 'van-icon'
        },
        plain: Boolean,
        block: Boolean,
        round: Boolean,
        square: Boolean,
        loading: Boolean,
        hairline: Boolean,
        disabled: Boolean,
        loadingText: String,
        customStyle: String,
        loadingType: {
            type: String,
            value: 'circular'
        },
        type: {
            type: String,
            value: 'default'
        },
        dataset: null,
        size: {
            type: String,
            value: 'normal'
        },
        loadingSize: {
            type: String,
            value: '20px'
        },
        color: {
            type: String,
            observer: function (color) {
                var style = '';
                if (color) {
                    style += 'color: ' + (this.plain ? color : 'white') + ';';
                    if (!this.plain) {
                        // Use background instead of backgroundColor to make linear-gradient work
                        style += 'background: ' + color + ';';
                    }
                    // hide border when color is linear-gradient
                    if (color.indexOf('gradient') !== -1) {
                        style += 'border: 0;';
                    } else {
                        style += 'border-color: ' + color + ';';
                    }
                }
                if (style !== this.baseStyle) {
                    this.setData({
                        baseStyle: style
                    });
                }
            }
        }
    },
    methods: {
        onClick: function () {
            if (!this.loading) {
                this.$emit('click');
            }
        },
        noop: function () {}
    }
});
</script>
<style>
@import './index.css';
</style>
