<template>
  <div class="status-item status-button" @click="show">
    <i-lucide-wifi class="status-icon" />
    <span class="status-label">网络通讯状态:</span>
    <span class="status-value success">{{ networkStatus }}</span>
  </div>

  <a-modal v-model:open="dialogVisible" :title="modalTitle" :footer="null">
    <a-row :gutter="[0, 12]">
      <template v-for="(item, index) in modalItems" :key="index">
        <a-col :span="8" class="modal-label">{{ item.label }}</a-col>
        <a-col :span="16" class="modal-value">{{ item.value }}</a-col>
      </template>
    </a-row>
  </a-modal>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { useDialog } from '@/utils/useDialog';

// Props
const props = defineProps({
  networkStatus: {
    type: String,
    default: '正常'
  },
  developingData: {
    type: String,
    default: '待赋值'
  }
});

// useDialog管理弹窗状态
const { visible: dialogVisible, show, hide } = useDialog();

// Modal配置数据
const networkStatus = ref(props.networkStatus);
const modalTitle = ref('网络通讯状态');
const modalItems = ref([
  { label: '网络状态', value: networkStatus.value },
  { label: 'IP地址', value: '192.168.1.100' },
  { label: '子网掩码', value: '255.255.255.0' },
  { label: '网关', value: '192.168.1.1' },
  { label: 'DNS服务器', value: '8.8.8.8' },
  { label: '开发数据', value: props.developingData }
]);

// 暴露方法
defineExpose({
  show,
  hide
});
</script>

<style scoped lang="scss">
@use "@/assets/styles/variables" as *;

.status-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  transition: all 0.2s ease;
  
  &.status-button {
    cursor: pointer;
    
    &:hover {
      background-color: rgba(255, 255, 255, 0.1);
    }
  }
  
  .status-icon {
    width: 16px;
    height: 16px;
    color: #8395B6;
    
    &.success {
      color: $success-color;
    }
    
    &.error {
      color: $error-color;
    }
    
    &.warning {
      color: $warning-color;
    }
  }
  
  .status-label {
    font-size: 13px;
    color: #8395B6;
    white-space: nowrap;
  }
  
  .status-value {
    font-size: 13px;
    font-weight: 500;
    
    &.success {
      color: $success-color;
    }
    
    &.error {
      color: $error-color;
    }
    
    &.warning {
      color: $warning-color;
    }
  }
}

.modal-label {
  font-size: $text-size;
  font-weight: bold;
}
</style>