<wxs src="../wxs/utils.wxs" module="utils" />
<wxs src="./index.wxs" module="computed" />

<block wx:if="{{stopClickPropagation}}">
  <view
    role="switch"
    aria-checked="{{ checked === activeValue ? 'true' : 'false' }}"
    aria-disabled="{{ disabled ? 'true' : 'false' }}"
    class="{{ utils.bem('switch', { on: checked === activeValue, disabled, label: activeText || inactiveText }) }} custom-class"
    style="{{ computed.rootStyle({ size, checked, activeColor, inactiveColor, activeValue }) }}"
    catch:tap="onClick"
  >
    <view class="smart-switch__center">
      <view wx:if="{{ activeText }}" style="opacity: {{checked ? '1' : '0'}}" class="smart-switch__label_active">
        <text class="smart-switch__label_text">{{ activeText }}</text>
      </view>
      <view wx:if="{{ inactiveText }}" style="opacity: {{!checked ? '1' : '0'}}" class="smart-switch__label_inactive">
        <text class="smart-switch__label_text">{{ inactiveText }}</text>
      </view>
      <view class="smart-switch__node node-class">
        <smart-loading
          wx:if="{{ loading }}"
          color="{{ computed.loadingColor({ checked, activeColor, inactiveColor, activeValue }) }}"
          custom-class="smart-switch__loading"
        />
      </view>
    </view>
  </view>
</block>
<block wx:else>
  <view
    role="switch"
    aria-checked="{{ checked === activeValue ? 'true' : 'false' }}"
    aria-disabled="{{ disabled ? 'true' : 'false' }}"
    class="{{ utils.bem('switch', { on: checked === activeValue, disabled, label: activeText || inactiveText }) }} custom-class"
    style="{{ computed.rootStyle({ size, checked, activeColor, inactiveColor, activeValue }) }}"
    bind:tap="onClick"
  >
    <view class="smart-switch__center">
      <view wx:if="{{ activeText }}" style="opacity: {{checked ? '1' : '0'}}" class="smart-switch__label_active">
        <text class="smart-switch__label_text">{{ activeText }}</text>
      </view>
      <view wx:if="{{ inactiveText }}" style="opacity: {{!checked ? '1' : '0'}}" class="smart-switch__label_inactive">
        <text class="smart-switch__label_text">{{ inactiveText }}</text>
      </view>
      <view class="smart-switch__node node-class">
        <smart-loading
          wx:if="{{ loading }}"
          color="{{ computed.loadingColor({ checked, activeColor, inactiveColor, activeValue }) }}"
          custom-class="smart-switch__loading"
          size="{{size}}"
        />
      </view>
    </view>
  </view>
</block>

