<template>
  <row-bar :color="builder.color">
    <color-band :color="builder.color"/>
    <slot/>
    <div class="align-self-center">
      <v-menu>
        <template v-slot:activator="{ props }">
          <v-btn variant="plain" v-bind="props" icon="mdi-dots-vertical"/>
        </template>
        <v-list>
<!--          <v-list-subheader :title="'Limit '+ (priceA?priceA.toPrecision(5):'')"/>-->
          <v-list-item title="Delete" key="withdraw" value="withdraw" prepend-icon="mdi-delete" color="red"
                       @click="deleteMyBuilder"/>
        </v-list>
      </v-menu>
    </div>
  </row-bar>
</template>

<script setup>
import {builderFuncs, deleteBuilder, useChartOrderStore} from "@/orderbuild.js";
import ColorBand from "@/components/chart/ColorBand.vue";
import RowBar from "@/components/chart/RowBar.vue";
import {onBeforeUnmount, onMounted, onUnmounted, onUpdated, watchEffect} from "vue";

const props = defineProps({
  order: Object,
  builder: Object,
  buildTranches: {type: Function},
  adjustShapes: {type: Function, default: null},
  deleteShapes: {type: Function, default: null},
})
const emit = defineEmits(['update:builder'])
const co = useChartOrderStore()


let lastId = props.builder.id
builderFuncs[props.builder.id] = props.buildTranches
onUpdated(()=>{
  if (lastId !== props.builder.id ) {
    delete builderFuncs[lastId]
    builderFuncs[props.builder.id] = props.buildTranches
    lastId = props.builder.id
  }
})
onUnmounted(() => delete builderFuncs[lastId])

if (props.adjustShapes) {
  watchEffect(props.adjustShapes)
  onMounted(props.adjustShapes)
}

if (props.deleteShapes)
  onBeforeUnmount(props.deleteShapes)

function deleteMyBuilder() {
  deleteBuilder(props.order, props.builder);
}


</script>

<style scoped lang="scss">

</style>
