<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of SellerCreation
 *
 * @author LENGY
 */

namespace ArtabanMarketplace\Form;

use ArtabanMarketplace\ArtabanMarketplace;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Form\BaseForm;
use Thelia\Model\Country;
use Thelia\Model\CountryQuery;
use Thelia\Model\Admin;
use Thelia\Model\AdminQuery;

/**
 * Class SellerForm
 * @package ArtabanMarketplace\Form
 */
class SellerForm extends BaseForm {

    /**
     *
     * in this function you add all the fields you need for your Form.
     * Form this you have to call add method on $this->formBuilder attribute :
     *
     * $this->formBuilder->add("name", "text")
     *   ->add("email", "email", array(
     *           "attr" => array(
     *               "class" => "field"
     *           ),
     *           "label" => "email",
     *           "constraints" => array(
     *               new \Symfony\Component\Validator\Constraints\NotBlank()
     *           )
     *       )
     *   )
     *   ->add('age', 'integer');
     *
     * @return null
     */
    protected function buildForm() {
        $this->formBuilder
                ->add("title", "text", array(
                    "label" => $this->translator->trans("Title", []),
                    "label_attr" => ["for" => "seller.title"],
                    "required" => true,
                    "constraints" => array(new NotBlank(),),
                    "attr" => array()
                ))
                ->add("ref", "text", array(
                    "label" => $this->translator->trans("Ref", []),
                    "label_attr" => ["for" => "seller.ref"],
                    "required" => true,
                    "constraints" => array(new NotBlank(),),
                    "attr" => array()
                ))
                ->add("description", "text", array(
                    "label" => $this->translator->trans("Description", []),
                    "label_attr" => ["for" => "seller.description"],
                    "required" => false,
                    "attr" => array()
                ))
                ->add("access", "text", array(
                    "label" => $this->translator->trans("Access", []),
                    "label_attr" => ["for" => "seller.access"],
                    "required" => false,
                    "attr" => array()
                ))
                ->add("address1", "text", array(
                    "label" => $this->translator->trans("Address1", [], ArtabanMarketplace::MESSAGE_DOMAIN),
                    "required" => true,
                    "constraints" => array(new NotBlank(),),
                    "attr" => array()
                ))
                ->add("address2", "text", array(
                    "label" => $this->translator->trans("Address2", []),
                    "label_attr" => ["for" => "seller.address2"],
                    "required" => false,
                    "attr" => array()
                ))
                ->add("address3", "text", array(
                    "label" => $this->translator->trans("Address3", []),
                    "label_attr" => ["for" => "seller.address3"],
                    "required" => false,
                    "attr" => array()
                ))
                ->add("zipcode", "text", array(
                    "label" => $this->translator->trans("Zipcode", []),
                    "label_attr" => ["for" => "seller.zipcode"],
                    "required" => true,
                    "constraints" => array(new NotBlank(),),
                    "attr" => array()
                ))
                ->add("city", "text", array(
                    "label" => $this->translator->trans("City", []),
                    "label_attr" => ["for" => "seller.city"],
                    "required" => true,
                    "constraints" => array(new NotBlank(),),
                    "attr" => array()
                ))
                ->add("country_id", "choice", array(
                    "choices" => $this->getCountries(),
                    "label" => $this->translator->trans("Country", []),
                    "label_attr" => ["for" => "seller.country"],
                    "required" => true,
                    "attr" => array()
                ))
                ->add("email", "text", array(
                    "label" => $this->translator->trans("Email", []),
                    "label_attr" => ["for" => "seller.email"],
                    "required" => true,
                    "constraints" => array(new NotBlank(),),
                    "attr" => array()
                ))
                ->add("phone", "text", array(
                    "label" => $this->translator->trans("Phone", []),
                    "label_attr" => ["for" => "seller.phone"],
                    "required" => false,
                    "attr" => array()
                ))
                ->add("fax", "text", array(
                    "label" => $this->translator->trans("Fax", []),
                    "label_attr" => ["for" => "seller.fax"],
                    "required" => false,
                    "attr" => array()
                ))
                ->add("url", "text", array(
                    "label" => $this->translator->trans("URL", []),
                    "label_attr" => ["for" => "seller.url"],
                    "required" => false,
                    "attr" => array()
                ))
                ->add("facebook", "text", array(
                    "label" => $this->translator->trans("Facebook", []),
                    "label_attr" => ["for" => "seller.facebook"],
                    "required" => false,
                    "attr" => array()
                ))
                ->add("twitter", "text", array(
                    "label" => $this->translator->trans("Twitter", []),
                    "label_attr" => ["for" => "seller.twitter"],
                    "required" => false,
                    "attr" => array()
                ))
                ->add("pinterest", "text", array(
                    "label" => $this->translator->trans("Pinterest", []),
                    "label_attr" => ["for" => "seller.pinterest"],
                    "required" => false,
                    "attr" => array()
                ))
                ->add("google", "text", array(
                    "label" => $this->translator->trans("Google", []),
                    "label_attr" => ["for" => "seller.google"],
                    "required" => false,
                    "attr" => array()
                ))
                ->add("youtube", "text", array(
                    "label" => $this->translator->trans("Youtube", []),
                    "label_attr" => ["for" => "seller.youtube"],
                    "required" => false,
                    "attr" => array()
                ))
                ->add("instagram", "text", array(
                    "label" => $this->translator->trans("Instagram", []),
                    "label_attr" => ["for" => "seller.instagram"],
                    "required" => false,
                    "attr" => array()
                ))
                ->add("locale", "text", array(
                    "constraints" => array(
                        new NotBlank(),
                    ),
                    "label_attr" => array("for" => "locale_create"),
        ));
    }

    protected function getCountries() {
        $countries = CountryQuery::create()->find();
        $retour = [];
        /** @var Country $country */
        foreach ($countries as $country) {
            $retour[$country->getId()] = $country->getTitle();
        }

        return $retour;
    }

    //NOT USED
    protected function getAdminSellers() {
        $admins = AdminQuery::create()->find();
        $retour = [0 => ""];
        /** @var Country $country */
        foreach ($admins as $admin) {
            $retour[$admin->getId()] = $admin->getFirstname() . " " . $admin->getLastname();
        }

        return $retour;
    }

    public function getName() {
        return "seller_create";
    }

}
