<template>
  <section class="pane glass card">
    <h2>Comandos</h2>
    <textarea v-model="text" rows="6" placeholder="Escribe el texto a imprimir..." />

    <div class="controls">
      <label>
        Align
        <select v-model="align">
          <option value="">(sin cambio)</option>
          <option value="left">left</option>
          <option value="center">center</option>
          <option value="right">right</option>
        </select>
      </label>
      <label>
        Font
        <select v-model="font">
          <option value="">(sin cambio)</option>
          <option value="font_a">A</option>
          <option value="font_b">B</option>
          <option value="font_c">C</option>
          <option value="font_d">D</option>
          <option value="font_e">E</option>
          <option value="special_a">Special A</option>
          <option value="special_b">Special B</option>
        </select>
      </label>
      <label>Width <input type="number" min="1" max="8" v-model.number="w" /></label>
      <label>Height <input type="number" min="1" max="8" v-model.number="h" /></label>
      <label><input type="checkbox" v-model="bold" /> Bold</label>
      <label><input type="checkbox" v-model="underline" /> Underline</label>
      <label><input type="checkbox" v-model="reverse" /> Reverse</label>
      <label>Smooth <input type="checkbox" v-model="smooth" /></label>
      <label>
        Color
        <select v-model="color">
          <option value="">(default)</option>
          <option value="color_1">1</option>
          <option value="color_2">2</option>
          <option value="color_3">3</option>
          <option value="color_4">4</option>
        </select>
      </label>
      <label>Feed lines <input type="number" min="0" max="255" v-model.number="feedLines" /></label>
      <label>
        Cut
        <select v-model="cut">
          <option value="">(no)</option>
          <option value="no_feed">no_feed</option>
          <option value="feed">feed</option>
          <option value="reserve">reserve</option>
          <option value="no_feed_fullcut">no_feed_fullcut</option>
          <option value="feed_fullcut">feed_fullcut</option>
          <option value="reserve_fullcut">reserve_fullcut</option>
        </select>
      </label>
    </div>

    <div class="actions">
      <button class="btn" @click="queueText">Agregar a cola</button>
      <button class="btn ghost" @click="resetAll">Limpiar</button>
    </div>

    <h3>Atajos</h3>
    <div class="chips">
      <button class="chip" @click="emitOps([{ op: 'feedLine', line: 2 }])">Feed 2</button>
      <button class="chip" @click="emitOps([{ op: 'cut', type: 'feed' }])">Cortar</button>
      <button class="chip" @click="emitOps([{ op: 'pulse', drawer: 'drawer_1', time: 'pulse_200' }])">Pulse</button>
      <button class="chip" @click="emitOps([{ op: 'qrcode', data: 'https://example.com', model: 'qrcode_model_2', level: 'level_m', size: 6 }])">QR</button>
      <button class="chip" @click="emitOps([{ op: 'barcode', data: '490123456789', type: 'ean13', hri: 'below', width: 3, height: 80 }])">Barcode</button>
    </div>
  </section>
</template>

<script setup>
import { ref } from 'vue';

defineProps({ adding: { type: Boolean, default: false } });
const emit = defineEmits(['add-ops']);

const text = ref('');
const align = ref('');
const font = ref('');
const w = ref();
const h = ref();
const bold = ref(false);
const underline = ref(false);
const reverse = ref(false);
const smooth = ref(false);
const color = ref('');
const feedLines = ref();
const cut = ref('');

function resetAll() {
  text.value = '';
  align.value = '';
  font.value = '';
  w.value = undefined; h.value = undefined;
  bold.value = underline.value = reverse.value = false;
  smooth.value = false; color.value = '';
  feedLines.value = undefined; cut.value = '';
}

function queueText() {
  const ops = [];
  if (align.value) ops.push({ op: 'textAlign', align: align.value });
  if (font.value) ops.push({ op: 'textFont', font: font.value });
  if (w.value || h.value) ops.push({ op: 'textSize', width: w.value, height: h.value });
  ops.push({ op: 'textStyle', em: bold.value, ul: underline.value, reverse: reverse.value, ...(color.value ? { color: color.value } : {}) });
  if (text.value) ops.push({ op: 'text', value: text.value });
  if (feedLines.value != null && feedLines.value !== '') ops.push({ op: 'feedLine', line: Number(feedLines.value) });
  if (cut.value) ops.push({ op: 'cut', type: cut.value });
  emit('add-ops', ops);
}

function emitOps(ops) { emit('add-ops', ops); }
</script>

<style scoped>
.pane { grid-area: main; }
.glass { background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border: 1px solid var(--border); border-radius: 14px; }
.card { padding: 16px; box-shadow: 0 8px 24px rgba(0,0,0,0.24), inset 0 1px 0 rgba(255,255,255,0.05); }
h2 { margin: 0 0 12px; font-size: 16px; font-weight: 600; color: var(--accent); }
h3 { margin: 16px 0 8px; font-size: 14px; color: var(--muted); }
textarea { width: 100%; color: var(--fg); background: rgba(255,255,255,0.04); border: 1px solid var(--border); border-radius: 10px; padding: 10px; resize: vertical; }
select, input[type="number"] { color: var(--fg); background: rgba(255,255,255,0.04); border: 1px solid var(--border); border-radius: 10px; padding: 6px 8px; }
label { display: inline-flex; gap: 8px; align-items: center; margin: 6px 10px 6px 0; color: var(--muted); }
.controls { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.actions { margin-top: 12px; display: flex; gap: 8px; }
.btn { appearance: none; border: 1px solid var(--border); background: rgba(255,255,255,0.08); color: var(--fg); border-radius: 10px; padding: 8px 12px; cursor: pointer; transition: 150ms ease; }
.btn:hover { background: rgba(255,255,255,0.12); }
.btn.ghost { background: transparent; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip { border: 1px dashed var(--border); background: rgba(255,255,255,0.04); color: var(--fg); border-radius: 999px; padding: 6px 10px; cursor: pointer; }
</style>

