<template>
  <left-skeleton @save="save" @deleteFunc="deleteFunc">
    <el-form :model="form">
      <el-form-item label="按钮名称">
        <el-input v-model="form.name" placeholder="请输入按钮名称" />
      </el-form-item>
      <el-form-item label="api">
        <el-input v-model="form.api" placeholder="请输入按钮调用api" />
      </el-form-item>
    </el-form>
  </left-skeleton>
</template>

<script setup>
import { defineProps, inject, ref } from 'vue';
import leftSkeleton from '../H5Editor/leftSkeleton.vue';

const saveComponents = inject('saveComponents');
const deleteItemComponents = inject('deleteItemComponents');

const props = defineProps({
  item: Object,
  index: String,
});

const form = ref({
  name: props.item.item.text || '',
  api: props.item.item.api || '',
});

const save = () => {
  const item = JSON.parse(JSON.stringify(props.item.item));
  item.text = form.value.name;
  item.api = form.value.api;
  item.type = 'van-buttom';
  delete item.index
  saveComponents({ item, index: props.index });
};

const deleteFunc = () => {
  /**
   * 1.删除本地
   * 2.删除远程
   */
  deleteItemComponents(props.index);
};
</script>

<style scoped></style>
