import { PropType, defineComponent, reactive } from 'vue';
import styles from './index.module.less';
import { InputProps, NButton, NIcon, NImage, NInput } from 'naive-ui';
import icon_search from '/src/common/images/icon_search.svg';
import icon_searchActive from '/src/common/images/icon_searchActive.svg';

export default defineComponent({
  name: 'TheSearch',
  props: {
    /** 圆角 */
    round: {
      type: Boolean as PropType<InputProps['round']>,
      default: false
    }
  },
  emits: ['search'],
  setup(props, { emit }) {
    const searchData = reactive({
      value: ''
    });
    return () => (
      <NInput
        class={styles.TheSearch}
        round={props.round}
        placeholder="请输入搜索关键词"
        v-model={searchData.value}>
        {{
          prefix: () => (
            <>
              <img class={styles.default} src={icon_search} />
              <img class={styles.active} src={icon_searchActive} />
            </>
          ),
          suffix: () => (
            <NButton
              size="small"
              round
              type="primary"
              onClick={() => emit('search', searchData.value)}>
              搜索
            </NButton>
          )
        }}
      </NInput>
    );
  }
});
