<template>
  <div class="demo">
    <h2 class="h2">{{ translate('basic') }}</h2>
    <nut-cell>
      <nut-inputnumber
       v-model="state.val1" />
    </nut-cell>
    <h2 class="h2">{{ translate('step') }}</h2>
    <nut-cell>
      <nut-inputnumber       
      @change="onValueChange" 
      v-model="state.val2" step="5" />
    </nut-cell>
    <h2 class="h2">{{ translate('limit') }}</h2>
    <nut-cell>
      <nut-inputnumber v-model="state.val3" @overlimit="overlimit" min="10" max="20" />
    </nut-cell>
    <h2 class="h2">{{ translate('disable') }}</h2>
    <nut-cell>
      <nut-inputnumber v-model="state.val4" disabled />
    </nut-cell>
    <h2 class="h2">{{ translate('readonly') }}</h2>
    <nut-cell>
      <nut-inputnumber v-model="state.val5" readonly />
    </nut-cell>
    <h2 class="h2">{{ translate('decimal') }}</h2>
    <nut-cell>
      <nut-inputnumber v-model="state.val6" step="0.1" decimal-places="1" readonly />
    </nut-cell>
    <h2 class="h2">{{ translate('asyc') }}</h2>
    <nut-cell>
      <nut-inputnumber :model-value="state.val8" @change="onChange" />
    </nut-cell>
    <h2 class="h2">{{ translate('size') }}</h2>
    <nut-cell>
      <nut-inputnumber v-model="state.val7" button-size="30" input-width="50" />
    </nut-cell>
  </div>
</template>

<script lang="ts">
import { reactive, getCurrentInstance } from 'vue';
import { createComponent } from '../../utils/create';
const { createDemo, translate } = createComponent('inputnumber');
import { useTranslate } from '../../../sites/assets/util/useTranslate';
import {Toast} from '../../nutui.js'
const initTranslate = () =>
  useTranslate({
    'zh-CN': {
      basic: '基本用法',
      step: '步长设置',
      limit: '限制输入范围',
      disable: '禁用操作',
      readonly: '只读禁用输入框',
      decimal: '支持小数',
      asyn: '支持异步修改',
      size: '自定义按钮大小',
      content1: '异步演示 2 秒后更改',
      content2: '超出限制事件触发'
    },
    'en-US': {
      basic: 'Basic Usage',
      step: 'Step size setting',
      limit: 'Limit input range',
      disable: 'Disable operation',
      readonly: 'Read only disable input box',
      decimal: 'Support decimal',
      asyc: 'Support asynchronous modification',
      size: 'Custom button size',
      content1: 'Asynchronous presentation changes in 2 seconds',
      content2: 'Trigger of limit exceeding event'
    }
  });
export default createDemo({
  props: {},
  setup() {
    initTranslate();
    let { proxy } = getCurrentInstance();

    const state = reactive({
      val1: 1,
      val2: 0,
      val3: 10,
      val4: 0,
      val5: 1,
      val6: 5.5,
      val7: 1,
      val8: 1,
      step: 1.1
    });

    const onChange = (value: number) => {
      Toast.loading(translate('content1'));
      setTimeout(() => {
        state.val8 = value;
        Toast.hide();
      }, 2000);
    };
    
    const onValueChange  = (value) => {
        console.log(value)
    }

    const overlimit = () => {
      Toast.warn(translate('content2'));
    };

    return {
      state,
      onChange,
      //blur,
      //focus,
      onValueChange,
      overlimit,
      translate
    };
  }
});
</script>

<style lang="scss" scoped></style>
