class AddAktModalController{
    constructor(API, $uibModal, $state,$timeout)


    $onInit(){
    }
}

export const AddAktModalComponent = {
    templateUrl: './views/app/components/addAktModal/addAktModal.component.html',
    controller: AddAktModalController,
    controllerAs: 'vm',
    bindings: {
        modalInstance: "<",
        resolve: "<"
    }
}

{
        'ngInject';
        let vm=this;
        vm.API=API;
        vm.program=vm.resolve.program;
        vm.programs=vm.resolve.programs;
        vm.data={
            program:vm.program.id,
            title:null,
            date:new Date()
        };
        vm.dateOptions = {
            altInputFormats: ['yyyy-MM-dd', 'dd.MM.yyyy'],
            formatDay: 'dd',
            formatMonth: 'MM',
            formatYear: 'yyyy',
            minDate: new Date(),
            startingDay: 1
        };
        vm.date = {
            opened: false
        };

        vm.openCalendar=()=>{
            vm.date.opened=true;
        };
        vm.close=()=>{
            this.modalInstance.dismiss('cancel');
        };
        vm.add=()=>{
            let calendar = this.API.all('akt');
            calendar.post({
                program:vm.data.program,
                title:vm.data.title,
                date:moment(vm.data.date).format('YYYY-MM-DD'),
            }).then((response) => {
                    vm.success=true;
                    $timeout( ()=>{
                        $state.reload();
                    }, 300);
                    $timeout(()=> {
                        vm.close();
                    }, 500);
                },
                (response) => {
                    vm.message=response.data.uniqemessage;
                    vm.errors=response.data.errors;
                });
        }
        //
    }