<commit_before><?php

namespace App\Widgets;

use Caffeinated\Widgets\Widget;
use App\Presenters\AppointmentPresenter;
use App\Appointment;
use App\User;
use Carbon\Carbon;
use Panel;
use Button;
use Icon;

class AppointmentPanel extends Widget
{
    protected $profile;

    protected $user;

    protected $appointments;

    public function __construct(Appointment $appointment, User $user)
    {
        $this->user = $user;

        $this->appointment = $appointment;
    }

    public function handle()
    {
        $this->profile = $this->getProfile();
        return $this->panel($this->appointment->getPresenter());
    }

    private function getProfile()
    {
        return $this->user->isOwner($this->appointment->business) ? 'manager' : 'user';
    }

    public function panel(AppointmentPresenter $appointment)
    {
        $header = $appointment->status();

        $footer = Icon::barcode() . '&nbsp;<code>' . $appointment->code() .'</code>';

        $panel = $this->getPanelWithStatus();
        $body  = $this->buildBody($appointment);

        return $panel->withAttributes(['id' => $appointment->code()])->withHeader($header)->withBody($body)->withFooter($footer);
    }

    public function getPanelWithStatus()
    {
        return Panel::setType('panel-'.$this->statusToClass());
    }

    public function buildBody($appointment)
    {
        $class = $this->statusToClass();
        $body  = "<ul class=\"list-group appointmentinfo $class\">";
        $body .= '<li class="list-group-item">';
        $body .= Icon::home(). '&nbsp;' . $appointment->business->name;
        $body .= '</li>';
        if($appointment->business->postal_address)
        {
            $body .= '<li class="list-group-item">';
            $body .= Icon::map_marker(). '&nbsp;' . $appointment->business->postal_address;
            $body .= '</li>';
        }
        if($appointment->business->phone)
        {
            $body .= '<li class="list-group-item">';
            $body .= Icon::phone(). '&nbsp;' . $appointment->business->phone;
            $body .= '</li>';
        }
        $body .= '<li class="list-group-item">';
        $body .= Icon::calendar() . '&nbsp;' . $appointment->date() . '&nbsp;&nbsp;' . '<span class="text-muted"><small>' . $appointment->start_at->diffForHumans() . '</small></span>';
        $body .= '</li>';
        $body .= '<li class="list-group-item">';
        $body .= '<span title="'.$appointment->tz.'">';
        $body .= Icon::time() . '&nbsp;' . $appointment->start_at->timezone($appointment->tz)->toTimeString();
        $body .= '</span>';
        $body .= '<li class="list-group-item">';
        $body .= Icon::tag(). '&nbsp;' . $appointment->service->name;
        $body .= '</li>';
        if($appointment->service->prerequisites)
        {
            $body .= '<li class="list-group-item">';
            $body .= Icon::alert(). '&nbsp;' . $appointment->service->prerequisites;
            $body .= '</li>';
        }
        $body .= '</li>';
        
        $body .= '</ul>';

        $body .= $this->actionButtons($appointment);
        
        if ($appointment->comments) {
            $body .= '<p>'. $appointment->comments .'</p>';
        }

        return $body;
    }

    public function statusToClass()
    {
        switch ($this->appointment->status) {
            case Appointment::STATUS_ANNULATED:
                return 'danger';
                break;
            case Appointment::STATUS_CONFIRMED:
                return 'success';
                break;
            case Appointment::STATUS_RESERVED:
                return 'warning';
                break;
            case Appointment::STATUS_SERVED:
            default:
                return 'default';
                break;
        }
    }

    public function actionButtons($appointment)
    {
        $method = $this->profile.'ActionButtons';
        return $this->$method($appointment);
    }

    private function getBtnCommonAttributes($appointment)
    {<commit_msg>Enhance layout by moving comments into a list item<commit_after><?php

namespace App\Widgets;

use Caffeinated\Widgets\Widget;
use App\Presenters\AppointmentPresenter;
use App\Appointment;
use App\User;
use Carbon\Carbon;
use Panel;
use Button;
use Icon;

class AppointmentPanel extends Widget
{
    protected $profile;

    protected $user;

    protected $appointments;

    public function __construct(Appointment $appointment, User $user)
    {
        $this->user = $user;

        $this->appointment = $appointment;
    }

    public function handle()
    {
        $this->profile = $this->getProfile();
        return $this->panel($this->appointment->getPresenter());
    }

    private function getProfile()
    {
        return $this->user->isOwner($this->appointment->business) ? 'manager' : 'user';
    }

    public function panel(AppointmentPresenter $appointment)
    {
        $header = $appointment->status();

        $footer = Icon::barcode() . '&nbsp;<code>' . $appointment->code() .'</code>';

        $panel = $this->getPanelWithStatus();
        $body  = $this->buildBody($appointment);

        return $panel->withAttributes(['id' => $appointment->code()])->withHeader($header)->withBody($body)->withFooter($footer);
    }

    public function getPanelWithStatus()
    {
        return Panel::setType('panel-'.$this->statusToClass());
    }

    public function buildBody($appointment)
    {
        $class = $this->statusToClass();
        $body  = "<ul class=\"list-group appointmentinfo $class\">";
        $body .= '<li class="list-group-item">';
        $body .= Icon::home(). '&nbsp;' . $appointment->business->name;
        $body .= '</li>';
        if ($appointment->business->postal_address) {
            $body .= '<li class="list-group-item">';
            $body .= Icon::map_marker(). '&nbsp;' . $appointment->business->postal_address;
            $body .= '</li>';
        }
        if ($appointment->business->phone) {
            $body .= '<li class="list-group-item">';
            $body .= Icon::phone(). '&nbsp;' . $appointment->business->phone;
            $body .= '</li>';
        }
        $body .= '<li class="list-group-item">';
        $body .= Icon::calendar() . '&nbsp;' . $appointment->date() . '&nbsp;&nbsp;' . '<span class="text-muted"><small>' . $appointment->start_at->diffForHumans() . '</small></span>';
        $body .= '</li>';
        $body .= '<li class="list-group-item">';
        $body .= '<span title="'.$appointment->tz.'">';
        $body .= Icon::time() . '&nbsp;' . $appointment->start_at->timezone($appointment->tz)->toTimeString();
        $body .= '</span>';
        $body .= '<li class="list-group-item">';
        $body .= Icon::tag(). '&nbsp;' . $appointment->service->name;
        $body .= '</li>';
        if ($appointment->service->prerequisites) {
            $body .= '<li class="list-group-item">';
            $body .= Icon::alert(). '&nbsp;' . $appointment->service->prerequisites;
            $body .= '</li>';
        }
        if ($appointment->comments) {
            $body .= '<li class="list-group-item">';
            $body .= Icon::pencil(). '&nbsp;' . $appointment->comments;
            $body .= '</li>';
        }
        $body .= '</li>';
        
        $body .= '</ul>';

        $body .= $this->actionButtons($appointment);

        return $body;
    }

    public function statusToClass()
    {
        switch ($this->appointment->status) {
            case Appointment::STATUS_ANNULATED:
                return 'danger';
                break;
            case Appointment::STATUS_CONFIRMED:
                return 'success';
                break;
            case Appointment::STATUS_RESERVED:
                return 'warning';
                break;
            case Appointment::STATUS_SERVED:
            default:
                return 'default';
                break;
        }
    }

    public function actionButtons($appointment)
    {
        $method = $this->profile.'ActionButtons';
        return $this->$method($appointment);
    }

    private function getBtnCommonAttributes($appointment)
    {
{'fraction_non_alphanumeric': 0.18225449175486094, 'fraction_numerical': 0.0, 'mean_word_length': 2.2033898305084745, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 163, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5194096', 'n_tokens_mistral': 2394, 'n_tokens_neox': 2343, 'n_words': 436}