<template>
  <div 
    class="workspace-block" 
    :class="[`block-${type}`, { 'edit-mode': editMode }]"
    :style="{ gridColumn: `span ${span}` }"
  >
    <div class="block-content">
      <slot></slot>
    </div>
    <div v-if="editMode" class="block-actions">
      <button class="action-btn drag-handle" :title="t('Drag')">
        <Icon icon="tabler:grip-vertical" />
      </button>
      <button v-if="editable" class="action-btn" @click="$emit('edit')" :title="t('Edit')">
        <Icon icon="tabler:edit" />
      </button>
      <button class="action-btn" @click="$emit('expand')" :title="t('Expand')">
        <Icon icon="tabler:arrows-maximize" />
      </button>
      <button class="action-btn" @click="$emit('shrink')" :title="t('Shrink')">
        <Icon icon="tabler:arrows-minimize" />
      </button>
      <button class="action-btn delete-btn" @click="$emit('delete')" :title="t('Delete')">
        <Icon icon="tabler:trash" />
      </button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { Icon } from '@iconify/vue'
import { t } from '@/shared/i18n'

defineProps<{
  type: string
  span: number
  editMode: boolean
  editable?: boolean
}>()

defineEmits<{
  edit: []
  expand: []
  shrink: []
  delete: []
}>()
</script>

<style scoped>
.workspace-block {
  position: relative;
  background: #fff;
  border: 1px solid #eef2f7;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(15,23,42,0.04);
  transition: all 0.2s;
}

.workspace-block.edit-mode {
  cursor: move;
  border: 2px dashed transparent;
}

.workspace-block.edit-mode:hover {
  border-color: #18a058;
  box-shadow: 0 4px 12px rgba(24, 160, 88, 0.15);
}

.block-content {
  padding: 16px;
}

.block-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 4px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  opacity: 0;
  transition: opacity 0.2s;
}

.workspace-block.edit-mode:hover .block-actions {
  opacity: 1;
}

.action-btn {
  background: transparent;
  border: none;
  color: #64748b;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  font-size: 16px;
}

.action-btn:hover {
  background: #f1f5f9;
  color: #0f172a;
}

.action-btn.delete-btn:hover {
  background: #fee;
  color: #ef4444;
}

.drag-handle {
  cursor: grab;
}

.drag-handle:active {
  cursor: grabbing;
}
</style>
