import { computed, type ComputedRef } from 'vue';

const useCalTableWidth = (columns: ComputedRef<any[]> | any[]) => {
  const tableWidth = computed(() => {
    const cols = Array.isArray(columns) ? columns : columns.value;
    if (!cols || cols.length === 0) return 0;
    return cols
      .map((item: any) => {
        if (!item.width) return 0;
        return Number(item.width.toString().replace('px', '')) || 0;
      })
      .reduce((a: number, b: number) => a + b, 0);
  });

  return { tableWidth };
};

export default useCalTableWidth;
