<template>
  <div class="manual actions-branches-item">
    <FormItem :rules="actionRules" :name="['branches', 0, 'then']">
      <Action :thenOptions="data.branches ? data?.branches[0].then : []" :name="0" />
    </FormItem>
  </div>
</template>

<script lang="ts" setup name="SceneSaveManual">
  import { useSceneStore } from '@jdlinker/func';
  import { storeToRefs } from 'pinia';
  import type { BranchesThen } from '../../typings';
  import Action from '../action/index.vue';
  import { FormItem } from 'linker-ui-components';

  const sceneStore = useSceneStore();
  const { data } = storeToRefs(sceneStore);

  const actionRules = [
    {
      validator(_: any, v?: BranchesThen[]) {
        if (!v || (v && !v.length) || !v.some((item) => item.actions && item.actions.length)) {
          return Promise.reject('至少配置一个执行动作');
        }
        return Promise.resolve();
      }
    }
  ];
</script>

<style scoped lang="less">
  @minWidth: 75%;

  .manual {
    &.actions-branches-item {
      width: 100%;
    }
  }

  @media (min-width: 1600px) {
    .manual {
      &.actions-branches-item {
        width: @minWidth;
      }
    }
  }
</style>
