import { Injectable, LOCALE_ID, NgModule } from '@angular/core';
import { CommonModule, registerLocaleData } from '@angular/common';
import { DemoDirective } from './directives/demo.directive';
import { DemoPipe } from './pipes/demo.pipe';
import { MatToolbarModule } from '@angular/material/toolbar';
import { ReactiveFormsModule, FormsModule } from '@angular/forms';
import { DateAdapter, MatNativeDateModule, MAT_DATE_FORMATS, NativeDateAdapter } from '@angular/material/core';
import { MatButtonModule } from '@angular/material/button';
import {MatSortModule} from '@angular/material/sort';
import {MatProgressSpinnerModule} from '@angular/material/progress-spinner';
import { MatCardModule } from '@angular/material/card';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatGridListModule } from '@angular/material/grid-list';
import { MatTableModule } from '@angular/material/table';
import { MatIconModule } from '@angular/material/icon';
import { MatChipsModule } from '@angular/material/chips';
import { MatCheckboxModule } from '@angular/material/checkbox'
import { MatStepperModule } from '@angular/material/stepper'
import { MatRadioModule } from '@angular/material/radio';
import { MatSelectModule } from '@angular/material/select';
import { MatDatepickerModule } from '@angular/material/datepicker';
import { MatAutocompleteModule } from '@angular/material/autocomplete';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { MatMenuModule    } from '@angular/material/menu'
import { MatProgressBarModule } from '@angular/material/progress-bar';
import { EditorModule } from '@tinymce/tinymce-angular';
import { MatExpansionModule } from '@angular/material/expansion';
import { MatPaginatorModule } from '@angular/material/paginator';
import { MatTabsModule } from '@angular/material/tabs';
import { SearchAutoPipe } from './pipes/search-auto/search-auto.pipe';
import { ThaidatePipe } from './pipes/thaidate/thaidate.';
import { SearchAutoPipeV2 } from './pipes/search-auto/search-autov2.pipe';
import { SpecialCharacterDirective } from './directives/input.directive';
import { RolePipePipe } from './pipes/role/role.pipe';
import { PreviewFilePipe } from './pipes/previewfile/preview-file.pipe';
import localeTh from '@angular/common/locales/th';
import { GetDataIdPipe } from './pipes/getdata/get-data-id.pipe';
import { CheckseatPipe } from './pipes/checkseat/checkseat.pipe';
import {MatSlideToggleModule} from '@angular/material/slide-toggle';
import { OnlyNumberDirective } from './directives/only-number.directive';
import { LimitLengthDirective } from './directives/limit-length.directive';
import { CheckdupicateseatPipe } from './pipes/checkseat/checkdupicateseat.pipe';
import { ChecklessmoreseatPipe } from './pipes/checkseat/checklessmoreseat.pipe';
import { ChecklessmoreallseatPipe } from './pipes/checkseat/checklessmoreallseat.pipe';
import { CheakseatallPipe } from './pipes/checkseat/cheakseatall.pipe';
import { CheckFormExamInformationSectionPipe } from './pipes/checkFormcustom/check-form-exam-information-section.pipe';
import { CheckfieldPipe } from './pipes/checkseat/checkfield.pipe';
import { CheckmaxseatPipe } from './pipes/checkseat/checkmaxseat.pipe';
import { CheckinrangePipe } from './pipes/checkseat/checkinrange.pipe';
import { CheckinrangeallseatPipe } from './pipes/checkseat/checkinrangeallseat.pipe';
import { EmailInputDirective } from './directives/email-input.directive';
import { CheckdupicateallseatPipe } from './pipes/checkseat/checkdupicateallseat.pipe';

registerLocaleData(localeTh)
@Injectable()
export class AppDateAdapter extends NativeDateAdapter {
    format(date: Date, displayFormat: Object): string {
            let monthNamesThai = ["ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.",
                "ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค"];
            date.setHours(7);
            let day: string = date.getDate().toLocaleString();
            day = +day < 10 ? '0' + day : day;
            let year = date.getFullYear();
            let thaidate = `${day}/${monthNamesThai[date.getMonth()]}/${year + 543}`;
            return thaidate;
    }
}

export const PICK_FORMATS = {
    parse: {
        dateInput: {
            month: 'short',
            year: 'numeric',
            day: 'numeric'
        }
    },
    display: {
            dateInput: 'input',
            monthYearLabel: {day: 'numeric', year: 'numeric', month: 'long'},
            dateA11yLabel: {year: 'numeric', month: 'long', day: 'numeric'},
            monthYearA11yLabel: {year: 'numeric', month: 'long'}
    }
};

export const MY_FORMATS = {
    parse: {
        dateInput: 'DD-MMM-YYYY',
    },
    display: {
        dateInput: 'DD-MMM-YYYY',
        monthYearLabel: 'DD-MMM-YYYY',
        dateA11yLabel: 'DD-MMM-YYYY',
        monthYearA11yLabel: 'DD-MMM-YYYY',
    },
};


const ext = [
    EditorModule
]
const mat = [
    MatSortModule,
    CommonModule,
    ReactiveFormsModule,
    FormsModule,
    MatButtonModule,
    MatToolbarModule,
    MatCardModule,
    MatFormFieldModule,
    MatInputModule,
    MatGridListModule,
    MatTableModule,
    MatIconModule,
    MatChipsModule,
    MatCheckboxModule,
    MatStepperModule,
    MatRadioModule,
    MatSelectModule,
    MatDatepickerModule,
    MatAutocompleteModule,
    MatSnackBarModule,
    MatMenuModule,
    MatSlideToggleModule,
    MatNativeDateModule,
    MatProgressBarModule,
    MatExpansionModule,
    MatPaginatorModule,
    MatTabsModule,
    MatProgressSpinnerModule
]

const pipe = [
    ThaidatePipe,
    SearchAutoPipe,
    SearchAutoPipeV2,
    RolePipePipe,
    PreviewFilePipe,
    GetDataIdPipe
]

const directive = [
    SpecialCharacterDirective,
    OnlyNumberDirective,
    LimitLengthDirective
]

@NgModule({
    declarations: [
        DemoDirective,
        DemoPipe,
        ...pipe,
        ...directive,
        CheckseatPipe,
        CheckdupicateseatPipe,
        ChecklessmoreseatPipe,
        ChecklessmoreallseatPipe,
        CheakseatallPipe,
        CheckFormExamInformationSectionPipe,
        CheckfieldPipe,
        CheckmaxseatPipe,
        CheckinrangePipe,
        CheckinrangeallseatPipe,
        EmailInputDirective,
        CheckdupicateallseatPipe,
    ],
    imports: [
        ...mat,
        ...ext
    ],
        exports: [
                ...mat,
                ...ext,
                ...pipe,
                ...directive,
                CheckseatPipe,
                CheckdupicateseatPipe,
                ChecklessmoreseatPipe,
                ChecklessmoreallseatPipe,
                CheakseatallPipe,
                CheckFormExamInformationSectionPipe,
                CheckfieldPipe,
                CheckmaxseatPipe,
                CheckinrangePipe,
                CheckinrangeallseatPipe,
                CheckdupicateallseatPipe,
        ],
    providers: [
        { provide: LOCALE_ID, useValue: 'th-TH'},
        { provide: DateAdapter, useClass: AppDateAdapter},
        { provide: MAT_DATE_FORMATS, useValue: PICK_FORMATS},
    ]
})
export class SharedModule { }
