<?php

namespace Inventory\Purchase\Forms;

class Order
{
    /**
     * Variable to store form configuration.
     *
     * @var collection
     */
    protected $form;

    /**
     * Variable to store form configuration.
     *
     * @var collection
     */
    protected $element;

    /**
     * Initialize the form.
     *
     * @return null
     */
    public function __construct()
    {
        $this->setForm();
    }

    /**
     * Return form elements.
     *
     * @return array.
     */
    public function form($element = 'fields', $grouped = true)
    {
        $item = collect($this->form->get($element));
        if ($element == 'fields' && $grouped == true) {
            return $item->groupBy(['group', 'section']);
        }
        return $item;

    }

    /**
     * Sets the form and form elements.
     * @return null.
     */
    public function setForm()
    {
        $this->form = collect([
            'form' => [
                'store' => [],
                'update' => [],
            ],
            'groups' => [
                'main' => 'Main',
            ],
            'fields' => [
                'vendor_id' => [
                    "type" => 'numeric',
                    "label" => trans('purchase::order.label.vendor_id'),
                    "placeholder" => trans('purchase::order.placeholder.vendor_id'),
                    "rules" => '',
                    "group" => "main",
                    "section" => "first",
                    "attributes" => [
                        'wrapper' => [],
                        "label" => [],
                        "input" => [],

                    ],
                ],
                'customer_id' => [
                    "type" => 'numeric',
                    "label" => trans('purchase::order.label.customer_id'),
                    "placeholder" => trans('purchase::order.placeholder.customer_id'),
                    "rules" => '',
                    "group" => "main",
                    "section" => "first",
                    "attributes" => [
                        'wrapper' => [],
                        "label" => [],
                        "input" => [],

                    ],
                ],
                'payment_term_id' => [
                    "type" => 'numeric',
                    "label" => trans('purchase::order.label.payment_term_id'),
                    "placeholder" => trans('purchase::order.placeholder.payment_term_id'),
                    "rules" => '',
                    "group" => "main",
                    "section" => "first",
                    "attributes" => [
                        'wrapper' => [],
                        "label" => [],
                        "input" => [],

                    ],
                ],
                'order_no' => [
                    "type" => 'text',
                    "label" => trans('purchase::order.label.order_no'),
                    "placeholder" => trans('purchase::order.placeholder.order_no'),
                    "rules" => '',
                    "group" => "main",
                    "section" => "first",
                    "attributes" => [
                        'wrapper' => [],
                        "label" => [],
                        "input" => [],

                    ],
                ],
                'reference' => [
                    "type" => 'text',
                    "label" => trans('purchase::order.label.reference'),
                    "placeholder" => trans('purchase::order.placeholder.reference'),
                    "rules" => '',
                    "group" => "main",
                    "section" => "first",
                    "attributes" => [
                        'wrapper' => [],
                        "label" => [],
                        "input" => [],

                    ],
                ],
                'order_date' => [
                    "type" => 'date_picker',
                    "label" => trans('purchase::order.label.order_date'),
                    "placeholder" => trans('purchase::order.placeholder.order_date'),
                    "rules" => '',
                    "group" => "main",
                    "section" => "first",
                    "attributes" => [
                        'wrapper' => [],
                        "label" => [],
                        "input" => [],

                    ],
                ],
                'expected_delivery_date' => [
                    "type" => 'date_picker',
                    "label" => trans('purchase::order.label.expected_delivery_date'),
                    "placeholder" => trans('purchase::order.placeholder.expected_delivery_date'),
                    "rules" => '',
                    "group" => "main",
                    "section" => "first",
                    "attributes" => [
                        'wrapper' => [],
                        "label" => [],
                        "input" => [],

                    ],
                ],
                'subtotal' => [
                    "type" => 'decimal',
                    "label" => trans('purchase::order.label.subtotal'),
                    "placeholder" => trans('purchase::order.placeholder.subtotal'),
                    "rules" => '',
                    "group" => "main",
                    "section" => "first",
                    "attributes" => [
                        'wrapper' => [],
                        "label" => [],
                        "input" => [],

                    ],
                ],
                'discount' => [
                    "type" => 'decimal',
                    "label" => trans('purchase::order.label.discount'),
                    "placeholder" => trans('purchase::order.placeholder.discount'),
                    "rules" => '',
                    "group" => "main",
                    "section" => "first",
                    "attributes" => [
                        'wrapper' => [],
                        "label" => [],
                        "input" => [],

                    ],
                ],
                'total' => [
                    "type" => 'decimal',
                    "label" => trans('purchase::order.label.total'),
                    "placeholder" => trans('purchase::order.placeholder.total'),
                    "rules" => '',
                    "group" => "main",
                    "section" => "first",
                    "attributes" => [
                        'wrapper' => [],
                        "label" => [],
                        "input" => [],

                    ],
                ],
                'notes' => [
                    "type" => 'text',
                    "label" => trans('purchase::order.label.notes'),
                    "placeholder" => trans('purchase::order.placeholder.notes'),
                    "rules" => '',
                    "group" => "main",
                    "section" => "first",
                    "attributes" => [
                        'wrapper' => [],
                        "label" => [],
                        "input" => [],

                    ],
                ],
                'terms_and_conditions' => [
                    "type" => 'text',
                    "label" => trans('purchase::order.label.terms_and_conditions'),
                    "placeholder" => trans('purchase::order.placeholder.terms_and_conditions'),
                    "rules" => '',
                    "group" => "main",
                    "section" => "first",
                    "attributes" => [
                        'wrapper' => [],
                        "label" => [],
                        "input" => [],

                    ],
                ],
                'files' => [
                    "type" => 'text',
                    "label" => trans('purchase::order.label.files'),
                    "placeholder" => trans('purchase::order.placeholder.files'),
                    "rules" => '',
                    "group" => "main",
                    "section" => "first",
                    "attributes" => [
                        'wrapper' => [],
                        "label" => [],
                        "input" => [],

                    ],
                ],
            ]
        );

    }
}