<template>
  <view class="ic-input-box" :style="style">
    <text class="ic-title" :style="textStyle">{{ title }}</text>
    <input
      ref="inputRef"
      class="ic-input"
      :value="inputContent"
      placeholder="请输入"
      placeholder-style="color: rgb(136,136,136)"
      @input="handleInput"
    />
  </view>
</template>

<script lang="ts" setup>
import { ref } from 'vue'

interface Props {
  title: string
  type: string
  defaultValue?: string
  style?: any
  textStyle?: any
}

const props = withDefaults(defineProps<Props>(), {
  defaultValue: '',
})

const emit = defineEmits<{
  change: [text: string, type: string]
}>()

const inputContent = ref(props.defaultValue)
const inputRef = ref<any>(null)

// 暴露方法
defineExpose({
  reset: () => {
    inputContent.value = ''
  },
  inputContent: inputContent.value,
})

// 处理输入
const handleInput = (e: any) => {
  const text = e.detail.value
  inputContent.value = text
  emit('change', text, props.type)
}
</script>

<style lang="scss" scoped>
.ic-input-box {
  display: flex;
  flex-direction: row;
  align-items: center;
  flex-wrap: nowrap;
  margin-left: 5px;
  margin-bottom: 10px;
  white-space: nowrap;
}

.ic-title {
  color: rgb(51, 51, 51);
  font-size: 12px;
  text-align: right;
  flex-shrink: 0;
}

.ic-input {
  flex: 1;
  min-width: 0;
  height: 30px;
  border: 1px solid #ccc;
  color: rgba(136, 136, 136, 1);
  font-size: 12px;
  border-radius: 6px;
  padding: 0 5px;
}
</style>
