<template>
  <div v-if="selectbox?.hasContent" class="control-item" :style="{ color: textColor }">
    <div>
      <h1>Selected: {{ selectbox.value }}</h1>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue';
import { useBackgroundElementDesign, useSelectboxElementContent } from '@lightspeed/crane';
import { Content, Design } from '../../type.ts';
import { isDark } from '../../../../shared/utils.ts';

const selectbox = useSelectboxElementContent<Content>('selectbox');
const backgroundDesign = useBackgroundElementDesign<Design>('background');

const backgroundColor = computed(() => {
  const currentColor = backgroundDesign.background?.type === 'solid' ? backgroundDesign.background?.solid?.color?.hex
    : backgroundDesign.background?.gradient?.fromColor?.hex;
  return currentColor || '#ffffff';
});

const textColor = computed(() => (isDark(backgroundColor.value) ? 'white' : 'black'));
</script>

<style lang="scss" scoped>
.control-item {
  margin: 20px 0;
  display: flex;
  align-items: center;
  gap: 10px;

  label {
    font-weight: 500;
  }

  select {
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
  }
}
</style>
