import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';

let page: Page;

test.beforeAll(async ({ browser }) => {
  page = await browser.newPage();
});

test.afterAll(async () => {
  if (page !== undefined) {
    await page.close();
  }
});

test('Login', async () => {
  // Login
  await page.goto('http://192.168.1.90:20001/');
  await expect(page).toHaveTitle(/^Sign in to /);
  await page.fill("input[name='username']", 'admin');
  await page.fill("input[name='password']", '1234');
  await page.click('id=kc-login');
  await page.waitForTimeout(2000);
  //   await page.click('id=acceptBtn');
});

test('Select Employee Tab', async () => {
  await page.click('id=menu-icon-customer-management');
  await page.waitForTimeout(2000);
});

test('Create Employee Not Input Data', async () => {
  await page.click('id=tab-employee');
  await page.click('id=btn-add');
  await page.click('id=add-employee');
  await page.click('id=submitBtn');
  await page.click('id=cancelBtn');
  await page.waitForTimeout(2000);
});

test('Create Employee Not Select Employee Code ', async () => {
  await page.click('id=btn-add');
  await page.click('id=add-employee');
  await page.fill("(//input[@id='input-nrcNo'])[2]", '6282282246226');
  await page.fill("(//input[@id='input-first-name'])[2]", 'ปองพล');
  await page.fill("(//input[@id='input-last-name'])[2]", 'กันธะณะ');
  await page.fill("(//input[@id='input-first-name-en'])[2]", 'Pongpon');
  await page.fill("(//input[@id='input-last-name-en'])[2]", 'Kuntana');
  await page.click("(//input[@id='input-birth-date'])[2]");
  await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
  await page.click("//div[text()='2536']");
  await page.click("//div[text()='8']");
  await page.click("(//div[@id='select-gender'])[2]");
  await page.click("//span[text()='หญิง']");
  await page.click("(//div[@id='select-nationality'])[2]");
  await page.waitForTimeout(2000);
  await page.click("(//div[@role='option'])[1]");
  await page.waitForTimeout(2000);
  await page.click("(//div[@id='select-passport-type'])[2]");
  await page.click("(//div[@role='option'])[1]");
  await page.fill("(//input[@id='input-passport-no'])[2]", 'TH2862242226262');
  await page.fill("(//input[@id='input-passport-ref'])[2]", '2042022022426');
  await page.fill("(//input[@id='input-passport-place'])[2]", 'Bangkok');
  await page.click("(//div[@id='select-passport-country'])[2]");
  await page.waitForTimeout(2000);
  await page.click("(//div[@role='option'])[1]");
  await page.click("(//input[@aria-label='วันที่ออกหนังสือเดินทาง'])[2]");
  await page.click("(//div[text()='2'])[1]");
  await page.click("(//input[@aria-label='วันหมดอายุหนังสือเดินทาง'])[2]");
  await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
  await page.click("//div[text()='2574']");
  await page.click("//div[text()='8']");
  await page.waitForTimeout(2000);
  await page.click("(//div[@id='select-visa-type'])[2]");
  await page.waitForTimeout(2000);
  await page.click("(//div[@role='option'])[1]");
  await page.fill("(//input[@id='input-visa-no'])[2]", '200222');
  await page.click("(//input[@aria-label='ออกให้วันที่'])[2]");
  await page.click("//div[text()='18']");
  await page.click("(//input[@aria-label='ใช้ได้ถึงวันที่'])[2]");
  await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
  await page.click("//div[text()='2568']");
  await page.click("//div[text()='8']");
  await page.fill(
    "(//input[@id='input-visa-place'])[2]",
    'กรมตรวจคนเข้าเมืองน่าน',
  );
  await page.click("(//input[@aria-label='ให้อยู่ในราชอาณาจักรถึงวันที่'])[2]");
  await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
  await page.click("//div[text()='2568']");
  await page.click("//div[text()='12']");
  await page.fill("(//input[@id='input-tm6'])[2]", '204422002');
  await page.click("(//input[@aria-label='วันที่เดินทางเข้ามาในประเทศ'])[2]");
  await page.click("//div[text()='18']");
  await page.click('id=submitBtn');
  await page.click('id=cancelBtn');
  await page.waitForTimeout(2000);
});

test('Create Employee Not Input Personal Information ', async () => {
  await page.click('id=btn-add');
  await page.click('id=add-employee');
  await page.click("(//input[@id='select-employer-branch'])[2]");
  await page.click('id=select-employer-branch_0');
  await page.fill("(//input[@id='input-nrcNo'])[2]", '6282282246226');

  await page.click("(//div[@id='select-passport-type'])[2]");
  await page.click("(//div[@role='option'])[1]");
  await page.fill("(//input[@id='input-passport-no'])[2]", 'TH2862242226262');
  await page.fill("(//input[@id='input-passport-ref'])[2]", '2042022022426');
  await page.fill("(//input[@id='input-passport-place'])[2]", 'Bangkok');
  await page.click("(//div[@id='select-passport-country'])[2]");
  await page.waitForTimeout(2000);
  await page.click("(//div[@role='option'])[1]");
  await page.click("(//input[@aria-label='วันที่ออกหนังสือเดินทาง'])[2]");
  await page.click("(//div[text()='2'])[1]");
  await page.click("(//input[@aria-label='วันหมดอายุหนังสือเดินทาง'])[2]");
  await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
  await page.click("//div[text()='2574']");
  await page.click("//div[text()='8']");
  await page.waitForTimeout(2000);

  await page.click("(//div[@id='select-visa-type'])[2]");
  await page.waitForTimeout(2000);
  await page.click("(//div[@role='option'])[1]");
  await page.fill("(//input[@id='input-visa-no'])[2]", '200222');
  await page.click("(//input[@aria-label='ออกให้วันที่'])[2]");
  await page.click("//div[text()='18']");
  await page.click("(//input[@aria-label='ใช้ได้ถึงวันที่'])[2]");
  await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
  await page.click("//div[text()='2568']");
  await page.click("//div[text()='8']");
  await page.fill(
    "(//input[@id='input-visa-place'])[2]",
    'กรมตรวจคนเข้าเมืองน่าน',
  );
  await page.click("(//input[@aria-label='ให้อยู่ในราชอาณาจักรถึงวันที่'])[2]");
  await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
  await page.click("//div[text()='2568']");
  await page.click("//div[text()='12']");
  await page.fill("(//input[@id='input-tm6'])[2]", '204422002');
  await page.click("(//input[@aria-label='วันที่เดินทางเข้ามาในประเทศ'])[2]");
  await page.click("//div[text()='18']");
  await page.click('id=submitBtn');
  await page.click('id=btn-ok-dialog');
  await page.click('id=submitBtn');
  await page.click('id=cancelBtn');
  await page.waitForTimeout(2000);
});

test('Create Employee Not Input Personal Address ', async () => {
  await page.click('id=btn-add');
  await page.click('id=add-employee');

  await page.click("(//input[@id='select-employer-branch'])[2]");
  await page.click('id=select-employer-branch_0');
  await page.fill("(//input[@id='input-nrcNo'])[2]", '6282282246226');
  await page.fill("(//input[@id='input-first-name'])[2]", 'ปองพล');
  await page.fill("(//input[@id='input-last-name'])[2]", 'กันธะณะ');
  await page.fill("(//input[@id='input-first-name-en'])[2]", 'Pongpon');
  await page.fill("(//input[@id='input-last-name-en'])[2]", 'Kuntana');
  await page.click("(//input[@id='input-birth-date'])[2]");
  await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
  await page.click("//div[text()='2536']");
  await page.click("//div[text()='8']");
  await page.click("(//div[@id='select-gender'])[2]");
  await page.click("//span[text()='หญิง']");
  await page.click("(//div[@id='select-nationality'])[2]");
  await page.waitForTimeout(2000);
  await page.click("(//div[@role='option'])[1]");
  await page.waitForTimeout(2000);

  await page.click("(//div[@id='select-passport-type'])[2]");
  await page.click("(//div[@role='option'])[1]");
  await page.fill("(//input[@id='input-passport-no'])[2]", 'TH2862242226262');
  await page.fill("(//input[@id='input-passport-ref'])[2]", '2042022022426');
  await page.fill("(//input[@id='input-passport-place'])[2]", 'Bangkok');
  await page.click("(//div[@id='select-passport-country'])[2]");
  await page.waitForTimeout(2000);
  await page.click("(//div[@role='option'])[1]");
  await page.click("(//input[@aria-label='วันที่ออกหนังสือเดินทาง'])[2]");
  await page.click("(//div[text()='2'])[1]");
  await page.click("(//input[@aria-label='วันหมดอายุหนังสือเดินทาง'])[2]");
  await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
  await page.click("//div[text()='2574']");
  await page.click("//div[text()='8']");

  await page.click("(//div[@id='select-visa-type'])[2]");
  await page.waitForTimeout(2000);
  await page.click("(//div[@role='option'])[1]");
  await page.fill("(//input[@id='input-visa-no'])[2]", '200222');
  await page.click("(//input[@aria-label='ออกให้วันที่'])[2]");
  await page.click("//div[text()='18']");
  await page.click("(//input[@aria-label='ใช้ได้ถึงวันที่'])[2]");
  await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
  await page.click("//div[text()='2568']");
  await page.click("//div[text()='8']");
  await page.fill(
    "(//input[@id='input-visa-place'])[2]",
    'กรมตรวจคนเข้าเมืองน่าน',
  );
  await page.click("(//input[@aria-label='ให้อยู่ในราชอาณาจักรถึงวันที่'])[2]");
  await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
  await page.click("//div[text()='2568']");
  await page.click("//div[text()='12']");
  await page.fill("(//input[@id='input-tm6'])[2]", '204422002');
  await page.click("(//input[@aria-label='วันที่เดินทางเข้ามาในประเทศ'])[2]");
  await page.click("//div[text()='18']");
  await page.click('id=submitBtn');
  await page.click('id=btn-ok-dialog');
  await page.waitForTimeout(2000);
});

test('Create Employee Not Input Personal Information OCR ', async () => {
  await page.click('id=btn-add');
  await page.click('id=add-employee');
  await page.click("(//input[@id='select-employer-branch'])[2]");
  await page.click('id=select-employer-branch_0');
  await page.fill("(//input[@id='input-nrcNo'])[2]", '6282282246226');
  await page.fill("(//input[@id='input-first-name'])[2]", 'ปองพล');
  await page.fill("(//input[@id='input-last-name'])[2]", 'กันธะณะ');
  await page.fill("(//input[@id='input-first-name-en'])[2]", 'Pongpon');
  await page.fill("(//input[@id='input-last-name-en'])[2]", 'Kuntana');
  await page.click("(//input[@id='input-birth-date'])[2]");
  await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
  await page.click("//div[text()='2536']");
  await page.click("//div[text()='8']");
  await page.click("(//div[@id='select-gender'])[2]");
  await page.click("//span[text()='หญิง']");
  await page.click("(//div[@id='select-nationality'])[2]");
  await page.waitForTimeout(2000);
  await page.click("(//div[@role='option'])[1]");

  await page.click("(//div[@id='select-visa-type'])[2]");
  await page.waitForTimeout(2000);
  await page.click("(//div[@role='option'])[1]");
  await page.fill("(//input[@id='input-visa-no'])[2]", '200222');
  await page.click("(//input[@aria-label='ออกให้วันที่'])[2]");
  await page.click("//div[text()='18']");
  await page.click("(//input[@aria-label='ใช้ได้ถึงวันที่'])[2]");
  await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
  await page.click("//div[text()='2568']");
  await page.click("//div[text()='8']");
  await page.fill(
    "(//input[@id='input-visa-place'])[2]",
    'กรมตรวจคนเข้าเมืองน่าน',
  );
  await page.click("(//input[@aria-label='ให้อยู่ในราชอาณาจักรถึงวันที่'])[2]");
  await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
  await page.click("//div[text()='2568']");
  await page.click("//div[text()='12']");
  await page.fill("(//input[@id='input-tm6'])[2]", '204422002');
  await page.click("(//input[@aria-label='วันที่เดินทางเข้ามาในประเทศ'])[2]");
  await page.click("//div[text()='18']");
  await page.click('id=submitBtn');
  await page.click('id=cancelBtn');
  await page.waitForTimeout(2000);
});

test('Create Employee Not Input Visa Information OCR ', async () => {
  await page.click('id=btn-add');
  await page.click('id=add-employee');

  await page.click("(//input[@id='select-employer-branch'])[2]");
  await page.click('id=select-employer-branch_0');
  await page.fill("(//input[@id='input-nrcNo'])[2]", '6282282246226');
  await page.fill("(//input[@id='input-first-name'])[2]", 'ปองพล');
  await page.fill("(//input[@id='input-last-name'])[2]", 'กันธะณะ');
  await page.fill("(//input[@id='input-first-name-en'])[2]", 'Pongpon');
  await page.fill("(//input[@id='input-last-name-en'])[2]", 'Kuntana');
  await page.click("(//input[@id='input-birth-date'])[2]");
  await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
  await page.click("//div[text()='2536']");
  await page.click("//div[text()='8']");
  await page.click("(//div[@id='select-gender'])[2]");
  await page.click("//span[text()='หญิง']");
  await page.click("(//div[@id='select-nationality'])[2]");
  await page.waitForTimeout(2000);
  await page.click("(//div[@role='option'])[1]");
  await page.click("(//div[@id='select-passport-type'])[2]");
  await page.click("(//div[@role='option'])[1]");
  await page.fill("(//input[@id='input-passport-no'])[2]", 'TH2862242226262');
  await page.fill("(//input[@id='input-passport-ref'])[2]", '2042022022426');
  await page.fill("(//input[@id='input-passport-place'])[2]", 'Bangkok');
  await page.click("(//div[@id='select-passport-country'])[2]");
  await page.waitForTimeout(2000);
  await page.click("(//div[@role='option'])[1]");
  await page.click("(//input[@aria-label='วันที่ออกหนังสือเดินทาง'])[2]");
  await page.click("(//div[text()='2'])[1]");
  await page.click("(//input[@aria-label='วันหมดอายุหนังสือเดินทาง'])[2]");
  await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
  await page.click("//div[text()='2574']");
  await page.click("//div[text()='8']");
  await page.click('id=submitBtn');
  await page.click('id=btn-ok-dialog');
  await page.waitForTimeout(2000);
});
