<template>
  <!-- Status Item -->
  <div class="status-item status-button" @click="show">
    <i-lucide-zap class="status-icon" />
    <span class="status-label">PLC 通讯状态:</span>
    <span class="status-value success">{{ plcStatus }}</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';

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

const plcStatus = ref('正常');
const modalTitle = ref('PLC 通讯状态');
const modalItems = ref([
  { label: 'PLC状态', value: plcStatus.value },
  { label: 'PLC型号', value: 'Siemens S7-1200' },
  { label: 'IP地址', value: '192.168.1.10' },
  { label: '通讯协议', value: 'Modbus TCP' },
  { label: '连接时间', value: '2024-01-15 08:30:00' },
  { label: '开发数据', value: '' }
]);

// 暴露方法
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>