<template>
  <div class="frame-style-panel">
    <div class="row">
      <div>{{ lang.ssTabWebLink }}：</div>
      <Input v-model:value="url" :placeholder="lang.ssWebUrlPh" />
      <Button @click="updateURL()">{{ lang.ssConfirm }}</Button>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref, watch, computed } from 'vue'
import { storeToRefs } from 'pinia'
import { useMainStore, useSlidesStore } from '@/store'
import useHistorySnapshot from '@/hooks/useHistorySnapshot'
import { lang } from '@/main'
import Input from '@/components/Input.vue'
import Button from '@/components/Button.vue'

const slidesStore = useSlidesStore()
const { handleElement } = storeToRefs(useMainStore())

const { addHistorySnapshot } = useHistorySnapshot()

const url = ref('')

// 监听选中的元素变化，更新链接字段
watch(handleElement, (newElement) => {
  if (newElement && newElement.type === 'frame') {
    url.value = (newElement as any).url || ''
  }
}, { immediate: true })

// 计算当前选中的网页元素
const currentFrameElement = computed(() => {
  if (handleElement.value && handleElement.value.type === 'frame') {
    return handleElement.value as any
  }
  return null
})

const updateURL = () => {
  if (!currentFrameElement.value) return
  slidesStore.updateElement({ id: currentFrameElement.value.id, props: { url: url.value } })
  addHistorySnapshot()
}
</script>

<style lang="scss" scoped>
.frame-style-panel {
  padding: 12px;
  
  .row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    
    > div:first-child {
      min-width: 60px;
      font-size: 12px;
      color: #666;
    }
    
    // 确保按钮不换行
    button {
      white-space: nowrap;
      flex-shrink: 0;
    }
    
    // 输入框自适应宽度
    input {
      flex: 1;
      min-width: 0;
    }
  }
}
</style> 