import { computed, unref } from 'vue';
import { useRoute } from 'vue-router';

export function useBlindStructureInfo(props) {
  const route = useRoute();

  const info = computed(() => {
    const rawId = unref(props?.blindStructureId) ?? route.query.blindStructureId;
    const rawName = unref(props?.name) ?? route.query.name;

    let parsedId = null;
    if (rawId !== undefined && rawId !== null && rawId !== '') {
      const num = Number(rawId);
      parsedId = isNaN(num) ? null : num;
    }

    return {
      id: parsedId, // number | null
      name: rawName ? String(rawName) : ''
    };
  });

  function getInfo() {
    return unref(info);
  }

  return {
    info: getInfo
  };
}
