<template>
  <div>
    <a-input-group compact>
      <a-input
        disabled
        style="width: calc(100% - 32px)"
        v-model:value="content"
        :placeholder="placeholder"
      />
      <a-button @click="openEdit">
        <template #icon><BulbOutlined class="ele-text-warning" /></template>
      </a-button>
    </a-input-group>
    <!-- 选择弹窗 -->
    <SelectData
      v-model:visible="showEdit"
      :title="placeholder"
      @done="onChange"
    />
  </div>
</template>

<script lang="ts" setup>
  import { BulbOutlined } from '@ant-design/icons-vue';
  import { ref, watch } from 'vue';
  import SelectData from './components/select-data.vue';
  import type { ShopStore } from '@/api/shop/shopStore/model';

  const props = withDefaults(
    defineProps<{
      value?: string;
      placeholder?: string;
    }>(),
    {
      placeholder: '选择门店'
    }
  );

  const emit = defineEmits<{
    (e: 'done', data?: ShopStore): void;
    (e: 'clear'): void;
  }>();

  const showEdit = ref(false);
  const content = ref<string>(props.value ?? '');

  const openEdit = () => {
    showEdit.value = true;
  };

  const onChange = (row?: ShopStore) => {
    showEdit.value = false;
    emit('done', row);
  };

  watch(
    () => props.value,
    (v) => {
      content.value = v ?? '';
    }
  );
</script>

