<?php
/*
Generated by OutputBooks Team
*/

class AsciiTable
{
    public $data;
    private $columnsList = array();
    private $maxLineLength = 40;
    private $columnsLength = array();
    private $result = array();
    private $charset = "\125\124\x46\55\x38";
    private $renderHeader = true;
    public function __construct()
    {
    }
    public function charset($charset)
    {
        goto j0Hoo;
        Ejs14:
        $this->charset = $charset;
        goto Ec7bn;
        Ec7bn:
        return $this;
        goto ZubzG;
        j0Hoo:
        if (!in_array($charset, mb_list_encodings())) {
            throw new \Exception("\124\x68\151\163\40\x63\x68\141\x72\x73\145\164\x20\140" . $charset . "\x60\40\151\163\x20\x6e\x6f\x74\x20\163\x75\160\x70\x6f\x72\x74\x65\144\40\x62\x79\x20\155\x62\x73\164\x72\151\x6e\147\x2e" . "\x50\154\145\x61\163\145\40\x63\150\x65\143\x6b\x20\x69\x74\72\40\150\x74\164\160\x3a\x2f\57\x70\x68\160\x2e\156\x65\x74\57\x6d\x61\x6e\165\141\x6c\57\x72\x75\x2f\x66\x75\156\143\x74\151\x6f\x6e\56\x6d\142\x2d\154\x69\163\x74\55\x65\x6e\143\x6f\144\x69\x6e\147\x73\x2e\x70\x68\x70");
        }
        goto Ejs14;
        ZubzG:
    }
    public function noHeader()
    {
        $this->renderHeader = false;
        return $this;
    }
    public function maxLineLength($length)
    {
        goto QaodP;
        QaodP:
        if ($length < 3) {
            throw new \Exception("\x4d\151\x6e\151\x6d\x75\155\x20\x6c\145\156\x67\164\150\x20\146\x6f\162\40\143\162\x6f\x70\x70\x65\x72\x20\x69\x73\x20\63\x20\x73\165\x6d\x62\157\x6c\x73");
        }
        goto mCBRq;
        qVh6_:
        return $this;
        goto EeBOT;
        mCBRq:
        $this->maxLineLength = $length;
        goto qVh6_;
        EeBOT:
    }
    public function render($data = array())
    {
        goto L3Rs9;
        HFaJo:
        $this->calcColumnsLength();
        goto MTMP2;
        jFFNn:
        $this->renderBody();
        goto K63pR;
        L3Rs9:
        if (empty($this->data) && empty($data)) {
            return "\105\x6d\x70\164\171";
        }
        goto dIaYP;
        E_m2C:
        $this->calcColumnsList();
        goto HFaJo;
        dB3TK:
        return str_replace(["\53\53", "\174\x7c"], ["\x2b", "\174"], implode(PHP_EOL, $this->result));
        goto Rn0Rp;
        K63pR:
        $this->lineSeparator();
        goto dB3TK;
        MTMP2:
        $this->renderHeader();
        goto jFFNn;
        dIaYP:
        if (empty($this->data) && !empty($data)) {
            $this->data = $data;
        }
        goto E_m2C;
        Rn0Rp:
    }
    protected function calcColumnsList()
    {
        $this->columnsList = array_keys(reset($this->data));
    }
    protected function length($str)
    {
        if (empty($str)) {
            return 0;
        }
        return mb_strlen($str, $this->charset);
    }
    private function calcColumnsLength()
    {
        foreach ($this->data as $row) {
            goto D0ex5;
            EuQOu:
            k6CzV:
            goto W8w3O;
            yQ8h_:
            JEbBV:
            goto EuQOu;
            HerBY:
            foreach ($this->columnsList as $column) {
                $this->columnsLength[$column] = max(isset($this->columnsLength[$column]) ? $this->columnsLength[$column] : 0, $this->length($row[$column]), $this->length($column));
                NW36H:
            }
            goto yQ8h_;
            D0ex5:
            if ($row === "\55\55\55") {
                goto k6CzV;
            }
            goto HerBY;
            W8w3O:
        }
        QH09M:
    }
    private function lineSeparator()
    {
        goto NA6rK;
        Pw9fe:
        $this->result[] = $tmp;
        goto tLa6n;
        NA6rK:
        $tmp = '';
        goto vzAxL;
        vzAxL:
        foreach ($this->columnsList as $column) {
            $tmp .= "\53" . str_repeat("\x2d", $this->columnsLength[$column] + 2) . "\x2b";
            Vejy7:
        }
        goto ie4DZ;
        ie4DZ:
        d3qss:
        goto Pw9fe;
        tLa6n:
    }
    private function column($columnKey, $value)
    {
        if (is_numeric($value)) {
            if ($value == 0) {
                $value = '';
            }
            return "\174\x20" . str_repeat("\40", $this->columnsLength[$columnKey] - $this->length($value)) . $value . "\40" . "\x7c";
        } else {
            return "\x7c\40" . $value . "\40" . str_repeat("\40", $this->columnsLength[$columnKey] - $this->length($value)) . "\174";
        }
    }
    private function renderHeader()
    {
        goto JcW9W;
        yoIFF:
        foreach ($this->columnsList as $column) {
            $tmp .= $this->column($column, $column);
            Km7nZ:
        }
        goto xdcDd;
        ZcaUK:
        $this->lineSeparator();
        goto y5R1I;
        EbSmu:
        $tmp = '';
        goto yoIFF;
        xdcDd:
        fmdN1:
        goto PuMeH;
        JcW9W:
        $this->lineSeparator();
        goto aXvXc;
        PuMeH:
        $this->result[] = $tmp;
        goto ZcaUK;
        aXvXc:
        if (!$this->renderHeader) {
            return;
        }
        goto EbSmu;
        y5R1I:
    }
    private function renderBody()
    {
        foreach ($this->data as $row) {
            goto OVznr;
            OVznr:
            if ($row === "\55\x2d\55") {
                $this->lineSeparator();
                goto WTdGs;
            }
            goto mxKPr;
            smP4D:
            GEzAH:
            goto VjmZH;
            mxKPr:
            $tmp = '';
            goto Di0v_;
            Di0v_:
            foreach ($this->columnsList as $column) {
                $tmp .= $this->column($column, $row[$column]);
                k2oNE:
            }
            goto smP4D;
            H_sS_:
            WTdGs:
            goto OzZ5H;
            VjmZH:
            $this->result[] = $tmp;
            goto H_sS_;
            OzZ5H:
        }
        L637E:
    }
}
