<?php
namespace Incoviba\Service\Contabilidad\Informe\Tesoreria\Input\Excel;

use PhpOffice\PhpSpreadsheet;

class DeudaBanco extends Sheet
{
    public function load(PhpSpreadsheet\Spreadsheet $excel): array
    {
        if (!$excel->sheetNameExists('Deuda Banco')) {
            return [];
        }
        $sheet = $excel->getSheetByName('Deuda Banco');
        $data = [];

        $rowIndex = 1;
        $columnOffset = 2;
        while ($sheet->getCell([$columnOffset, $rowIndex])->getValue() !== 'EMPRESA') {
            $rowIndex ++;
        }
        $titleRow = $rowIndex;
        $titles = $this->getTableTitles($sheet, $titleRow, $columnOffset, 13, 'UF', ['(']);
        $rowIndex ++;

        while ($sheet->getCell([$columnOffset, $rowIndex])->getValue() !== 'TOTAL GRUPO EMPRESAS') {
            if ($sheet->getCell([$columnOffset, $rowIndex])->getValue() !== null) {
                $data []= $this->getRow($sheet, $titles, $titleRow, $rowIndex, $columnOffset);
            }
            $rowIndex ++;
        }

        return $data;
    }
}
