package Hangle;

use strict;
use warnings;
use Lingua::KO::Hangul::Util qw(:all);
use base qw/Exporter/;
use Encode qw/decode encode/;

our @EXPORT_OK = qw/transformation/;

sub transformation{
	my $arg = shift;
	my $str = decode('cp-949', $arg);
	binmode STDOUT, ':encoding(cp-949)';
	my %hangle = (
			#초성
			"\x{1100}" => 'r', "\x{1102}" => 's', "\x{1103}" => 'e', "\x{1105}" => 'f',  # ㄱㄴㄷㄹ
			"\x{1106}" => 'a', "\x{1107}" => 'q', "\x{1109}" => 't', "\x{110B}" => 'd',  # ㅁㅂㅅㅇ
			"\x{110C}" => 'w', "\x{110E}" => 'c', "\x{110F}" => 'z', "\x{1110}" => 'x',  # ㅈㅊㅋㅌ
			"\x{1111}" => 'v', "\x{1112}" => 'g', "\x{1101}" => 'R', "\x{1104}" => 'E',  # ㅍㅎㄲ ㄸ
			"\x{1108}" => 'Q', "\x{110A}" => 'T', "\x{110D}" => 'W',                     # ㅃ ㅆ ㅉ		  
			#중성
			"\x{1161}" => 'k', "\x{1163}" => 'i', "\x{1165}" => 'j', "\x{1167}" => 'u',  # ㅏㅑㅓㅕ
			"\x{1169}" => 'h', "\x{116D}" => 'y', "\x{116E}" => 'n', "\x{1172}" => 'b',  # ㅗㅛㅜㅠ
			"\x{1173}" => 'm', "\x{1175}" => 'l',                                        # ㅡㅣ
			"\x{1162}" => 'o', "\x{1164}" => 'O', "\x{1166}" => 'p', "\x{1168}" => 'P',  # ㅐㅒㅔㅖ
			#종성
			"\x{11A8}" => 'r', "\x{11AB}" => 's', "\x{11AE}" => 'e', "\x{11AF}" => 'f',  # ㄱㄴㄷㄹ
			"\x{11B7}" => 'a', "\x{11B8}" => 'q', "\x{11BA}" => 't', "\x{11BC}" => 'd',  # ㅁㅂㅅㅇ
			"\x{11BD}" => 'w', "\x{11BE}" => 'c', "\x{11BF}" => 'z', "\x{11C0}" => 'x',  # ㅈㅊㅋㅌ
			"\x{11C1}" => 'v', "\x{11C2}" => 'g',                                        # ㅍㅎ
			"\x{11A9}" => 'R', "\x{11BB}" => 'T',                                        # ㄲ ㅆ
			#특수문자
			"\x{20}" => ' ' , "\x{A}" => "\n" , "\x{2E}" => '.' , "\x{2C}" => ',' ,      #Space Enter . ,
			"\x{2D}" => '-' , 
			#Number
			"\x{30}" => '0' , "\x{31}" => '1' , "\x{32}" => '2' , "\x{33}" => '3' ,
			"\x{34}" => '4' , "\x{35}" => '5' , "\x{36}" => '6' , "\x{37}" => '7' ,
			"\x{38}" => '8' , "\x{39}" => '9' ,
	);
	my @jamos =  map { split //, decomposeJamo($_) }split //, decomposeSyllable($str);
	my $keys = '{HAN}';
	foreach (@jamos) { $keys .= $hangle{$_} }
	# print "$strokes";
	return $keys;
}